# zonda-tsai/chess architecture

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

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

## Overview

This is a two-player terminal chess game. Players enter source and destination squares or game commands; the game loop obtains input, requests promotion when needed, applies and validates moves, updates history and reports terminal outcomes. The renderer handles board display and terminal input mode, while chess_tool.c provides board rules and move history. README-listed capabilities are retained; AI.h is referenced by game.c but absent from the supplied tree, and chess_tool.c is only partially sampled, so uncertain internal wiring is omitted.

Main entry points: [`game.c`](https://github.com/zonda-tsai/chess/blob/main/game.c) (Game loop), [`painter.c`](https://github.com/zonda-tsai/chess/blob/main/painter.c) (Board and status rendering), [`chess_tool.c`](https://github.com/zonda-tsai/chess/blob/main/chess_tool.c) (Move validation and execution), [`chess_tool.h`](https://github.com/zonda-tsai/chess/blob/main/chess_tool.h) (Board state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Game control"]
  node_loop["Game loop<br/>[game.c]"]
  node_input["Move and command input<br/>[game.c]"]
  node_promotion["Promotion choice<br/>[painter.c]"]
end

subgraph group_rules["Chess rules"]
  node_board["Board state<br/>[chess_tool.h]"]
  node_moves["Move validation and execution<br/>[chess_tool.c]"]
  node_outcomes["Checkmate and draw rules<br/>[chess_tool.c]"]
  node_history["Move history and undo/redo<br/>[chess_tool.c]"]
end

subgraph group_terminal["Terminal interface"]
  node_renderer["Board and status rendering<br/>[painter.c]"]
  node_terminal_mode["Terminal input mode<br/>[painter.c]"]
  node_customization["Unicode and ANSI styling<br/>[customise.h]"]
end

node_player(("Player"))
node_terminal_io(("Terminal"))

node_player -->|"enters moves"| node_input
node_loop -->|"requests input"| node_input
node_input -->|"returns commands"| node_loop
node_loop -->|"requests choice"| node_promotion
node_loop -->|"applies move"| node_moves
node_moves -->|"updates state"| node_board
node_moves -->|"records move"| node_history
node_loop -->|"undoes or redoes"| node_history
node_loop -->|"checks result"| node_outcomes
node_loop -->|"draws game"| node_renderer
node_renderer -->|"reads position"| node_board
node_renderer -->|"reads moves"| node_history
node_input -->|"displays prompts"| node_renderer
node_promotion -->|"reads choice"| node_terminal_io
node_terminal_mode -->|"configures input"| node_terminal_io
node_input -->|"reads keys"| node_terminal_io
node_renderer -->|"writes display"| node_terminal_io
node_renderer -->|"uses symbols"| node_customization
node_loop -->|"enables mode"| node_terminal_mode

click node_loop "https://github.com/zonda-tsai/chess/blob/main/game.c"
click node_input "https://github.com/zonda-tsai/chess/blob/main/game.c"
click node_promotion "https://github.com/zonda-tsai/chess/blob/main/painter.c"
click node_board "https://github.com/zonda-tsai/chess/blob/main/chess_tool.h"
click node_moves "https://github.com/zonda-tsai/chess/blob/main/chess_tool.c"
click node_outcomes "https://github.com/zonda-tsai/chess/blob/main/chess_tool.c"
click node_history "https://github.com/zonda-tsai/chess/blob/main/chess_tool.c"
click node_renderer "https://github.com/zonda-tsai/chess/blob/main/painter.c"
click node_terminal_mode "https://github.com/zonda-tsai/chess/blob/main/painter.c"
click node_customization "https://github.com/zonda-tsai/chess/blob/main/customise.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_loop,node_input,node_promotion toneBlue
class node_board,node_moves,node_outcomes,node_history toneAmber
class node_renderer,node_terminal_mode,node_customization toneMint
class node_player,node_terminal_io toneIndigo
```

## Components

### Game control

- [Game loop](https://github.com/zonda-tsai/chess/blob/main/game.c): `game.c`
- [Move and command input](https://github.com/zonda-tsai/chess/blob/main/game.c): `game.c`
- [Promotion choice](https://github.com/zonda-tsai/chess/blob/main/painter.c): `painter.c`

### Chess rules

- [Board state](https://github.com/zonda-tsai/chess/blob/main/chess_tool.h): `chess_tool.h`
- [Move validation and execution](https://github.com/zonda-tsai/chess/blob/main/chess_tool.c): `chess_tool.c`
- [Checkmate and draw rules](https://github.com/zonda-tsai/chess/blob/main/chess_tool.c): `chess_tool.c`
- [Move history and undo/redo](https://github.com/zonda-tsai/chess/blob/main/chess_tool.c): `chess_tool.c`

### Terminal interface

- [Board and status rendering](https://github.com/zonda-tsai/chess/blob/main/painter.c): `painter.c`
- [Terminal input mode](https://github.com/zonda-tsai/chess/blob/main/painter.c): `painter.c`
- [Unicode and ANSI styling](https://github.com/zonda-tsai/chess/blob/main/customise.h): `customise.h`

### Other components

- **Player**
- **Terminal**

## Connections

- Player → Move and command input: enters moves
- Game loop → Move and command input: requests input
- Move and command input → Game loop: returns commands
- Game loop → Promotion choice: requests choice
- Game loop → Move validation and execution: applies move
- Move validation and execution → Board state: updates state
- Move validation and execution → Move history and undo/redo: records move
- Game loop → Move history and undo/redo: undoes or redoes
- Game loop → Checkmate and draw rules: checks result
- Game loop → Board and status rendering: draws game
- Board and status rendering → Board state: reads position
- Board and status rendering → Move history and undo/redo: reads moves
- Move and command input → Board and status rendering: displays prompts
- Promotion choice → Terminal: reads choice
- Terminal input mode → Terminal: configures input
- Move and command input → Terminal: reads keys
- Board and status rendering → Terminal: writes display
- Board and status rendering → Unicode and ANSI styling: uses symbols
- Game loop → Terminal input mode: enables mode
