# bb182/chess-scramble architecture

> Architecture diagram of the GitHub repository bb182/chess-scramble, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-04). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bb182/chess-scramble
- Repository: https://github.com/bb182/chess-scramble

## Overview

minichess is a Gardner 5×5 chess engine with three user-facing workflows: play through a browser UI, run headless agent matches, and train/evaluate AlphaZero-style agents. The game engine supplies legal moves, notation, and outcomes; agents use it directly, while the Gymnasium environment provides the observation/action interface used by RL. The README documents the full training loop and UI capabilities; some links among unsampled RL modules are supported by the SOURCE INDEX rather than inspected implementation excerpts.

Main entry points: [`src/minichess/core/board.py`](https://github.com/bb182/chess-scramble/blob/main/src/minichess/core/board.py) (Board and rules), [`src/minichess/web/server.py`](https://github.com/bb182/chess-scramble/blob/main/src/minichess/web/server.py) (WebSocket game server), [`src/minichess/core/move.py`](https://github.com/bb182/chess-scramble/blob/main/src/minichess/core/move.py) (Move encoding), [`src/minichess/cli.py`](https://github.com/bb182/chess-scramble/blob/main/src/minichess/cli.py) (Command line)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_engine["Chess engine"]
  node_board["Board and rules<br/>[board.py]"]
  node_move["Move encoding<br/>[move.py]"]
  node_notation["Notation and FEN<br/>[notation.py]"]
  node_constants["Board geometry<br/>[constants.py]"]
  node_perft["Move generation check<br/>[perft.py]"]
end

subgraph group_play["Play and agents"]
  node_cli["Command line<br/>[cli.py]"]
  node_agent_protocol["Agent protocol<br/>[base.py]"]
  node_registry["Agent registry<br/>[registry.py]"]
  node_minimax["Minimax agent<br/>[minimax.py]"]
  node_random["Random agent<br/>[random_agent.py]"]
  node_arena["Match arena<br/>[arena.py]"]
end

subgraph group_rl["RL training"]
  node_environment["RL environment<br/>[env.py]"]
  node_network["Policy value network<br/>[network.py]"]
  node_mcts["Batched MCTS<br/>[mcts.py]"]
  node_selfplay["Self-play generation<br/>[selfplay.py]"]
  node_replay["Replay buffer<br/>[replay.py]"]
  node_symmetry["Board symmetry<br/>[symmetry.py]"]
  node_training["Training orchestration<br/>[train.py]"]
  node_az_agent["AlphaZero agent<br/>[agent.py]"]
end

subgraph group_web["Browser UI"]
  node_web_server["WebSocket game server<br/>[server.py]"]
  node_web_app["Browser board<br/>[app.js]"]
end

node_user(("User"))
node_browser(("Browser player"))

node_user -->|"runs commands"| node_cli
node_cli -->|"starts play UI"| node_web_server
node_cli -->|"runs matches"| node_arena
node_cli -->|"starts training"| node_training
node_cli -->|"runs perft"| node_perft
node_board -->|"parses and formats"| node_notation
node_board -->|"uses geometry"| node_constants
node_board -->|"encodes moves"| node_move
node_notation -->|"converts moves"| node_move
node_perft -->|"counts positions"| node_board
node_minimax -->|"searches positions"| node_board
node_minimax -->|"scores pieces"| node_constants
node_minimax -->|"selects moves"| node_move
node_random -->|"gets legal moves"| node_board
node_random -->|"returns move"| node_move
node_registry -->|"creates agent"| node_minimax
node_registry -->|"creates agent"| node_random
node_registry -->|"creates agent"| node_az_agent
node_arena -->|"resolves agent specs"| node_registry
node_arena -->|"plays game"| node_board
node_arena -->|"invokes agents"| node_agent_protocol
node_environment -->|"steps game state"| node_board
node_environment -->|"maps actions"| node_move
node_network -->|"uses observation shape"| node_environment
node_network -->|"uses action count"| node_move
node_mcts -->|"searches positions"| node_board
node_selfplay -->|"runs search"| node_mcts
node_selfplay -->|"evaluates leaves"| node_network
node_selfplay -->|"plays games"| node_board
node_replay -->|"augments samples"| node_symmetry
node_training -->|"generates games"| node_selfplay
node_training -->|"stores samples"| node_replay
node_training -->|"trains network"| node_network
node_training -->|"evaluates agents"| node_arena
node_az_agent -->|"searches moves"| node_mcts
node_az_agent -->|"loads checkpoint"| node_network
node_browser -->|"sends game intents"| node_web_server
node_web_server -->|"serves board assets"| node_web_app
node_web_server -->|"owns game state"| node_board
node_web_server -->|"resolves opponents"| node_registry
node_web_server -->|"discovers checkpoints"| node_az_agent

click node_cli "https://github.com/bb182/chess-scramble/blob/main/src/minichess/cli.py"
click node_board "https://github.com/bb182/chess-scramble/blob/main/src/minichess/core/board.py"
click node_move "https://github.com/bb182/chess-scramble/blob/main/src/minichess/core/move.py"
click node_notation "https://github.com/bb182/chess-scramble/blob/main/src/minichess/core/notation.py"
click node_constants "https://github.com/bb182/chess-scramble/blob/main/src/minichess/core/constants.py"
click node_perft "https://github.com/bb182/chess-scramble/blob/main/src/minichess/core/perft.py"
click node_agent_protocol "https://github.com/bb182/chess-scramble/blob/main/src/minichess/agents/base.py"
click node_registry "https://github.com/bb182/chess-scramble/blob/main/src/minichess/agents/registry.py"
click node_minimax "https://github.com/bb182/chess-scramble/blob/main/src/minichess/agents/minimax.py"
click node_random "https://github.com/bb182/chess-scramble/blob/main/src/minichess/agents/random_agent.py"
click node_arena "https://github.com/bb182/chess-scramble/blob/main/src/minichess/arena.py"
click node_environment "https://github.com/bb182/chess-scramble/blob/main/src/minichess/env.py"
click node_network "https://github.com/bb182/chess-scramble/blob/main/src/minichess/rl/network.py"
click node_mcts "https://github.com/bb182/chess-scramble/blob/main/src/minichess/rl/mcts.py"
click node_selfplay "https://github.com/bb182/chess-scramble/blob/main/src/minichess/rl/selfplay.py"
click node_replay "https://github.com/bb182/chess-scramble/blob/main/src/minichess/rl/replay.py"
click node_symmetry "https://github.com/bb182/chess-scramble/blob/main/src/minichess/rl/symmetry.py"
click node_training "https://github.com/bb182/chess-scramble/blob/main/src/minichess/rl/train.py"
click node_az_agent "https://github.com/bb182/chess-scramble/blob/main/src/minichess/rl/agent.py"
click node_web_server "https://github.com/bb182/chess-scramble/blob/main/src/minichess/web/server.py"
click node_web_app "https://github.com/bb182/chess-scramble/blob/main/src/minichess/web/static/app.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_board,node_move,node_notation,node_constants,node_perft,node_user,node_browser toneBlue
class node_cli,node_agent_protocol,node_registry,node_minimax,node_random,node_arena toneAmber
class node_environment,node_network,node_mcts,node_selfplay,node_replay,node_symmetry,node_training,node_az_agent toneMint
class node_web_server,node_web_app toneRose
```

## Components

### Chess engine

- [Board and rules](https://github.com/bb182/chess-scramble/blob/main/src/minichess/core/board.py): `src/minichess/core/board.py`
- [Move encoding](https://github.com/bb182/chess-scramble/blob/main/src/minichess/core/move.py): `src/minichess/core/move.py`
- [Notation and FEN](https://github.com/bb182/chess-scramble/blob/main/src/minichess/core/notation.py): `src/minichess/core/notation.py`
- [Board geometry](https://github.com/bb182/chess-scramble/blob/main/src/minichess/core/constants.py): `src/minichess/core/constants.py`
- [Move generation check](https://github.com/bb182/chess-scramble/blob/main/src/minichess/core/perft.py): `src/minichess/core/perft.py`

### Play and agents

- [Command line](https://github.com/bb182/chess-scramble/blob/main/src/minichess/cli.py): `src/minichess/cli.py`
- [Agent protocol](https://github.com/bb182/chess-scramble/blob/main/src/minichess/agents/base.py): `src/minichess/agents/base.py`
- [Agent registry](https://github.com/bb182/chess-scramble/blob/main/src/minichess/agents/registry.py): `src/minichess/agents/registry.py`
- [Minimax agent](https://github.com/bb182/chess-scramble/blob/main/src/minichess/agents/minimax.py): `src/minichess/agents/minimax.py`
- [Random agent](https://github.com/bb182/chess-scramble/blob/main/src/minichess/agents/random_agent.py): `src/minichess/agents/random_agent.py`
- [Match arena](https://github.com/bb182/chess-scramble/blob/main/src/minichess/arena.py): `src/minichess/arena.py`

### RL training

- [RL environment](https://github.com/bb182/chess-scramble/blob/main/src/minichess/env.py): `src/minichess/env.py`
- [Policy value network](https://github.com/bb182/chess-scramble/blob/main/src/minichess/rl/network.py): `src/minichess/rl/network.py`
- [Batched MCTS](https://github.com/bb182/chess-scramble/blob/main/src/minichess/rl/mcts.py): `src/minichess/rl/mcts.py`
- [Self-play generation](https://github.com/bb182/chess-scramble/blob/main/src/minichess/rl/selfplay.py): `src/minichess/rl/selfplay.py`
- [Replay buffer](https://github.com/bb182/chess-scramble/blob/main/src/minichess/rl/replay.py): `src/minichess/rl/replay.py`
- [Board symmetry](https://github.com/bb182/chess-scramble/blob/main/src/minichess/rl/symmetry.py): `src/minichess/rl/symmetry.py`
- [Training orchestration](https://github.com/bb182/chess-scramble/blob/main/src/minichess/rl/train.py): `src/minichess/rl/train.py`
- [AlphaZero agent](https://github.com/bb182/chess-scramble/blob/main/src/minichess/rl/agent.py): `src/minichess/rl/agent.py`

### Browser UI

- [WebSocket game server](https://github.com/bb182/chess-scramble/blob/main/src/minichess/web/server.py): `src/minichess/web/server.py`
- [Browser board](https://github.com/bb182/chess-scramble/blob/main/src/minichess/web/static/app.js): `src/minichess/web/static/app.js`

### Other components

- **User**
- **Browser player**

## Connections

- User → Command line: runs commands (evidence: `README.md`)
- Command line → WebSocket game server: starts play UI (evidence: `src/minichess/cli.py`)
- Command line → Match arena: runs matches (evidence: `src/minichess/cli.py`)
- Command line → Training orchestration: starts training (evidence: `src/minichess/cli.py`)
- Command line → Move generation check: runs perft (evidence: `src/minichess/cli.py`)
- Board and rules → Notation and FEN: parses and formats (evidence: `src/minichess/core/board.py`)
- Board and rules → Board geometry: uses geometry (evidence: `src/minichess/core/board.py`)
- Board and rules → Move encoding: encodes moves (evidence: `src/minichess/core/board.py`)
- Notation and FEN → Move encoding: converts moves (evidence: `src/minichess/core/notation.py`)
- Move generation check → Board and rules: counts positions (evidence: `src/minichess/core/perft.py`)
- Minimax agent → Board and rules: searches positions (evidence: `src/minichess/agents/minimax.py`)
- Minimax agent → Board geometry: scores pieces (evidence: `src/minichess/agents/minimax.py`)
- Minimax agent → Move encoding: selects moves (evidence: `src/minichess/agents/minimax.py`)
- Random agent → Board and rules: gets legal moves (evidence: `src/minichess/agents/random_agent.py`)
- Random agent → Move encoding: returns move (evidence: `src/minichess/agents/random_agent.py`)
- Agent registry → Minimax agent: creates agent (evidence: `src/minichess/agents/registry.py`)
- Agent registry → Random agent: creates agent (evidence: `src/minichess/agents/registry.py`)
- Agent registry → AlphaZero agent: creates agent (evidence: `src/minichess/agents/registry.py`)
- Match arena → Agent registry: resolves agent specs (evidence: `src/minichess/arena.py`)
- Match arena → Board and rules: plays game (evidence: `src/minichess/arena.py`)
- Match arena → Agent protocol: invokes agents (evidence: `src/minichess/arena.py`)
- RL environment → Board and rules: steps game state (evidence: `src/minichess/env.py`)
- RL environment → Move encoding: maps actions (evidence: `src/minichess/env.py`)
- Policy value network → RL environment: uses observation shape (evidence: `src/minichess/rl/network.py`)
- Policy value network → Move encoding: uses action count (evidence: `src/minichess/rl/network.py`)
- Batched MCTS → Board and rules: searches positions (evidence: `src/minichess/rl/mcts.py`)
- Self-play generation → Batched MCTS: runs search (evidence: `src/minichess/rl/selfplay.py`)
- Self-play generation → Policy value network: evaluates leaves (evidence: `src/minichess/rl/selfplay.py`)
- Self-play generation → Board and rules: plays games (evidence: `src/minichess/rl/selfplay.py`)
- Replay buffer → Board symmetry: augments samples (evidence: `src/minichess/rl/replay.py`)
- Training orchestration → Self-play generation: generates games (evidence: `src/minichess/rl/train.py`)
- Training orchestration → Replay buffer: stores samples (evidence: `src/minichess/rl/train.py`)
- Training orchestration → Policy value network: trains network (evidence: `src/minichess/rl/train.py`)
- Training orchestration → Match arena: evaluates agents (evidence: `src/minichess/rl/train.py`)
- AlphaZero agent → Batched MCTS: searches moves (evidence: `src/minichess/rl/agent.py`)
- AlphaZero agent → Policy value network: loads checkpoint (evidence: `src/minichess/rl/agent.py`)
- Browser player → WebSocket game server: sends game intents (evidence: `src/minichess/web/server.py`)
- WebSocket game server → Browser board: serves board assets (evidence: `src/minichess/web/server.py`)
- WebSocket game server → Board and rules: owns game state (evidence: `src/minichess/web/server.py`)
- WebSocket game server → Agent registry: resolves opponents (evidence: `src/minichess/web/server.py`)
- WebSocket game server → AlphaZero agent: discovers checkpoints (evidence: `src/minichess/web/server.py`)
