# official-stockfish/stockfish architecture

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

- Interactive diagram: https://gitdiagram.com/official-stockfish/stockfish
- Repository: https://github.com/official-stockfish/stockfish
- Video tour (about a minute): https://gitdiagram.com/official-stockfish/stockfish/video

## Overview

Stockfish is a UCI chess engine: a client supplies a position and search request, and the engine analyzes it and returns a best move. The graph follows that runtime path and includes chess-position and move-generation logic, search support, NNUE evaluation, and Syzygy tablebase probing. Edges are limited to relationships shown by the README or SOURCE INDEX references; the sampled excerpts do not expose all runtime call sites, so some internal links are omitted.

Main entry points: [`src/search.cpp`](https://github.com/official-stockfish/stockfish/blob/master/src/search.cpp) (Tree search), [`src/position.cpp`](https://github.com/official-stockfish/stockfish/blob/master/src/position.cpp) (Position state), [`src/nnue/network.cpp`](https://github.com/official-stockfish/stockfish/blob/master/src/nnue/network.cpp) (NNUE network), [`src/engine.cpp`](https://github.com/official-stockfish/stockfish/blob/master/src/engine.cpp) (Engine control)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["UCI and engine"]
  node_main["Program entry<br/>[main.cpp]"]
  node_uci["UCI protocol<br/>[uci.cpp]"]
  node_engine["Engine control<br/>[engine.cpp]"]
end

subgraph group_chess["Chess state"]
  node_position["Position state<br/>[position.cpp]"]
  node_bitboard["Bitboard operations<br/>[bitboard.h]"]
  node_attacks["Attack queries<br/>[attacks.h]"]
  node_movegen["Move generation<br/>[movegen.cpp]"]
end

subgraph group_search["Search and support"]
  node_search["Tree search<br/>[search.cpp]"]
  node_movepick["Move ordering<br/>[movepick.cpp]"]
  node_history["Search histories<br/>[history.h]"]
  node_threads["Search threads<br/>[thread.cpp]"]
  node_tt[("Transposition table<br/>[tt.cpp]")]
  node_timeman["Time management<br/>[timeman.cpp]"]
  node_tablebases[("Syzygy probing<br/>[tbprobe.cpp]")]
  node_misc["Shared utilities<br/>[misc.h]"]
  node_memory["Memory support<br/>[memory.h]"]
end

subgraph group_evaluation["Evaluation"]
  node_evaluate["Evaluation interface<br/>[evaluate.cpp]"]
  node_network["NNUE network<br/>[network.cpp]"]
  node_accumulator["NNUE accumulator"]
  node_features["Feature transformer"]
  node_architecture["NNUE architecture"]
  node_feature_sets["Chess feature sets"]
end

node_client(("UCI client"))

node_client -->|"sends commands"| node_uci
node_main -->|"starts protocol"| node_uci
node_uci -->|"dispatches requests"| node_engine
node_engine -->|"sets position"| node_position
node_engine -->|"starts search"| node_threads
node_engine -->|"loads network"| node_network
node_position -->|"uses move generation"| node_movegen
node_position -->|"uses bitboards"| node_bitboard
node_position -->|"uses attack queries"| node_attacks
node_threads -->|"runs search"| node_search
node_search -->|"searches positions"| node_position
node_search -->|"generates moves"| node_movegen
node_search -->|"orders moves"| node_movepick
node_search -->|"updates histories"| node_history
node_search -->|"uses transpositions"| node_tt
node_search -->|"checks time limits"| node_timeman
node_search -->|"evaluates positions"| node_evaluate
node_search -->|"probes endgames"| node_tablebases
node_evaluate -->|"uses NNUE"| node_network
node_network -->|"uses accumulators"| node_accumulator
node_network -->|"propagates network"| node_architecture
node_accumulator -->|"updates features"| node_features
node_architecture -->|"configures inputs"| node_feature_sets
node_features -->|"reads chess state"| node_position
node_search -->|"uses utilities"| node_misc
node_network -->|"uses allocation support"| node_memory

click node_main "https://github.com/official-stockfish/stockfish/blob/master/src/main.cpp"
click node_uci "https://github.com/official-stockfish/stockfish/blob/master/src/uci.cpp"
click node_engine "https://github.com/official-stockfish/stockfish/blob/master/src/engine.cpp"
click node_position "https://github.com/official-stockfish/stockfish/blob/master/src/position.cpp"
click node_bitboard "https://github.com/official-stockfish/stockfish/blob/master/src/bitboard.h"
click node_attacks "https://github.com/official-stockfish/stockfish/blob/master/src/attacks.h"
click node_movegen "https://github.com/official-stockfish/stockfish/blob/master/src/movegen.cpp"
click node_search "https://github.com/official-stockfish/stockfish/blob/master/src/search.cpp"
click node_movepick "https://github.com/official-stockfish/stockfish/blob/master/src/movepick.cpp"
click node_history "https://github.com/official-stockfish/stockfish/blob/master/src/history.h"
click node_threads "https://github.com/official-stockfish/stockfish/blob/master/src/thread.cpp"
click node_tt "https://github.com/official-stockfish/stockfish/blob/master/src/tt.cpp"
click node_timeman "https://github.com/official-stockfish/stockfish/blob/master/src/timeman.cpp"
click node_tablebases "https://github.com/official-stockfish/stockfish/blob/master/src/syzygy/tbprobe.cpp"
click node_evaluate "https://github.com/official-stockfish/stockfish/blob/master/src/evaluate.cpp"
click node_network "https://github.com/official-stockfish/stockfish/blob/master/src/nnue/network.cpp"
click node_accumulator "https://github.com/official-stockfish/stockfish/blob/master/src/nnue/nnue_accumulator.cpp"
click node_features "https://github.com/official-stockfish/stockfish/blob/master/src/nnue/nnue_feature_transformer.h"
click node_architecture "https://github.com/official-stockfish/stockfish/blob/master/src/nnue/nnue_architecture.h"
click node_feature_sets "https://github.com/official-stockfish/stockfish/tree/master/src/nnue/features"
click node_misc "https://github.com/official-stockfish/stockfish/blob/master/src/misc.h"
click node_memory "https://github.com/official-stockfish/stockfish/blob/master/src/memory.h"

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_main,node_uci,node_engine,node_client toneBlue
class node_position,node_bitboard,node_attacks,node_movegen toneAmber
class node_search,node_movepick,node_history,node_threads,node_tt,node_timeman,node_tablebases,node_misc,node_memory toneMint
class node_evaluate,node_network,node_accumulator,node_features,node_architecture,node_feature_sets toneRose
```

## Components

### UCI and engine

- [Program entry](https://github.com/official-stockfish/stockfish/blob/master/src/main.cpp): `src/main.cpp`
- [UCI protocol](https://github.com/official-stockfish/stockfish/blob/master/src/uci.cpp): `src/uci.cpp`
- [Engine control](https://github.com/official-stockfish/stockfish/blob/master/src/engine.cpp): `src/engine.cpp`

### Chess state

- [Position state](https://github.com/official-stockfish/stockfish/blob/master/src/position.cpp): `src/position.cpp`
- [Bitboard operations](https://github.com/official-stockfish/stockfish/blob/master/src/bitboard.h): `src/bitboard.h`
- [Attack queries](https://github.com/official-stockfish/stockfish/blob/master/src/attacks.h): `src/attacks.h`
- [Move generation](https://github.com/official-stockfish/stockfish/blob/master/src/movegen.cpp): `src/movegen.cpp`

### Search and support

- [Tree search](https://github.com/official-stockfish/stockfish/blob/master/src/search.cpp): `src/search.cpp`
- [Move ordering](https://github.com/official-stockfish/stockfish/blob/master/src/movepick.cpp): `src/movepick.cpp`
- [Search histories](https://github.com/official-stockfish/stockfish/blob/master/src/history.h): `src/history.h`
- [Search threads](https://github.com/official-stockfish/stockfish/blob/master/src/thread.cpp): `src/thread.cpp`
- [Transposition table](https://github.com/official-stockfish/stockfish/blob/master/src/tt.cpp): `src/tt.cpp`
- [Time management](https://github.com/official-stockfish/stockfish/blob/master/src/timeman.cpp): `src/timeman.cpp`
- [Syzygy probing](https://github.com/official-stockfish/stockfish/blob/master/src/syzygy/tbprobe.cpp): `src/syzygy/tbprobe.cpp`
- [Shared utilities](https://github.com/official-stockfish/stockfish/blob/master/src/misc.h): `src/misc.h`
- [Memory support](https://github.com/official-stockfish/stockfish/blob/master/src/memory.h): `src/memory.h`

### Evaluation

- [Evaluation interface](https://github.com/official-stockfish/stockfish/blob/master/src/evaluate.cpp): `src/evaluate.cpp`
- [NNUE network](https://github.com/official-stockfish/stockfish/blob/master/src/nnue/network.cpp): `src/nnue/network.cpp`
- [NNUE accumulator](https://github.com/official-stockfish/stockfish/blob/master/src/nnue/nnue_accumulator.cpp): `src/nnue/nnue_accumulator.cpp`
- [Feature transformer](https://github.com/official-stockfish/stockfish/blob/master/src/nnue/nnue_feature_transformer.h): `src/nnue/nnue_feature_transformer.h`
- [NNUE architecture](https://github.com/official-stockfish/stockfish/blob/master/src/nnue/nnue_architecture.h): `src/nnue/nnue_architecture.h`
- [Chess feature sets](https://github.com/official-stockfish/stockfish/tree/master/src/nnue/features): `src/nnue/features`

### Other components

- **UCI client**

## Connections

- UCI client → UCI protocol: sends commands (evidence: `README.md`)
- Program entry → UCI protocol: starts protocol (evidence: `src/main.cpp`)
- UCI protocol → Engine control: dispatches requests
- Engine control → Position state: sets position (evidence: `src/engine.cpp`)
- Engine control → Search threads: starts search (evidence: `src/engine.cpp`)
- Engine control → NNUE network: loads network (evidence: `src/engine.cpp`)
- Position state → Move generation: uses move generation (evidence: `src/position.cpp`)
- Position state → Bitboard operations: uses bitboards (evidence: `src/position.cpp`)
- Position state → Attack queries: uses attack queries
- Search threads → Tree search: runs search (evidence: `src/search.cpp`)
- Tree search → Position state: searches positions (evidence: `src/search.cpp`)
- Tree search → Move generation: generates moves (evidence: `src/search.cpp`)
- Tree search → Move ordering: orders moves (evidence: `src/search.cpp`)
- Tree search → Search histories: updates histories (evidence: `src/search.cpp`)
- Tree search → Transposition table: uses transpositions (evidence: `src/search.cpp`)
- Tree search → Time management: checks time limits (evidence: `src/search.cpp`)
- Tree search → Evaluation interface: evaluates positions (evidence: `src/search.cpp`)
- Tree search → Syzygy probing: probes endgames (evidence: `src/search.cpp`)
- Evaluation interface → NNUE network: uses NNUE (evidence: `src/nnue/network.cpp`)
- NNUE network → NNUE accumulator: uses accumulators
- NNUE network → NNUE architecture: propagates network (evidence: `src/nnue/network.cpp`)
- NNUE accumulator → Feature transformer: updates features (evidence: `src/nnue/nnue_accumulator.cpp`)
- NNUE architecture → Chess feature sets: configures inputs (evidence: `src/nnue/nnue_architecture.h`)
- Feature transformer → Position state: reads chess state (evidence: `src/nnue/nnue_feature_transformer.h`)
- Tree search → Shared utilities: uses utilities (evidence: `src/search.cpp`)
- NNUE network → Memory support: uses allocation support
