Studies

Detailed behavior for the repertoire list and study editor.

Purpose and access

A study is a named opening repertoire for one fixed side, represented as a tree of chess positions and moves. It is private to the Lichess account that created it. All study screens require Lichess sign-in.

When signed out, the Studies page and editor show a short sign-in prompt and a Sign in link. If a requested study ID does not belong to the account or does not exist, show “Study not found.”

Study list

Study data model

Persist id, name, side, tree, explorerSettings, optional startNodeId, and calculation data. The tree is a node map: each node has an ID, SAN move (null at the root), parent ID, and ordered child IDs. Keep a root ID and next ID. Child order matters: the first child is the main line; later children are variations.

The side is chosen as Playing White or Playing Black only when creating a study. Show a selector for a new study and a read-only badge for an existing one. The server must ignore attempts to change the side during an update.

Editor layout and move editing

The editor contains a name input and side badge/selector, then a chessboard, a clickable move tree with controls, an Opening Explorer panel, and a Stockfish panel. New studies start at the normal initial chess position with an empty root. Apply the user's Lichess board theme and piece set when available; otherwise use the default board appearance.

Navigation and actions

Starting point

The starting point changes where Stats calculations begin, not the tree or move numbering. Default is the actual root (startNodeId: null). When a non-root node is selected, the action sets that node as the starting point; selecting the active starting node changes the action to Clear starting point. Clearing restores the root default.

Visually color the designated move muted blue and show a badge by the study name with its actual move notation. Do not renumber the move tree. Auto-save this toggle like other study edits. If deleting a subtree removes the chosen node, clear the starting point. Backend calculations must also fall back to the true root if a stored ID no longer exists.

Opening Explorer

Explorer is below the board and updates for the currently selected FEN. Its enable checkbox hides the panel and disables its settings when off. Changing a setting fetches data for the current position. Show a loading state while fetching and a recoverable unavailable message on failure.

Explorer is not anonymous in this app: a signed-in Lichess session is required. On an HTTP 429, report that the user must wait before retrying rather than rapidly retrying.

Stockfish

The checkbox lazily starts a local Stockfish WASM worker on first use. Analyze the current position with MultiPV 5. Draw up to five ranked arrows on the board, green through red, and show a matching ranked list with SAN and evaluation. Selecting a candidate plays it like an Explorer row. Re-analyze whenever the selected node changes; stop/discard stale searches when navigation moves on. Turning the option off clears arrows/results and terminates the worker. Game-over positions show a game-over state and no candidate moves.

Auto-save and errors

Study CRUD and calculation data are account-scoped in SQLite. Auto-save edits after a short debounce and show a persistent status. If a save fails, keep the editor state and show the error; retry after another edit or when connectivity returns. Require a non-empty name before creating a new study. Deleting a study requires confirmation and removes its practice history.

Relevant behavior is implemented across the study list/editor, tree helpers, study API, Explorer service, and shared Stockfish client.