# pktlmezun/chess-engine architecture

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

- Interactive diagram: https://gitdiagram.com/pktlmezun/chess-engine
- Repository: https://github.com/pktlmezun/chess-engine

## Overview

This is a C++17 chess engine exposed through UCI. A GUI sends position and search commands; the engine builds or updates a board, searches for a move, and returns UCI output. The core includes move generation, bitboard attacks, position evaluation, and a transposition table. The README documents the search and evaluation features; source-level links are limited to the excerpts and SOURCE INDEX references provided.

Main entry points: [`src/board.cpp`](https://github.com/pktlmezun/chess-engine/blob/main/src/board.cpp) (Board state), [`src/uci.cpp`](https://github.com/pktlmezun/chess-engine/blob/main/src/uci.cpp) (UCI handler), [`src/search.cpp`](https://github.com/pktlmezun/chess-engine/blob/main/src/search.cpp) (Iterative search), [`src/movegen.cpp`](https://github.com/pktlmezun/chess-engine/blob/main/src/movegen.cpp) (Move generation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["UCI interface"]
  node_main["Engine entry<br/>[main.cpp]"]
  node_uci["UCI handler<br/>[uci.cpp]"]
  node_position["Position setup<br/>[uci.cpp]"]
end

subgraph group_search["Search"]
  node_search["Iterative search<br/>[search.cpp]"]
  node_tt["Transposition table<br/>[search.cpp]"]
end

subgraph group_chess["Chess core"]
  node_movegen["Move generation<br/>[movegen.cpp]"]
  node_board["Board state<br/>[board.cpp]"]
  node_bitboards["Attack tables<br/>[bitboard.cpp]"]
  node_moves["Move encoding<br/>[move.h]"]
  node_types["Chess types<br/>[types.h]"]
end

subgraph group_evaluation["Evaluation"]
  node_evaluation["Position evaluation<br/>[eval.cpp]"]
end

node_gui(("UCI GUI"))

node_gui -->|"sends commands"| node_uci
node_main -->|"starts loop"| node_uci
node_uci -->|"handles position"| node_position
node_position -->|"sets and updates"| node_board
node_position -->|"parses moves"| node_movegen
node_uci -->|"initializes tables"| node_bitboards
node_uci -->|"starts or stops"| node_search
node_search -->|"generates moves"| node_movegen
node_search -->|"evaluates positions"| node_evaluation
node_search -->|"makes and unmakes"| node_board
node_search -.->|"probes and stores"| node_tt
node_movegen -->|"reads positions"| node_board
node_movegen -->|"uses attack tables"| node_bitboards
node_board -->|"queries attacks"| node_bitboards
node_board -->|"applies moves"| node_moves
node_board -->|"uses chess types"| node_types
node_moves -->|"uses chess types"| node_types
node_evaluation -->|"evaluates position"| node_board
node_uci -->|"returns UCI output"| node_gui

click node_main "https://github.com/pktlmezun/chess-engine/blob/main/src/main.cpp"
click node_uci "https://github.com/pktlmezun/chess-engine/blob/main/src/uci.cpp"
click node_position "https://github.com/pktlmezun/chess-engine/blob/main/src/uci.cpp"
click node_search "https://github.com/pktlmezun/chess-engine/blob/main/src/search.cpp"
click node_tt "https://github.com/pktlmezun/chess-engine/blob/main/src/search.cpp"
click node_evaluation "https://github.com/pktlmezun/chess-engine/blob/main/src/eval.cpp"
click node_movegen "https://github.com/pktlmezun/chess-engine/blob/main/src/movegen.cpp"
click node_board "https://github.com/pktlmezun/chess-engine/blob/main/src/board.cpp"
click node_bitboards "https://github.com/pktlmezun/chess-engine/blob/main/src/bitboard.cpp"
click node_moves "https://github.com/pktlmezun/chess-engine/blob/main/src/move.h"
click node_types "https://github.com/pktlmezun/chess-engine/blob/main/src/types.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_position,node_gui toneBlue
class node_search,node_tt toneAmber
class node_movegen,node_board,node_bitboards,node_moves,node_types toneMint
class node_evaluation toneRose
```

## Components

### UCI interface

- [Engine entry](https://github.com/pktlmezun/chess-engine/blob/main/src/main.cpp): `src/main.cpp`
- [UCI handler](https://github.com/pktlmezun/chess-engine/blob/main/src/uci.cpp): `src/uci.cpp`
- [Position setup](https://github.com/pktlmezun/chess-engine/blob/main/src/uci.cpp): `src/uci.cpp`

### Search

- [Iterative search](https://github.com/pktlmezun/chess-engine/blob/main/src/search.cpp): `src/search.cpp`
- [Transposition table](https://github.com/pktlmezun/chess-engine/blob/main/src/search.cpp): `src/search.cpp`

### Chess core

- [Move generation](https://github.com/pktlmezun/chess-engine/blob/main/src/movegen.cpp): `src/movegen.cpp`
- [Board state](https://github.com/pktlmezun/chess-engine/blob/main/src/board.cpp): `src/board.cpp`
- [Attack tables](https://github.com/pktlmezun/chess-engine/blob/main/src/bitboard.cpp): `src/bitboard.cpp`
- [Move encoding](https://github.com/pktlmezun/chess-engine/blob/main/src/move.h): `src/move.h`
- [Chess types](https://github.com/pktlmezun/chess-engine/blob/main/src/types.h): `src/types.h`

### Evaluation

- [Position evaluation](https://github.com/pktlmezun/chess-engine/blob/main/src/eval.cpp): `src/eval.cpp`

### Other components

- **UCI GUI**

## Connections

- UCI GUI → UCI handler: sends commands (evidence: `README.md`)
- Engine entry → UCI handler: starts loop (evidence: `src/main.cpp`)
- UCI handler → Position setup: handles position (evidence: `src/uci.cpp`)
- Position setup → Board state: sets and updates (evidence: `src/uci.cpp`)
- Position setup → Move generation: parses moves (evidence: `src/uci.cpp`)
- UCI handler → Attack tables: initializes tables (evidence: `src/uci.cpp`)
- UCI handler → Iterative search: starts or stops (evidence: `src/uci.cpp`)
- Iterative search → Move generation: generates moves (evidence: `src/search.cpp`)
- Iterative search → Position evaluation: evaluates positions (evidence: `src/search.cpp`)
- Iterative search → Board state: makes and unmakes (evidence: `src/search.cpp`)
- Iterative search → Transposition table: probes and stores (evidence: `README.md`)
- Move generation → Board state: reads positions
- Move generation → Attack tables: uses attack tables (evidence: `src/movegen.cpp`)
- Board state → Attack tables: queries attacks (evidence: `README.md`)
- Board state → Move encoding: applies moves
- Board state → Chess types: uses chess types
- Move encoding → Chess types: uses chess types (evidence: `src/move.h`)
- Position evaluation → Board state: evaluates position
- UCI handler → UCI GUI: returns UCI output (evidence: `README.md`)
