# patvakanyan/chess architecture

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

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

## Overview

This is a C++ chess engine with a terminal game loop. A player selects a color, enters moves or requests undo, and sees the updated board and game result. The main domain stages are position parsing, move execution, board and history updates, and end-state checks; piece-specific movement and attack detection provide the rules layer. The graph reflects documented capabilities where source was not sampled, but omits uncertain implementation links.

Main entry points: [`src/terminal.cpp`](https://github.com/patvakanyan/chess/blob/main/src/terminal.cpp) (Terminal loop), [`src/board.cpp`](https://github.com/patvakanyan/chess/blob/main/src/board.cpp) (Board), [`src/game.cpp`](https://github.com/patvakanyan/chess/blob/main/src/game.cpp) (Game controller), [`src/pieces`](https://github.com/patvakanyan/chess/tree/main/src/pieces) (Piece movement rules)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Terminal interface"]
  node_main["Application entry<br/>[main.cpp]"]
  node_terminal["Terminal loop<br/>[terminal.cpp]"]
end

subgraph group_state["Game state"]
  node_game["Game controller<br/>[game.cpp]"]
  node_board["Board<br/>[board.cpp]"]
  node_square["Square<br/>[square.cpp]"]
  node_move["Move execution<br/>[move.cpp]"]
  node_history["Move history<br/>[moveHistory.cpp]"]
end

subgraph group_rules["Chess rules"]
  node_position["Position parsing<br/>[position.cpp]"]
  node_piece["Piece abstraction<br/>[piece.cpp]"]
  node_pieces["Piece movement rules"]
  node_chessutils["Rule checks<br/>[chessUtils.cpp]"]
  node_result["Game result types"]
end

node_player(("Player"))

node_player -->|"enters moves"| node_terminal
node_main -->|"starts loop"| node_terminal
node_terminal -->|"starts and controls"| node_game
node_terminal -->|"parses coordinates"| node_position
node_terminal -->|"checks game end"| node_chessutils
node_terminal -->|"displays outcomes"| node_result
node_game -->|"sets up and reads"| node_board
node_game -->|"executes moves"| node_move
node_game -->|"records and undoes"| node_history
node_move -->|"updates position"| node_board
node_board -->|"stores squares"| node_square
node_pieces -->|"implements types"| node_piece
node_chessutils -->|"checks board state"| node_board
node_pieces -->|"queries legal moves"| node_board
node_history -->|"restores moves"| node_board

click node_main "https://github.com/patvakanyan/chess/blob/main/src/main.cpp"
click node_terminal "https://github.com/patvakanyan/chess/blob/main/src/terminal.cpp"
click node_game "https://github.com/patvakanyan/chess/blob/main/src/game.cpp"
click node_board "https://github.com/patvakanyan/chess/blob/main/src/board.cpp"
click node_square "https://github.com/patvakanyan/chess/blob/main/src/square.cpp"
click node_move "https://github.com/patvakanyan/chess/blob/main/src/move.cpp"
click node_history "https://github.com/patvakanyan/chess/blob/main/src/moveHistory.cpp"
click node_position "https://github.com/patvakanyan/chess/blob/main/src/position.cpp"
click node_piece "https://github.com/patvakanyan/chess/blob/main/src/piece.cpp"
click node_pieces "https://github.com/patvakanyan/chess/tree/main/src/pieces"
click node_chessutils "https://github.com/patvakanyan/chess/blob/main/src/chessUtils.cpp"
click node_result "https://github.com/patvakanyan/chess/blob/main/include/chess/utils/chessGameResult.hpp"

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_terminal toneBlue
class node_game,node_board,node_square,node_move,node_history toneAmber
class node_position,node_piece,node_pieces,node_chessutils,node_result toneMint
class node_player toneIndigo
```

## Components

### Terminal interface

- [Application entry](https://github.com/patvakanyan/chess/blob/main/src/main.cpp): `src/main.cpp`
- [Terminal loop](https://github.com/patvakanyan/chess/blob/main/src/terminal.cpp): `src/terminal.cpp`

### Game state

- [Game controller](https://github.com/patvakanyan/chess/blob/main/src/game.cpp): `src/game.cpp`
- [Board](https://github.com/patvakanyan/chess/blob/main/src/board.cpp): `src/board.cpp`
- [Square](https://github.com/patvakanyan/chess/blob/main/src/square.cpp): `src/square.cpp`
- [Move execution](https://github.com/patvakanyan/chess/blob/main/src/move.cpp): `src/move.cpp`
- [Move history](https://github.com/patvakanyan/chess/blob/main/src/moveHistory.cpp): `src/moveHistory.cpp`

### Chess rules

- [Position parsing](https://github.com/patvakanyan/chess/blob/main/src/position.cpp): `src/position.cpp`
- [Piece abstraction](https://github.com/patvakanyan/chess/blob/main/src/piece.cpp): `src/piece.cpp`
- [Piece movement rules](https://github.com/patvakanyan/chess/tree/main/src/pieces): `src/pieces`
- [Rule checks](https://github.com/patvakanyan/chess/blob/main/src/chessUtils.cpp): `src/chessUtils.cpp`
- [Game result types](https://github.com/patvakanyan/chess/blob/main/include/chess/utils/chessGameResult.hpp): `include/chess/utils/chessGameResult.hpp`

### Other components

- **Player**

## Connections

- Player → Terminal loop: enters moves
- Application entry → Terminal loop: starts loop
- Terminal loop → Game controller: starts and controls
- Terminal loop → Position parsing: parses coordinates
- Terminal loop → Rule checks: checks game end
- Terminal loop → Game result types: displays outcomes
- Game controller → Board: sets up and reads
- Game controller → Move execution: executes moves
- Game controller → Move history: records and undoes
- Move execution → Board: updates position
- Board → Square: stores squares
- Piece movement rules → Piece abstraction: implements types
- Rule checks → Board: checks board state
- Piece movement rules → Board: queries legal moves
- Move history → Board: restores moves
