Expand description
The open-chess server, as a library (the open-chess binary is a
thin wrapper; integration tests drive the same pieces).
Modules§
- ai
- Playing the computer:
POST /api/challenge/aiwithlevel1–8, as on Lichess. The computer is open-chess’s own engine (chess_analysis::bot) at that level, played by the server itself: a game againstai-level-N, a bot account made on first use, with the level’s fixed rating (Level::rating). A game against it can be rated, as an offline game against the same level in the iOS app is: the player’s rating moves, the computer’s never does, and Glicko gives little for beating a level far below you, so it can’t be farmed. - 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.
- apple
- Sign in with Apple, for the iOS app.
- auth
- Who is calling: this server’s API tokens (bearer) and session cookies.
- challenges
- Challenges: create (optionally accepted at once with the opponent’s token), accept, decline, cancel, list, and lapse.
- cli
- The server’s commands, as the
open-chessprogram runs them (theopen-chesscrate; built with itsserverfeature): - 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.
- passkeys
- Passkeys (WebAuthn): registering them, signing in (or making an account) with one instead of a password, and the passkey check that switches on an admin’s or manager’s rights.
- 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.
- push
- Apple push notifications for the iOS app: “your move” in correspondence
games, a result to confirm. Sent over APNs’ HTTP/2 API with a token
signed by the team’s
.p8key (ES256), which is kept for 50 minutes as Apple asks. Off unless CHESS_APNS_KEY, _KEY_ID and _TEAM_ID are set. A device APNs reports gone is forgotten. - 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).