How Hot Shots is built

The code runs in four places: the Tipster's browser, the TanStack Start server on Vercel, the Supabase database, and Squiggle, the AFL data service. Click a box on the map, or a topic under it, to open that part of the system.

The browser only ever talks to the site's own server, plus a Realtime WebSocket during Games. Only the two sync endpoints call Squiggle, and Supabase's own scheduler starts them. Every other read comes from the site's own tables.

Live scores

One connection to Squiggle for the whole site, held in runs of about five minutes. A database trigger fans every change out to signed-in tabs over Supabase Realtime.

pg_croneach minute, if a Game is onPOST, if lease freeEvent APIgoals, clock, resultLive ingest≤ 290 s a run · leaseafl_games5 live fieldsRealtimeafl:live-gamesTabTabTabSSEupdatetrigger
One goal, end to end. The trigger only fires when one of the five live fields changes: home score, away score, game clock, completion or winner.
pg_croningestrun 1 · one connectionrun 2 · reconnectrun 3~10 s gap~10 s gap05 min10 min15 min
Fifteen minutes of a live Game. Filled ticks start a run. Hollow ticks find the lease held and do nothing. Each run stops at 290 seconds, just short of five minutes, and the next tick starts the next one. On connect, Squiggle sends each live Game's current state, which covers the gap.

How it works

  1. Takes the lease, a single database row that only one run can hold. If another run has it, this one stops straight away.
  2. Checks afl_games for a Game that's live or starts within 30 minutes. If there's none, it stops.
  3. Opens sse.squiggle.com.au/events, which covers every Game, with the site's User-Agent.
  4. Writes each event's live fields to afl_games. A Game that finishes without a winner gets one from the scores, and a Draw gets none.
  5. If the connection drops, it reconnects after 2, 4, 8, 16, then 30 seconds. A refusal such as a 403 stops the run.
  6. At about 290 seconds it closes, releases the lease, and records a live run.

Rules

  • In the browser, a tab joins the channel only while a Game is live or about to start, and leaves when the last one finishes.
  • It gets a short-lived access token from getRealtimeToken, never the refresh token, and refreshes it 5 minutes before it expires.
  • If the channel drops, it rejoins (2 s, doubling to 60 s), then refetches Games once in case it missed an update.

Why

The earlier relay opened one Squiggle connection per open tab. Now it's one for the site, and Supabase holds the tabs' connections.

Decision records: ADR 0010, ADR 0005

Stack and testing

Built with

  • React 19, the interface
  • TanStack Start and Router, file-based routes and server functions
  • TanStack Query, server state, cached in the browser
  • Supabase, Postgres, Auth and Realtime
  • Vercel, hosting for the server
  • Tailwind CSS v4 and shadcn/ui, styling and components
  • Zod, validating what Squiggle sends and what the server receives

How it's tested

  • Vitest unit and component tests, next to the code they cover.
  • Storybook stories for components and diagrams, including this page's.
  • The Demo: the whole site running in the browser over a snapshot, so every page can be exercised end to end with no accounts or live data.

Read the code in the repository, the decision records, or AGENTS.md, the guide the project's contributors and coding agents work from.

Decisions

Each decision record explains what was chosen and the alternatives it beat.