# FV Sports V2 - build status

Updated 2026-11-25. Plain JavaScript, Fastify API + two Next.js apps, PostgreSQL.

## Built and verified
"Verified" = automated tests pass (`npm test`, run on the laptop by the check watcher) and the flow was clicked through in Chrome on localhost.

| Phase | Area | Tests | Chrome |
|---|---|---|---|
| 5 | Notifications, email templates, bell | yes | yes (bell, unread badges) |
| 6 | Match requests, accept, admin approval | yes | yes |
| 7 | Payments (provider adapter, ledger, webhook, refunds) | yes (dev provider + signed Stripe webhooks) | yes (dev provider) |
| 8 | Team selection, spin wheel (server random, 3 spins) | yes | yes |
| 9-10 | Draft, rosters, admin review, CSV export, Blacktop | yes | yes |
| 11-12 | Tournaments, geo restriction, timed snake draft, bracket | yes | yes (create, join, draft, bracket) |
| 13 | Results, winner claims, champion, match results | yes | yes (admin set winners, tournament completed) |
| 14 | Chat: private, support, league lobbies, image safety, moderation | yes | yes (admin to user message, unread badge) |
| 15 | Profiles, public profile, automatic stats | yes | yes (profile page) |
| 16 | Audit log UI, anonymise user, payments CSV, stat corrections, login history, top selections | yes | audit log page checked |
| 17 | CI workflow, TOTP replay protection, starting terms text | yes (replay) | - |
| 18 | Website content (CMS): hero banners (image/video), Who We Are, Why Fantasy, blogs, FAQs, contact, terms; settings split into General, Match Pricing, Restricted States | yes (uploads: real-byte type check, 5 MB image / 25 MB video limits; CRUD; public visibility) | banner create, validation, oversize rejection, restricted states page checked |
| 19 | Forms redesign (sectioned pages, drag-drop uploads, steppers, debounced search) and messenger-style chat (conversation list, search, tabs, lobbies, new chat, admin intervene, image attach) | UI only | admin chat verified in Chrome (thread send, lobby send, new chat); player-side chat not yet viewed (maintenance mode blocks player login) |
| 20 | Match scaling: query-shaped indexes, batched draft/roster progress for lists, match timeline (match_events), winner integrity checks, league filter | yes (timeline, DB winner check, list) | admin create NFL match, list, timeline, edit, record result checked in Chrome |
| 21 | Tournament bracket as rows (tournament_matches) instead of JSON; tournament_results is now a view; batched publish notifications; list queries use lateral counts + indexes; admin tournament list/detail redesign with league/status filters | yes (existing draft/results/profile suites) | NFL draft->publish->cancel and migrated NBA bracket checked in Chrome |
| 22 | Wheel: readable radial segment labels, final-spin result message, reset request available after teams are locked (admin approve/decline verified) | yes (existing selection suite) | NBA home keep, away 3-spin auto-assign, opponent exclusion, reset approve/decline, error states checked in Chrome |
| 23 | Tournament admin rebuilt as tabs (Overview, Users, Draft, Matches): cover image, team pool (current/all-time) enforced in the draft, add users with a team, start now or after a draft, end with a champion, extra scheduled matches. Gamified tables with icon actions; 10-second polling instead of sockets; consistent page widths | yes (tournament-admin suite) | NBA all-time cup created, 4 players added with teams, started, extra match, ended; checked in Chrome |

## Not done / needs the owner
- Stripe: only the dev simulator and signed-webhook handling are tested. Real card payments need STRIPE_SECRET_KEY, STRIPE_PUBLISHABLE_KEY, STRIPE_WEBHOOK_SECRET in .env. Venmo is deferred as decided.
- Email: no SMTP provider yet; mails are logged (dev only: GET /api/v1/dev/mail?to=...). Needs SMTP credentials.
- Geo restriction uses the US state found from the user's IP address (ipwho.is, cached). Outside production, localhost falls back to the state saved on the profile, or GEO_DEV_STATE.
- Roster PDF: replaced by CSV export plus a print view.
- NFL roster/depth rules are generic; confirm the real rules with the business.
- Terms text is a starting draft (migration 016). A lawyer must review it before launch.
- Catalog seed: 75 NFL rows are skipped (73 point at V1 team 40, missing from the team export; 2 have no position). Decide whether to add the missing team.
- XLSX import and a separate upload store: not built. Chat/profile images are stored in PostgreSQL (PNG/JPEG/WebP checked by content, 2 MB / 1 MB limits).
- Load and penetration testing, backup/restore and the go-live runbook (rest of phase 17) were not done.
- Playwright e2e tests were not extended for phases 5-16; coverage is API tests plus manual Chrome runs.

## Running
start-dev.bat -> admin http://localhost:3000, player app http://localhost:3001, API http://localhost:4000. Dev admin credentials: .data/dev-admin.txt. Test results: .data/checks.txt and .data/checks-full.txt.

## Terminology
- **User**: someone who signs up on the website (account, profile, joins matches and tournaments). Shown as "Users" in the admin console and user app.
- **Player**: a real NBA/NFL player in the catalog. Users draft players onto their roster. Shown as "Players" under Catalog.
- Code identifiers that still say "player" for a signed-in user (the web `PlayerShell`/`player` API client, `maxPlayers`, `max_players`) are internal names kept to avoid breaking the API contract.

## Match draft and rosters (latest)
- **Pick timer:** every match-draft turn runs on a server deadline (`match_drafts.turn_deadline`, length = `DRAFT_TURN_SECONDS`, default 180). When it expires the best-rated available player is auto-picked (lazy on read plus a 5 s background job). Users, and the admin Draft tab on a match, show the same ring (`TurnTimer`).
- **Polling:** the draft page polls the tiny `GET /matches/:id/draft/status` every 10 s and only refetches the full draft when something changed.
- **Admin draft control:** `GET /admin/matches/:id/draft`, `.../players`, `POST .../pick` (picks for whoever is on the clock, audited) and `.../auto-pick`.
- **Roster builder:** `RosterBuilder` in `packages/ui` draws an NBA court and an NFL field (offense, defense, special teams) as SVG. A field spot is one (position, depth) pair, so it maps 1:1 onto the stored roster rows; extra players go to the bench. Used by the user roster page and, read-only, by the admin match Rosters tab and the Roster review queue.
- **Dev passwords:** all dev accounts use `12345678` (admin dev MFA code `123456`).
