Expand description
The open-chess server, as a library (the open-chess binary is a
thin wrapper; integration tests drive the same pieces).
Modules§
- analyse
- The fair-play worker (
open-chess analyse): takes finished games off the queue, has Stockfish evaluate every position, and stores a screening report per human player. With no game to screen, it evaluates positions people confirmed from board photos for the position dictionary, scoring every legal move. Run as many as you like (games are claimed with SKIP LOCKED and a lease, so a crashed worker’s game is picked up again). - app
- The shared context, and the HTTP server’s routes.
- auth
- Who is calling: the site’s own API tokens (bearer) and session cookies.
- challenges
- Challenges: create (optionally accepted at once with the opponent’s token), accept, decline, cancel, list, and lapse.
- config
- Settings, all from the environment (containers on Kubernetes and
Cloudflare both pass configuration that way). Every variable has a
working default except
DATABASE_URL. - db
- Postgres: the connection pool, this server’s schema, and the LISTEN connection that fans changes out to every replica.
- error
- API errors, in Lichess’s shape:
{"error": "..."}with a status code. - http
- HTTP handlers, grouped as Lichess’s API docs group them.
- metrics
- Prometheus metrics for the chess server.
- model
- Rows (accounts, games, challenges) and their Lichess JSON views.
- play
- Playing a game: moves, resignations, draws, takebacks, aborts, claims, the end of a game (ratings, notifications) and the sweeper that flags clocks and lapses challenges.
- vision
- Reading a chess board from a photo.
Functions§
- spawn_
background - What every serving replica runs besides HTTP: the LISTEN connection that brings other replicas’ changes in, and the clock/challenge sweeper (rows are claimed with SKIP LOCKED, so replicas don’t collide).
- stopped
- Resolves once shutdown has begun (the watch guard isn’t held, so the
future stays
Send).