# iZilotto

A modern lottery management platform built with Laravel 13, designed to manage the full lifecycle of Haitian borlette lottery operations — from ticket sales at points of sale to prize payouts.

## Overview

iZilotto is a complete rewrite of a legacy lottery ticketing system, modernized with a clean architecture, role-based access control, and an admin dashboard. It handles multiple lotteries, daily draws, ticket sales across a network of points of sale, winning number publication, and payment processing.

## Tech Stack

| Layer | Technology |
|---|---|
| Framework | Laravel 13 |
| PHP | 8.4 |
| Admin Panel | Backpack for Laravel v7 |
| Permissions | Spatie Laravel Permission |
| Database | MySQL |
| Web Server | Apache |
| Runtime | PHP-FPM 8.4 |

## Features

- Multi-lottery support (e.g. New York, Florida)
- Two daily draws per lottery: Midi (AM) and Soir (PM)
- Multiple game types: borlette (2-digit), mariage, 3chif, loto4, loto5
- Full point-of-sale network management (tracked by IMEI)
- Ticket and number entry with combo support
- Betting limits per number and game type
- Winning number publication
- Prize payment tracking and processing
- Role-based access: Admin, Manager, Center, Vendeur
- Activity logging via Spatie Activity Log

## Domain Hierarchy

```
Users → Managers → Centers → Points of Sale → Tickets → Numbers
```

## Roles

| Role | Description |
|---|---|
| `ADMIN` | Full platform access |
| `MANAGER` | Manages assigned centers |
| `CENTER` | Manages assigned points of sale |
| `VENDEUR` | Sells tickets at a point of sale |

## Local Development Setup

### Prerequisites

- PHP 8.4
- Composer
- MySQL
- Apache or Nginx

### Installation

```bash
# Clone the repository
git clone <repo-url>
cd izilotto

# Install dependencies
composer install

# Copy environment file
cp .env.example .env

# Generate application key
php artisan key:generate

# Configure your database in .env, then run migrations
php artisan migrate --seed

# Start local server
php artisan serve
```

## Deployment

This project uses GitLab CI/CD for automatic deployment to the production VPS.

Every push to the `main` branch triggers a pipeline that:

1. SSHs into the VPS
2. Pulls the latest code
3. Runs `composer install` (production mode)
4. Runs database migrations
5. Clears and rebuilds Laravel caches
6. Restarts PHP-FPM

**Production URL:** https://lotto.alhdo.dev

### CI/CD Setup (for new environments)

1. Generate a dedicated SSH key pair for GitLab
2. Add the public key to the VPS's `authorized_keys`
3. Add the private key as a GitLab CI/CD variable named `SSH_PRIVATE_KEY`

## Project Structure

```
app/
├── Http/Controllers/Admin/   # Backpack CRUD controllers
├── Http/Requests/            # Form validation
├── Models/                   # Eloquent models
│   ├── Lottery.php
│   ├── Draw.php
│   ├── Game.php
│   ├── Center.php
│   ├── Pointofsale.php
│   ├── Ticket.php
│   ├── Number.php
│   ├── Winning.php
│   ├── Payment.php
│   └── BettingLimit.php
routes/
├── backpack/custom.php       # Admin panel routes
resources/views/
├── admin/                    # Custom admin views
```

## License

Private — All rights reserved.