# Deploying Turboopay Live on a Web Server

This package includes everything needed to deploy **Turboopay** on a live VPS (Ubuntu/Debian) or managed cloud platform.

---

## Option 1: Docker Compose on Any VPS (Fastest & Recommended)

1. **Upload & extract** `turboopay-platform.zip` on your server:
   ```bash
   unzip turboopay-platform.zip && cd turboopay
   ```

2. **Edit `docker-compose.yml`**:
   - Replace `change_this_strong_db_password` with a strong PostgreSQL password.
   - Replace `JWT_SECRET` with a random 64-character secret (`openssl rand -hex 32`).
   - Replace `NEXT_PUBLIC_APP_URL` with your live domain (e.g., `https://pay.yourdomain.com`).

3. **Build & start PostgreSQL + Turboopay**:
   ```bash
   docker compose up -d --build
   ```

4. **Run database migrations & seed initial accounts** (one-time):
   ```bash
   docker compose exec web npx prisma db push
   # To load demo data (admin01, mgr01, mgr02, vendor01, vendor02), run locally or via a one-off node container:
   docker run --rm --network turboopay_default -v $(pwd):/app -w /app -e DATABASE_URL="postgresql://turboopay:change_this_strong_db_password@postgres:5432/turboopay?schema=public" node:20-alpine sh -c "npm install && npx tsx prisma/seed.ts"
   ```

5. **Point your domain with Nginx + Free SSL (Certbot)**:
   ```bash
   sudo cp deploy/nginx.conf /etc/nginx/sites-available/turboopay
   # Edit server_name in /etc/nginx/sites-available/turboopay
   sudo ln -s /etc/nginx/sites-available/turboopay /etc/nginx/sites-enabled/
   sudo nginx -t && sudo systemctl reload nginx
   sudo certbot --nginx -d your-domain.com
   ```

---

## Option 2: Direct Ubuntu VPS (Node.js 20 + PM2 + PostgreSQL)

1. **Install dependencies, build & migrate**:
   ```bash
   cp .env.example .env
   # Edit .env with your PostgreSQL DATABASE_URL and a strong JWT_SECRET
   npm install
   npx prisma generate
   npx prisma migrate deploy
   npm run db:seed
   npm run build
   ```

2. **Start with PM2**:
   ```bash
   npm install -g pm2
   pm2 start npm --name "turboopay" -- start
   pm2 save
   pm2 startup
   ```

3. **Configure Nginx** using `deploy/nginx.conf` and enable HTTPS with `certbot --nginx`.

---

## Option 3: Managed PaaS (Railway / Render / Coolify)

1. Push the `turboopay/` folder to a private GitHub repository.
2. Add a **PostgreSQL** service and link `DATABASE_URL`.
3. Set environment variables: `DATABASE_URL`, `JWT_SECRET`, and `NEXT_PUBLIC_APP_URL`.
4. Set Build Command: `npx prisma generate && npm run build`
5. Set Start Command: `npx prisma migrate deploy && npm run start`
