The short version
FreeChessCoach is a personal chess coach: it analyses your games and talks you through them, Socratically, grounded in what the engine says. The product is free forever, which is only possible because of the architecture: almost nothing that costs money runs on the server.
1. The player’s browser is a compute node
Every signed-in tab keeps one authenticated WebSocket to the API. Over it, the server sends work with a request ID, and the tab answers:
- Engine: Stockfish compiled to WebAssembly runs in the tab, as the main engine in Browser mode and as a “lite” source of extra candidate lines in every mode.
- Fetch: calls to a cloud engine API are made from the player’s own IP, so the rate limits are theirs.
- Local LLM: a model running on the player’s computer (LM Studio, Ollama), which the server could never reach on its own.
It’s built like a small distributed system. Sockets bind to the authenticated user only. Work goes to the tab the player used most recently, because background tabs get throttled. If a tab closes, only its own requests fail and the next tab takes over, and on reconnect the server re-queues paused analyses. Background workers reach the registry through an internal relay with a token the public proxy never routes.
2. Bring your own key, without the server being able to read it
Players connect OpenAI, Anthropic, OpenRouter, any compatible endpoint, or a local model, and pay at cost. The hard part is holding someone’s API key responsibly:
- The setup is encrypted with AES-256-GCM under a key derived from the player’s unlock phrase with scrypt. Neither the phrase nor the plaintext is stored. New phrases must pass a zxcvbn strength check that also treats the player’s own name and email as guessable.
- Unlocking puts the setup in Redis, encrypted again with a deployment key, under an HMAC-derived name, expiring after inactivity. A database dump or a Redis dump alone recovers no key.
- Changing models uses a strict schema with no endpoint or key field, so a hijacked session can’t point a saved key at a different host. Outbound calls only go to public addresses: user-supplied URLs are an SSRF risk.
3. A gateway that speaks to any model
The gateway doesn’t ask the player which API format their endpoint speaks: it probes each model with a real tool call (OpenAI Responses, then Anthropic Messages, then Chat Completions) and stores what works, per model. Two tiers keep costs sensible: standard for the live coach, light for planning, summaries and compression.
Local models get their own treatment. Streaming goes over the tunnel frame by frame, reasoning included. Calls are serialised per user because a local server answers one at a time. The prompt is lighter for small models (one-line tool cues, plain-English game facts, a deterministic session goal), because those details were observed to confuse small quantised models.
4. An engine pipeline engineered for cost
Every engine question, from the review, the coach, hints or bots, goes through one pipeline:
- The Lichess evaluation index: about 394 million positions the community already evaluated (CC0), stored as a single sorted, fixed-width ~10 GB file and read with a binary search. No database server, no native dependency. Most positions end here.
- On a miss, the player’s chosen engine method, then a reliable fallback, with a circuit breaker per job.
- Browser-lite only adds breadth. It never overrides the authoritative line.
Analysis is chunked and resumable: evals are saved after every 6 positions, so a crash picks up where it stopped and re-analysing a game makes zero engine calls. Repeated positions are searched once. Positions get 3 lines, and only the 0–2 brilliant-move candidates per game get 5. Each move gets one verdict, using cheap gates and per-reason ceilings with an early stop, and a replay benchmark measures every step. Importing and reviewing games calls no model at all, so it’s free to run.
5. A coach agent with hard boundaries
The coach is an agent with 25 tools: showing and annotating the board, expecting a move, testing a hypothetical line, reading engine analysis, recording findings, and updating focus areas and conversation threads. The rules that keep it trustworthy:
- Tools call services, never SQL or infrastructure, and guards decide what each phase of a session may do.
- The engine is authoritative: the coach asks before it tells, and every claim traces back to an evaluation.
- History is append-only and sessions survive restarts. Long conversations are summarised and compacted while the raw history is kept.
Bots are engineered too: they make human-like mistakes, plausible moves near what the player just did, checked against the engine until one is as bad as the rating calls for.
6. Security as a practice
A STRIDE threat model maps seven trust boundaries, from the internet through the auth proxy and the browser tunnel to the supply chain. It found real issues, each fixed with a test or a rendered-config assertion and recorded with its commit:
- header spoofing behind the proxy
- SSRF through user-supplied AI endpoints
- cross-site WebSocket hijacking
- ReDoS in PGN parsing
- a tab that would run any fetch it was sent
- missing browser security headers
CodeQL, Dependabot and NetworkPolicies keep it that way.
7. Built spec-first, with AI coding agents
The first commit, on 28 July 2026, contained no code: it was the specs, the architecture, the prompts, a plan and an AGENTS.md contract for coding agents. Four months later the repository has about 700 commits, roughly 100k lines of TypeScript and 321 test files, with CI running only the tests affected by each change. The same approach as GoGetCV: agents move fast inside guardrails a senior engineer designs.
Outcome
FreeChessCoach is live at freechesscoach.org and open source (PolyForm Noncommercial). On the cluster it’s a web server, an API, a worker and two engine replicas behind oauth2-proxy, using the platform’s shared Postgres and Redis.
TypeScript
Fastify 5
React 19
Vite
PostgreSQL
- Kysely
- graphile-worker
Redis
- Stockfish
WebAssembly
- WebSocket
Vercel AI SDK
Zod
- oauth2-proxy
Helm
CodeQL

