# harborg1/chesscnn architecture

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

- Interactive diagram: https://gitdiagram.com/harborg1/chesscnn
- Repository: https://github.com/harborg1/chesscnn

## Overview

This project recognizes a chessboard image as a position, converts its square-wise CNN predictions into FEN, then asks the bundled Stockfish engine for a best move. The Python source excerpt shows image preprocessing, dataset construction, training, and model-weight saving; the README documents the image-to-FEN-to-engine workflow. Stockfish’s UCI entry and engine search are represented using the available source and file tree. The runner’s implementation was not sampled, so its exact process and data-transfer details are uncertain.

Main entry points: [`stockfish-windows-x86-64-avx2/stockfish/src/search.cpp`](https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/search.cpp) (Move search), [`app.py`](https://github.com/harborg1/chesscnn/blob/main/app.py) (Chess CNN), [`stockfish-windows-x86-64-avx2/stockfish/src/uci.cpp`](https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/uci.cpp) (UCI interface), [`stockfish-windows-x86-64-avx2/stockfish/src/engine.cpp`](https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/engine.cpp) (Engine orchestration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_vision["Position recognition"]
  node_preprocess["Image preprocessing<br/>[app.py]"]
  node_dataset["Training dataset<br/>[app.py]"]
  node_cnn["Chess CNN<br/>[app.py]"]
  node_weights["Model weights<br/>[app.py]"]
  node_fen["FEN conversion<br/>[app.py]"]
end

subgraph group_integration["Engine integration"]
  node_runner["Position runner<br/>[run_stockfish.py]"]
end

subgraph group_engine["Stockfish engine"]
  node_stockfish["Stockfish process<br/>[main.cpp]"]
  node_uci["UCI interface<br/>[uci.cpp]"]
  node_enginecore["Engine orchestration<br/>[engine.cpp]"]
end

subgraph group_search["Search and evaluation"]
  node_position["Board position<br/>[position.cpp]"]
  node_search["Move search<br/>[search.cpp]"]
  node_movegen["Move generation<br/>[movegen.cpp]"]
  node_nnue["NNUE evaluation<br/>[network.cpp]"]
  node_tablebases["Syzygy tables<br/>[tbprobe.cpp]"]
end

node_user(("Chess position image"))
node_result(("Suggested move"))

node_user -->|"provides image"| node_preprocess
node_preprocess -->|"prepares squares"| node_cnn
node_dataset -->|"loads images"| node_preprocess
node_dataset -->|"trains model"| node_cnn
node_cnn -->|"saves weights"| node_weights
node_cnn -->|"predicts squares"| node_fen
node_fen -->|"supplies FEN"| node_runner
node_weights -->|"loads model"| node_runner
node_runner -->|"starts engine"| node_stockfish
node_stockfish -->|"enters UCI loop"| node_uci
node_uci -->|"dispatches commands"| node_enginecore
node_enginecore -->|"sets position"| node_position
node_enginecore -->|"starts search"| node_search
node_search -->|"generates moves"| node_movegen
node_search -->|"evaluates positions"| node_nnue
node_search -.->|"probes endings"| node_tablebases
node_uci -->|"reports best move"| node_result

click node_preprocess "https://github.com/harborg1/chesscnn/blob/main/app.py"
click node_dataset "https://github.com/harborg1/chesscnn/blob/main/app.py"
click node_cnn "https://github.com/harborg1/chesscnn/blob/main/app.py"
click node_weights "https://github.com/harborg1/chesscnn/blob/main/app.py"
click node_fen "https://github.com/harborg1/chesscnn/blob/main/app.py"
click node_runner "https://github.com/harborg1/chesscnn/blob/main/run_stockfish.py"
click node_stockfish "https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/main.cpp"
click node_uci "https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/uci.cpp"
click node_enginecore "https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/engine.cpp"
click node_position "https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/position.cpp"
click node_search "https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/search.cpp"
click node_movegen "https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/movegen.cpp"
click node_nnue "https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/nnue/network.cpp"
click node_tablebases "https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/syzygy/tbprobe.cpp"

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_preprocess,node_dataset,node_cnn,node_weights,node_fen toneBlue
class node_runner toneAmber
class node_stockfish,node_uci,node_enginecore toneMint
class node_position,node_search,node_movegen,node_nnue,node_tablebases toneRose
class node_user,node_result toneIndigo
```

## Components

### Position recognition

- [Image preprocessing](https://github.com/harborg1/chesscnn/blob/main/app.py): `app.py`
- [Training dataset](https://github.com/harborg1/chesscnn/blob/main/app.py): `app.py`
- [Chess CNN](https://github.com/harborg1/chesscnn/blob/main/app.py): `app.py`
- [Model weights](https://github.com/harborg1/chesscnn/blob/main/app.py): `app.py`
- [FEN conversion](https://github.com/harborg1/chesscnn/blob/main/app.py): `app.py`

### Engine integration

- [Position runner](https://github.com/harborg1/chesscnn/blob/main/run_stockfish.py): `run_stockfish.py`

### Stockfish engine

- [Stockfish process](https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/main.cpp): `stockfish-windows-x86-64-avx2/stockfish/src/main.cpp`
- [UCI interface](https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/uci.cpp): `stockfish-windows-x86-64-avx2/stockfish/src/uci.cpp`
- [Engine orchestration](https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/engine.cpp): `stockfish-windows-x86-64-avx2/stockfish/src/engine.cpp`

### Search and evaluation

- [Board position](https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/position.cpp): `stockfish-windows-x86-64-avx2/stockfish/src/position.cpp`
- [Move search](https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/search.cpp): `stockfish-windows-x86-64-avx2/stockfish/src/search.cpp`
- [Move generation](https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/movegen.cpp): `stockfish-windows-x86-64-avx2/stockfish/src/movegen.cpp`
- [NNUE evaluation](https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/nnue/network.cpp): `stockfish-windows-x86-64-avx2/stockfish/src/nnue/network.cpp`
- [Syzygy tables](https://github.com/harborg1/chesscnn/blob/main/stockfish-windows-x86-64-avx2/stockfish/src/syzygy/tbprobe.cpp): `stockfish-windows-x86-64-avx2/stockfish/src/syzygy/tbprobe.cpp`

### Other components

- **Chess position image**
- **Suggested move**

## Connections

- Chess position image → Image preprocessing: provides image
- Image preprocessing → Chess CNN: prepares squares
- Training dataset → Image preprocessing: loads images
- Training dataset → Chess CNN: trains model
- Chess CNN → Model weights: saves weights
- Chess CNN → FEN conversion: predicts squares
- FEN conversion → Position runner: supplies FEN
- Model weights → Position runner: loads model
- Position runner → Stockfish process: starts engine
- Stockfish process → UCI interface: enters UCI loop
- UCI interface → Engine orchestration: dispatches commands
- Engine orchestration → Board position: sets position
- Engine orchestration → Move search: starts search
- Move search → Move generation: generates moves
- Move search → NNUE evaluation: evaluates positions
- Move search → Syzygy tables: probes endings
- UCI interface → Suggested move: reports best move
