# Deploying PintRush

Nothing here is configured yet — these are the steps to take when you are ready. PintRush needs three
things in production:

| Piece | Recommended host | Why |
|---|---|---|
| Website (`apps/web`, Next.js) | **Vercel** | Zero-config Next.js, global CDN for the marketing pages |
| Game server (`apps/game-server`) | **Render** (Web Service) or **Fly.io** | Must be a long-running process with WebSockets — not serverless |
| PostgreSQL | **Neon**, **Supabase** or Render Postgres | Managed backups; both apps share it |
| Redis (optional) | Upstash / Render Key Value | Only needed to fan out broadcasts across several game-server processes |

Rough pilot cost: Vercel Hobby/Pro ($0–20), Render Starter ($7), Neon free tier → **$7–27/month**.

> The game server keeps live rooms in memory. Run **one** instance (the "single-process limit" in
> `docs/ARCHITECTURE.md`). That comfortably handles a pilot of 3–5 bars. Scaling out later means
> routing each room to a fixed instance, then turning on `REDIS_URL`.

---

## 1. Domain
1. Register `pintrush.com` (it was unregistered on 2026-10-29) and, ideally, the backups listed in the spec.
2. Plan two hostnames: `pintrush.com` (website) and `play.pintrush.com` or `game.pintrush.com` (game server).

## 2. Database
1. Create a Postgres 16+ database (Neon: new project → copy the **pooled** connection string for the web app
   and the **direct** string for migrations).
2. From a machine with the repo: `DATABASE_URL=<direct url> pnpm --filter @pintrush/db exec prisma db push`
   (or `prisma migrate deploy` once migrations are committed), then `DATABASE_URL=<direct url> pnpm db:seed`.
3. Change the seeded passwords immediately (set `SEED_ADMIN_PASSWORD` / `SEED_HOST_PASSWORD` before seeding,
   and remove the demo host accounts you don't need).

## 3. Game server (Render)
- **New Web Service** → repo root, runtime Node 24.
- Build command: `corepack enable && pnpm install --frozen-lockfile`
- Start command: `pnpm --filter @pintrush/game-server start`
- Health check path: `/health`
- Environment:
  - `NODE_ENV=production`
  - `DATABASE_URL=<pooled or direct url>`
  - `AUTH_SECRET=<same 32+ char secret as the website>`
  - `WEB_ORIGIN=https://pintrush.com` (comma-separate extra origins, e.g. preview URLs)
  - `TRUST_PROXY=1` (Render/Fly put one proxy in front; the server then reads the client address the proxy
    appended to `X-Forwarded-For`, which per-IP limits rely on. Use the number of proxies if there are more.)
  - `DEVICE_SALT=<random string>`
  - optional `REDIS_URL`
- Add the custom domain `game.pintrush.com`. WebSockets work on Render web services out of the box.
- Fly.io alternative: `fly launch` with an internal port of 4000, one machine, `auto_stop_machines = false`
  (a stopped machine would end live games).

## 4. Website (Vercel)
- Import the repo; **Root Directory** `apps/web`; framework Next.js. Vercel detects pnpm workspaces.
- Environment:
  - `DATABASE_URL=<pooled url>`
  - `AUTH_SECRET=<same secret as the game server>`
  - `NEXT_PUBLIC_SITE_URL=https://pintrush.com`
  - `NEXT_PUBLIC_GAME_SERVER_URL=https://game.pintrush.com`
  - `ANALYTICS_SALT=<random string>`
  - no `TRUST_PROXY` needed on Vercel (the site reads Vercel's client-IP header). If you host the website
    elsewhere behind a proxy, set `TRUST_PROXY` to the number of proxies, or per-IP limits fall back to
    one shared bucket.
  - optional `SMTP_URL` (e.g. `smtps://user:pass@smtp.provider.com:465`) and `ADMIN_NOTIFY_EMAIL` — without
    them, pilot-form emails are only logged.
- Add `pintrush.com` and `www.pintrush.com` (redirect www → apex).

## 5. After the first deploy
- Visit `/admin/login` with the seeded admin, create the real pilot venues, hosts and rooms.
- For each room: open the host dashboard → **TV link** → open it on the bar's TV browser (full screen).
  Print the QR poster from the same page.
- Run a 10-minute test night with staff phones before the first public night.
- Check Lighthouse on the marketing pages (target ≥ 90 performance / accessibility / SEO).

## 6. Before going public
- Lawyer review of `/legal/privacy` and `/legal/terms` (both are flagged as drafts).
- USPTO trademark search for "PintRush" (Class 41 entertainment; Classes 9/42 software).
- Confirm no prizes of value are offered until reviewed per jurisdiction (the product has no paid entry
  and no wagering).
- Music: the seed packs contain trivia only — no recordings, no lyrics. Playing music in a venue needs its
  own public-performance licensing, handled separately.
- Backups: enable point-in-time recovery on the database.
