# callmepeterd/chess-ia architecture

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

- Interactive diagram: https://gitdiagram.com/callmepeterd/chess-ia
- Repository: https://github.com/callmepeterd/chess-ia

## Overview

chess-ia is a chess-playing AI exposed as a polling worker: it fetches a FEN job, parses the position, searches for a legal move, and submits the UCI move and evaluation. The engine also supports a standalone FEN-to-move harness, perft validation, and an optional PolyGlot opening book; the README documents a mock backend for local play. The rules package is represented as one engine subsystem rather than a file-by-file map. Worker-client internals and mock handlers were not excerpted, so their documented relationships are shown with README evidence.

Main entry points: [`search/search.go`](https://github.com/callmepeterd/chess-ia/blob/main/search/search.go) (Minimax search), [`harness/main.go`](https://github.com/callmepeterd/chess-ia/blob/main/harness/main.go) (FEN harness), [`cmd/worker/main.go`](https://github.com/callmepeterd/chess-ia/blob/main/cmd/worker/main.go) (Worker CLI), [`worker/worker.go`](https://github.com/callmepeterd/chess-ia/blob/main/worker/worker.go) (Polling client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interfaces["Interfaces"]
  node_workercli["Worker CLI<br/>[main.go]"]
  node_harness["FEN harness<br/>[main.go]"]
  node_mockcli["Mock server CLI<br/>[main.go]"]
end

subgraph group_engine["Chess engine"]
  node_rules["Rules engine"]
  node_evaluation["Position evaluation<br/>[eval.go]"]
  node_search["Minimax search<br/>[search.go]"]
  node_transposition["Transposition table<br/>[tt.go]"]
end

subgraph group_openings["Opening book"]
  node_polyglot["PolyGlot book"]
end

subgraph group_workerflow["Worker flow"]
  node_worker["Polling client<br/>[worker.go]"]
  node_solver["Job solver<br/>[solver.go]"]
end

subgraph group_mockflow["Mock backend"]
  node_mock["Mock endpoints<br/>[mock.go]"]
end

node_operator(("Operator"))
node_backend["Backend API"]

node_operator -->|"starts worker"| node_workercli
node_workercli -->|"loads optional book"| node_polyglot
node_workercli -->|"sets book"| node_search
node_workercli -->|"starts polling"| node_worker
node_worker -->|"polls and submits"| node_backend
node_worker -->|"solves jobs"| node_solver
node_solver -->|"parses FEN"| node_rules
node_solver -->|"runs search"| node_search
node_search -->|"generates and applies moves"| node_rules
node_search -->|"evaluates positions"| node_evaluation
node_search -->|"probes and stores"| node_transposition
node_search -->|"checks opening book"| node_polyglot
node_operator -->|"runs analysis"| node_harness
node_harness -->|"parses FEN and perft"| node_rules
node_harness -->|"evaluates position"| node_evaluation
node_harness -->|"requests move"| node_search
node_harness -->|"loads optional book"| node_polyglot
node_operator -->|"starts mock"| node_mockcli
node_mockcli -->|"serves endpoints"| node_mock
node_mockcli -->|"builds selfplay positions"| node_rules
node_mock -->|"simulates backend contract"| node_worker

click node_workercli "https://github.com/callmepeterd/chess-ia/blob/main/cmd/worker/main.go"
click node_harness "https://github.com/callmepeterd/chess-ia/blob/main/harness/main.go"
click node_mockcli "https://github.com/callmepeterd/chess-ia/blob/main/cmd/mockbackend/main.go"
click node_rules "https://github.com/callmepeterd/chess-ia/tree/main/rules"
click node_evaluation "https://github.com/callmepeterd/chess-ia/blob/main/eval/eval.go"
click node_search "https://github.com/callmepeterd/chess-ia/blob/main/search/search.go"
click node_transposition "https://github.com/callmepeterd/chess-ia/blob/main/search/tt.go"
click node_polyglot "https://github.com/callmepeterd/chess-ia/tree/main/book"
click node_worker "https://github.com/callmepeterd/chess-ia/blob/main/worker/worker.go"
click node_solver "https://github.com/callmepeterd/chess-ia/blob/main/worker/solver.go"
click node_mock "https://github.com/callmepeterd/chess-ia/blob/main/mock/mock.go"

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_workercli,node_harness,node_mockcli toneBlue
class node_rules,node_evaluation,node_search,node_transposition toneAmber
class node_polyglot,node_backend toneMint
class node_worker,node_solver toneRose
class node_mock,node_operator toneIndigo
```

## Components

### Interfaces

- [Worker CLI](https://github.com/callmepeterd/chess-ia/blob/main/cmd/worker/main.go): `cmd/worker/main.go`
- [FEN harness](https://github.com/callmepeterd/chess-ia/blob/main/harness/main.go): `harness/main.go`
- [Mock server CLI](https://github.com/callmepeterd/chess-ia/blob/main/cmd/mockbackend/main.go): `cmd/mockbackend/main.go`

### Chess engine

- [Rules engine](https://github.com/callmepeterd/chess-ia/tree/main/rules): `rules`
- [Position evaluation](https://github.com/callmepeterd/chess-ia/blob/main/eval/eval.go): `eval/eval.go`
- [Minimax search](https://github.com/callmepeterd/chess-ia/blob/main/search/search.go): `search/search.go`
- [Transposition table](https://github.com/callmepeterd/chess-ia/blob/main/search/tt.go): `search/tt.go`

### Opening book

- [PolyGlot book](https://github.com/callmepeterd/chess-ia/tree/main/book): `book`

### Worker flow

- [Polling client](https://github.com/callmepeterd/chess-ia/blob/main/worker/worker.go): `worker/worker.go`
- [Job solver](https://github.com/callmepeterd/chess-ia/blob/main/worker/solver.go): `worker/solver.go`

### Mock backend

- [Mock endpoints](https://github.com/callmepeterd/chess-ia/blob/main/mock/mock.go): `mock/mock.go`

### Other components

- **Operator**
- **Backend API**

## Connections

- Operator → Worker CLI: starts worker (evidence: `README.md`)
- Worker CLI → PolyGlot book: loads optional book (evidence: `cmd/worker/main.go`)
- Worker CLI → Minimax search: sets book (evidence: `cmd/worker/main.go`)
- Worker CLI → Polling client: starts polling (evidence: `cmd/worker/main.go`)
- Polling client → Backend API: polls and submits (evidence: `README.md`)
- Polling client → Job solver: solves jobs (evidence: `README.md`)
- Job solver → Rules engine: parses FEN (evidence: `worker/solver.go`)
- Job solver → Minimax search: runs search (evidence: `worker/solver.go`)
- Minimax search → Rules engine: generates and applies moves (evidence: `search/search.go`)
- Minimax search → Position evaluation: evaluates positions (evidence: `search/search.go`)
- Minimax search → Transposition table: probes and stores (evidence: `search/search.go`)
- Minimax search → PolyGlot book: checks opening book (evidence: `search/search.go`)
- Operator → FEN harness: runs analysis (evidence: `README.md`)
- FEN harness → Rules engine: parses FEN and perft (evidence: `harness/main.go`)
- FEN harness → Position evaluation: evaluates position (evidence: `harness/main.go`)
- FEN harness → Minimax search: requests move (evidence: `harness/main.go`)
- FEN harness → PolyGlot book: loads optional book (evidence: `harness/main.go`)
- Operator → Mock server CLI: starts mock (evidence: `README.md`)
- Mock server CLI → Mock endpoints: serves endpoints (evidence: `cmd/mockbackend/main.go`)
- Mock server CLI → Rules engine: builds selfplay positions (evidence: `cmd/mockbackend/main.go`)
- Mock endpoints → Polling client: simulates backend contract (evidence: `README.md`)
