# AURA LIVE — Production Deployment Guide (Linux VPS)

## 1. Server prerequisites
```bash
# Ubuntu 22.04/24.04 example
sudo apt update && sudo apt install -y nginx certbot python3-certbot-nginx
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash - && sudo apt install -y nodejs
# MySQL 8 + Redis 7 (or use docker compose)
```

## 2. Layout
```
/var/www/aura-live/            # this repo
  server/    → runs on :4000 via pm2
  apps/web/dist/   → served by nginx at /
  admin/dist/      → served by nginx at /admin
```

## 3. Backend with pm2
```bash
cd /var/www/aura-live/server
npm install && npm run build
cp ../.env .env   # ensure production values: NODE_ENV=production, strong JWT secrets, real DB creds
node migrations/run.js
node seeders/seed.ts --skip   # production: do NOT seed demo users; create admin manually if needed
npm i -g pm2
pm2 start dist/server.js --name aura-server
pm2 startup && pm2 save
```

## 4. Frontends
```bash
cd ../apps/web && npm install && npm run build
cd ../../admin && npm install && npm run build
```

## 5. Nginx
```nginx
server {
  server_name yourdomain.com www.yourdomain.com;
  client_max_body_size 10m;

  # Web app
  root /var/www/aura-live/apps/web/dist;
  index index.html;
  location / { try_files $uri $uri/ /index.html; }

  # Admin panel
  location /admin {
    alias /var/www/aura-live/admin/dist;
    try_files $uri $uri/ /admin/index.html;
  }

  # API + uploads
  location /api/ { proxy_pass http://127.0.0.1:4000; proxy_set_header Host $host; proxy_set_header X-Forwarded-For $remote_addr; }
  location /uploads/ { proxy_pass http://127.0.0.1:4000; }

  # Socket.IO websocket
  location /socket.io/ {
    proxy_pass http://127.0.0.1:4000;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
  }
}
```
HTTPS:
```bash
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
```

## 6. Docker Compose alternative
```bash
cp .env.example .env   # fill values
docker compose up -d --build
# services: mysql (:3306), redis (:6379), server (:4000), web (:8080), admin (:8081)
```

## 7. Post-deploy checklist
- [ ] HTTPS active; `API_PUBLIC_URL`, `WEB_APP_URL`, `ADMIN_APP_URL` match your domains
- [ ] Strong `JWT_*` secrets (server refuses to boot with dev defaults in production)
- [ ] Razorpay live keys + webhook URL `https://yourdomain.com/api/v1/payments/webhook/razorpay` registered in dashboard
- [ ] LiveKit cloud or self-hosted LiveKit configured
- [ ] SMTP configured (verification emails actually send)
- [ ] Backups scheduled (`mysqldump` cron)
- [ ] `pm2 logs aura-server` clean; `/api/v1/admin/health` all green
- [ ] Admin default password changed
