# Deployment — HostGator VPS (WHM/cPanel, Linux)

## 1. Server prep (as root via SSH)

```bash
# Python 3.11+ and Node 20+
dnf install -y python3.11 python3.11-pip   # AlmaLinux/CentOS
curl -fsSL https://rpm.nodesource.com/setup_20.x | bash - && dnf install -y nodejs
```

Create a MySQL database + user in WHM/cPanel (e.g. `trading_lab`), then load
the schema: `mysql trading_lab < database/schema.sql` (optional — the backend
auto-creates tables on first boot).

## 2. Backend (FastAPI + Uvicorn behind Apache/Nginx)

```bash
cd /opt && git clone <your-repo> ai-trading-signal-lab
cd ai-trading-signal-lab/backend
python3.11 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
cp ../.env.example .env   # set DATABASE_URL (MySQL), SECRET_KEY, FRONTEND_ORIGIN
```

Install the systemd service (edit paths first):

```bash
cp ../deployment/trading-lab-api.service /etc/systemd/system/
systemctl daemon-reload && systemctl enable --now trading-lab-api
```

## 3. Frontend (Next.js)

```bash
cd /opt/ai-trading-signal-lab/frontend
echo "NEXT_PUBLIC_API_URL=https://api.yourdomain.com" > .env.local
npm ci && npm run build
npm i -g pm2 && pm2 start "npm run start" --name trading-lab-web && pm2 save
```

## 4. Reverse proxy + SSL

Use `deployment/nginx.conf.example` (or the Apache equivalent via WHM):
frontend on `yourdomain.com` → localhost:3000, API on `api.yourdomain.com` →
localhost:8000. Issue SSL via WHM AutoSSL / Let's Encrypt for both hosts.

## 5. Cron jobs (cPanel → Cron Jobs)

Install `deployment/crontab.example`:
- market scan every 15 min during market hours (Mon–Fri)
- mark-to-market + daily report at 4:15 PM ET

## 6. GitHub Actions

`.github/workflows/ci.yml` builds the frontend and runs backend tests on every
push/PR. Add a deploy job (rsync/SSH) once the VPS is provisioned.

## Notes

- Never expose the backend without SSL.
- Set a strong `SECRET_KEY`; rotate on schedule.
- The MVP has no live-trading paths; keep it that way until Phase 3 review.
