# Powerball Claims Center - VPS & Server Deployment Guide

This project is a complete, production-ready fullstack web application built with **Next.js (App Router)**, **Tailwind CSS**, and **PostgreSQL**.

---

## 🚀 Quick Deployment Options on Linux VPS (Ubuntu / Debian / AlmaLinux)

### Option 1: Standard VPS Deployment with Node.js & PM2 (Recommended)

1. **Install Node.js (v20+ recommended) & PostgreSQL on your VPS:**
   ```bash
   # Ubuntu / Debian
   sudo apt update
   sudo apt install -y nodejs npm postgresql postgresql-contrib git
   ```

2. **Clone / Upload your project files:**
   ```bash
   cd /var/www/powerball-claims
   ```

3. **Configure Environment Variables (`.env`):**
   ```bash
   cp .env.example .env
   nano .env
   ```
   Set your `DATABASE_URL` to your PostgreSQL database:
   ```env
   DATABASE_URL="postgresql://postgres:your_password@127.0.0.1:5432/powerball_claims"
   PORT=3000
   ADMIN_USERNAME=admin
   ADMIN_PASSWORD=admin
   CLAIM_AGENT_EMAIL=claims@yourdomain.com
   ```

4. **Run the Automated Deploy Script:**
   ```bash
   chmod +x deploy.sh
   ./deploy.sh
   ```
   *Note: On startup, the application automatically verifies and initializes all PostgreSQL tables (`admin_settings`, `winning_entries`, `winner_claims`) if they do not exist.*

5. **Configure Nginx Reverse Proxy (Optional with SSL):**
   ```nginx
   server {
       server_name yourdomain.com www.yourdomain.com;

       location / {
           proxy_pass http://127.0.0.1:3000;
           proxy_http_version 1.1;
           proxy_set_header Upgrade $http_upgrade;
           proxy_set_header Connection 'upgrade';
           proxy_set_header Host $host;
           proxy_set_header X-Real-IP $remote_addr;
           proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
           proxy_set_header X-Forwarded-Proto $scheme;
           proxy_cache_bypass $http_upgrade;
       }
   }
   ```
   Install free SSL with Certbot:
   ```bash
   sudo apt install -y certbot python3-certbot-nginx
   sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
   ```

---

### Option 2: 1-Click Docker Compose Deployment

If you have Docker and Docker Compose installed on your VPS:

```bash
docker compose up -d --build
```

This starts both the Next.js application container (port 3000) and the PostgreSQL database container with automatic health checks and persistent volume storage.

---

### Option 3: cPanel / CloudLinux Node.js Application Manager

1. Upload the files to `public_html` or your designated folder.
2. In cPanel, navigate to **Setup Node.js App**.
3. Create Application:
   - **Node.js Version:** 20.x or 22.x
   - **Application Mode:** Production
   - **Application Root:** `/` (or your folder)
   - **Application Startup File:** `server.js` (from `.next/standalone`) or `node_modules/next/dist/bin/next` with `start`
4. Add Environment Variable:
   - `DATABASE_URL` = your cPanel PostgreSQL database connection string.
5. Click **Run NPM Install** and then **Run NPM Build** (`npm run build`).
6. Click **Restart**.

---

## 🛠 Features Included

- **5-Step Official Winner Claim Portal (`/`)**
  - Step 1: Verify win (*Ticket Serial Number + 6 Winning Numbers*)
  - Step 2: Winner identity (*Full name, Date of birth, Nationality, Govt ID*)
  - Step 3: Contact & Address (*Active Email, Phone, Preferred Contact, Address*)
  - Step 4: Prize & Payout (*Grand Prize Jackpot payout choice: Lump-Sum vs Annuity*)
  - Step 5: Review & Digital Signature Declaration
- **`🔍 Track claim process` Feature:** Real-time lookup of any submitted claim reference code (`PB-XXXXXXXX`) or ticket serial number.
- **Dual Transactional Email Notifications:** Automatically notifies both claimant and administrator upon submission.
- **Protected Administrator Center (`/admin`):**
  - Persistent login (stays signed in until clicking Sign Out).
  - Bulk / single generation of winning numbers & serials without requiring winner email.
  - Custom prize amount & draw date configuration.
  - Interactive **✏ Edit** modal to adjust numbers, serials, and update claim progress statuses.
  - Real-time linked claim dossiers showing claimant name, email, phone, and country.
  - One-click **🗑 Clear All Records** for fresh starts.
  - Account & SMTP server configuration tab.
- **Official Powerball Branding & Favicon:** High-DPI Powerball logos and multi-layer square favicons across all devices and browsers.
