# 0shrihari0/checkers architecture

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

- Interactive diagram: https://gitdiagram.com/0shrihari0/checkers
- Repository: https://github.com/0shrihari0/checkers

## Overview

Checkers in C combines local terminal play, a TCP multiplayer service and client, and a browser game with local, AI, and WebSocket modes. The principal flow is player input through a game loop, rule and move handling, and board updates; online play routes clients through a protocol to lobby and room handling. Server rooms also support reconnection, spectators, AI games, and history, while SQLite-backed stats and matchmaking are documented capabilities. Some web and server internals are unsampled, so their links rely on README statements or are omitted.

Main entry points: [`server/room.c`](https://github.com/0shrihari0/checkers/blob/main/server/room.c) (Game rooms), [`src/main.c`](https://github.com/0shrihari0/checkers/blob/main/src/main.c) (Local game loop), [`web/ui.js`](https://github.com/0shrihari0/checkers/blob/main/web/ui.js) (Browser interface), [`server/server.c`](https://github.com/0shrihari0/checkers/blob/main/server/server.c) (Lobby and matchmaking)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_local["Terminal Game"]
  node_local_loop["Local game loop<br/>[main.c]"]
  node_terminal_ui["Terminal UI<br/>[terminal.c]"]
end

subgraph group_rules["Game Logic"]
  node_board["Board state<br/>[board.c]"]
  node_moves["Move handling<br/>[moves.c]"]
  node_rules_engine["Rules engine<br/>[rules.c]"]
end

subgraph group_network["TCP Multiplayer"]
  node_terminal_client["Terminal client<br/>[client.c]"]
  node_protocol["Packet protocol<br/>[protocol.c]"]
end

subgraph group_server["Server Services"]
  node_lobby["Lobby and matchmaking<br/>[server.c]"]
  node_game_rooms["Game rooms<br/>[room.c]"]
  node_ai_engine["Server AI<br/>[ai.c]"]
  node_player_database[("Player database<br/>[db.c]")]
  node_game_history[("Game history<br/>[history.c]")]
end

subgraph group_browser["Browser Game"]
  node_web_interface["Browser interface<br/>[ui.js]"]
  node_web_game["Web game engine<br/>[game.js]"]
  node_web_ai["Browser AI<br/>[ai.js]"]
  node_web_multiplayer["WebSocket client<br/>[multiplayer.js]"]
  node_web_server["WebSocket server<br/>[server.js]"]
end

node_terminal_player(("Terminal player"))
node_tcp_player(("TCP player"))
node_browser_player(("Browser player"))

node_terminal_player -->|"plays through"| node_local_loop
node_local_loop -->|"requests input and display"| node_terminal_ui
node_local_loop -->|"manages state"| node_board
node_local_loop -->|"executes moves"| node_moves
node_local_loop -->|"checks rules"| node_rules_engine
node_moves -->|"reads and updates"| node_board
node_rules_engine -->|"uses player state"| node_board
node_tcp_player -->|"plays through"| node_terminal_client
node_terminal_client -->|"packs and unpacks"| node_protocol
node_lobby -->|"handles packets"| node_protocol
node_lobby -->|"creates and reconnects"| node_game_rooms
node_lobby -->|"queries profiles and rankings"| node_player_database
node_game_rooms -->|"sends game packets"| node_protocol
node_game_rooms -->|"executes moves"| node_moves
node_game_rooms -->|"checks game state"| node_rules_engine
node_browser_player -->|"plays through"| node_web_interface
node_web_interface -->|"supports local play"| node_web_game
node_web_interface -->|"offers AI mode"| node_web_ai
node_web_interface -->|"offers online mode"| node_web_multiplayer
node_web_multiplayer -->|"connects by WebSocket"| node_web_server
node_game_rooms -->|"supports AI games"| node_ai_engine
node_game_rooms -.->|"logs game history"| node_game_history
node_player_database -.->|"persists game records"| node_game_history

click node_local_loop "https://github.com/0shrihari0/checkers/blob/main/src/main.c"
click node_terminal_ui "https://github.com/0shrihari0/checkers/blob/main/src/ui/terminal.c"
click node_board "https://github.com/0shrihari0/checkers/blob/main/src/game/board.c"
click node_moves "https://github.com/0shrihari0/checkers/blob/main/src/game/moves.c"
click node_rules_engine "https://github.com/0shrihari0/checkers/blob/main/src/game/rules.c"
click node_terminal_client "https://github.com/0shrihari0/checkers/blob/main/client/client.c"
click node_protocol "https://github.com/0shrihari0/checkers/blob/main/shared/protocol.c"
click node_lobby "https://github.com/0shrihari0/checkers/blob/main/server/server.c"
click node_game_rooms "https://github.com/0shrihari0/checkers/blob/main/server/room.c"
click node_ai_engine "https://github.com/0shrihari0/checkers/blob/main/server/ai.c"
click node_player_database "https://github.com/0shrihari0/checkers/blob/main/server/db.c"
click node_game_history "https://github.com/0shrihari0/checkers/blob/main/server/history.c"
click node_web_interface "https://github.com/0shrihari0/checkers/blob/main/web/ui.js"
click node_web_game "https://github.com/0shrihari0/checkers/blob/main/web/game.js"
click node_web_ai "https://github.com/0shrihari0/checkers/blob/main/web/ai.js"
click node_web_multiplayer "https://github.com/0shrihari0/checkers/blob/main/web/multiplayer.js"
click node_web_server "https://github.com/0shrihari0/checkers/blob/main/web/server.js"

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_local_loop,node_terminal_ui,node_browser_player toneBlue
class node_board,node_moves,node_rules_engine toneAmber
class node_terminal_client,node_protocol toneMint
class node_lobby,node_game_rooms,node_ai_engine,node_player_database,node_game_history toneRose
class node_web_interface,node_web_game,node_web_ai,node_web_multiplayer,node_web_server,node_terminal_player,node_tcp_player toneIndigo
```

## Components

### Terminal Game

- [Local game loop](https://github.com/0shrihari0/checkers/blob/main/src/main.c): `src/main.c`
- [Terminal UI](https://github.com/0shrihari0/checkers/blob/main/src/ui/terminal.c): `src/ui/terminal.c`

### Game Logic

- [Board state](https://github.com/0shrihari0/checkers/blob/main/src/game/board.c): `src/game/board.c`
- [Move handling](https://github.com/0shrihari0/checkers/blob/main/src/game/moves.c): `src/game/moves.c`
- [Rules engine](https://github.com/0shrihari0/checkers/blob/main/src/game/rules.c): `src/game/rules.c`

### TCP Multiplayer

- [Terminal client](https://github.com/0shrihari0/checkers/blob/main/client/client.c): `client/client.c`
- [Packet protocol](https://github.com/0shrihari0/checkers/blob/main/shared/protocol.c): `shared/protocol.c`

### Server Services

- [Lobby and matchmaking](https://github.com/0shrihari0/checkers/blob/main/server/server.c): `server/server.c`
- [Game rooms](https://github.com/0shrihari0/checkers/blob/main/server/room.c): `server/room.c`
- [Server AI](https://github.com/0shrihari0/checkers/blob/main/server/ai.c): `server/ai.c`
- [Player database](https://github.com/0shrihari0/checkers/blob/main/server/db.c): `server/db.c`
- [Game history](https://github.com/0shrihari0/checkers/blob/main/server/history.c): `server/history.c`

### Browser Game

- [Browser interface](https://github.com/0shrihari0/checkers/blob/main/web/ui.js): `web/ui.js`
- [Web game engine](https://github.com/0shrihari0/checkers/blob/main/web/game.js): `web/game.js`
- [Browser AI](https://github.com/0shrihari0/checkers/blob/main/web/ai.js): `web/ai.js`
- [WebSocket client](https://github.com/0shrihari0/checkers/blob/main/web/multiplayer.js): `web/multiplayer.js`
- [WebSocket server](https://github.com/0shrihari0/checkers/blob/main/web/server.js): `web/server.js`

### Other components

- **Terminal player**
- **TCP player**
- **Browser player**

## Connections

- Terminal player → Local game loop: plays through (evidence: `README.md`)
- Local game loop → Terminal UI: requests input and display (evidence: `src/main.c`)
- Local game loop → Board state: manages state (evidence: `src/main.c`)
- Local game loop → Move handling: executes moves (evidence: `src/main.c`)
- Local game loop → Rules engine: checks rules (evidence: `src/main.c`)
- Move handling → Board state: reads and updates (evidence: `src/game/moves.c`)
- Rules engine → Board state: uses player state
- TCP player → Terminal client: plays through (evidence: `README.md`)
- Terminal client → Packet protocol: packs and unpacks (evidence: `client/client.c`)
- Lobby and matchmaking → Packet protocol: handles packets (evidence: `server/server.c`)
- Lobby and matchmaking → Game rooms: creates and reconnects (evidence: `server/server.c`)
- Lobby and matchmaking → Player database: queries profiles and rankings (evidence: `server/server.c`)
- Game rooms → Packet protocol: sends game packets (evidence: `server/room.c`)
- Game rooms → Move handling: executes moves (evidence: `server/room.c`)
- Game rooms → Rules engine: checks game state (evidence: `server/room.c`)
- Browser player → Browser interface: plays through (evidence: `README.md`)
- Browser interface → Web game engine: supports local play (evidence: `README.md`)
- Browser interface → Browser AI: offers AI mode (evidence: `README.md`)
- Browser interface → WebSocket client: offers online mode (evidence: `README.md`)
- WebSocket client → WebSocket server: connects by WebSocket (evidence: `README.md`)
- Game rooms → Server AI: supports AI games
- Game rooms → Game history: logs game history
- Player database → Game history: persists game records
