# rico-knots/p2pchess architecture

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

- Interactive diagram: https://gitdiagram.com/rico-knots/p2pchess
- Repository: https://github.com/rico-knots/p2pchess

## Overview

This repository is a graphical chess application with a separate socket-server prototype and networking client code. The visible main loop initializes a window, creates a new game state, then repeatedly draws it until shutdown. The engine provides board representation and game initialization; UI rendering and asset loading form a separate layer. Networking defines packet formats and serialization, while the server accepts connections and deserializes received packets. UI internals and client protocol usage are only partially evidenced, so their detailed call relationships are omitted.

Main entry points: [`src/main.c`](https://github.com/rico-knots/p2pchess/blob/main/src/main.c) (Game Loop), [`src/ui/asset_manager.c`](https://github.com/rico-knots/p2pchess/blob/main/src/ui/asset_manager.c) (Asset Manager), [`src/networking/server.c`](https://github.com/rico-knots/p2pchess/blob/main/src/networking/server.c) (Socket Server), [`src/ui/window.c`](https://github.com/rico-knots/p2pchess/blob/main/src/ui/window.c) (Window)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application"]
  node_entry["Game Loop<br/>[main.c]"]
end

subgraph group_engine["Chess Engine"]
  node_game["Game State<br/>[chess.c]"]
  node_boards["Bitboards<br/>[bitboard.c]"]
  node_moves["Move Generation<br/>[movegen.c]"]
end

subgraph group_ui["Graphical UI"]
  node_window["Window<br/>[window.c]"]
  node_renderer["Renderer<br/>[renderer.c]"]
  node_assets["Asset Manager<br/>[asset_manager.c]"]
  node_images["Image Decoder<br/>[stb_image.h]"]
  node_glad["OpenGL Loader<br/>[gl.h]"]
  node_gl["OpenGL API<br/>[gl.c]"]
  node_shaders["Quad Shaders<br/>[quad.vert]"]
end

subgraph group_network["Networking"]
  node_client["Network Client<br/>[client.c]"]
  node_protocol["Packet Protocol<br/>[protocol.c]"]
  node_packets["Packet Types<br/>[packets.h]"]
  node_server["Socket Server<br/>[server.c]"]
end

node_player(("Player"))
node_remote(("Remote Peer"))

node_player -->|"plays"| node_entry
node_entry -->|"runs loop"| node_window
node_entry -->|"creates state"| node_game
node_entry -->|"draws state"| node_window
node_assets -->|"decodes images"| node_images
node_assets -->|"uses API"| node_glad
node_server -->|"deserializes packets"| node_protocol
node_client -.->|"communicates"| node_remote
node_server -->|"accepts connections"| node_remote

click node_entry "https://github.com/rico-knots/p2pchess/blob/main/src/main.c"
click node_game "https://github.com/rico-knots/p2pchess/blob/main/src/engine/chess.c"
click node_boards "https://github.com/rico-knots/p2pchess/blob/main/src/engine/bitboard.c"
click node_moves "https://github.com/rico-knots/p2pchess/blob/main/src/engine/movegen.c"
click node_window "https://github.com/rico-knots/p2pchess/blob/main/src/ui/window.c"
click node_renderer "https://github.com/rico-knots/p2pchess/blob/main/src/ui/renderer.c"
click node_assets "https://github.com/rico-knots/p2pchess/blob/main/src/ui/asset_manager.c"
click node_images "https://github.com/rico-knots/p2pchess/blob/main/src/include/stb/stb_image.h"
click node_glad "https://github.com/rico-knots/p2pchess/blob/main/src/include/glad/gl.h"
click node_gl "https://github.com/rico-knots/p2pchess/blob/main/src/gl.c"
click node_shaders "https://github.com/rico-knots/p2pchess/blob/main/src/shaders/quad.vert"
click node_client "https://github.com/rico-knots/p2pchess/blob/main/src/networking/client.c"
click node_protocol "https://github.com/rico-knots/p2pchess/blob/main/src/networking/protocol.c"
click node_packets "https://github.com/rico-knots/p2pchess/blob/main/src/networking/packets.h"
click node_server "https://github.com/rico-knots/p2pchess/blob/main/src/networking/server.c"

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_entry toneBlue
class node_game,node_boards,node_moves toneAmber
class node_window,node_renderer,node_assets,node_images,node_glad,node_gl,node_shaders toneMint
class node_client,node_protocol,node_packets,node_server toneRose
class node_player,node_remote toneIndigo
```

## Components

### Application

- [Game Loop](https://github.com/rico-knots/p2pchess/blob/main/src/main.c): `src/main.c`

### Chess Engine

- [Game State](https://github.com/rico-knots/p2pchess/blob/main/src/engine/chess.c): `src/engine/chess.c`
- [Bitboards](https://github.com/rico-knots/p2pchess/blob/main/src/engine/bitboard.c): `src/engine/bitboard.c`
- [Move Generation](https://github.com/rico-knots/p2pchess/blob/main/src/engine/movegen.c): `src/engine/movegen.c`

### Graphical UI

- [Window](https://github.com/rico-knots/p2pchess/blob/main/src/ui/window.c): `src/ui/window.c`
- [Renderer](https://github.com/rico-knots/p2pchess/blob/main/src/ui/renderer.c): `src/ui/renderer.c`
- [Asset Manager](https://github.com/rico-knots/p2pchess/blob/main/src/ui/asset_manager.c): `src/ui/asset_manager.c`
- [Image Decoder](https://github.com/rico-knots/p2pchess/blob/main/src/include/stb/stb_image.h): `src/include/stb/stb_image.h`
- [OpenGL Loader](https://github.com/rico-knots/p2pchess/blob/main/src/include/glad/gl.h): `src/include/glad/gl.h`
- [OpenGL API](https://github.com/rico-knots/p2pchess/blob/main/src/gl.c): `src/gl.c`
- [Quad Shaders](https://github.com/rico-knots/p2pchess/blob/main/src/shaders/quad.vert): `src/shaders/quad.vert`

### Networking

- [Network Client](https://github.com/rico-knots/p2pchess/blob/main/src/networking/client.c): `src/networking/client.c`
- [Packet Protocol](https://github.com/rico-knots/p2pchess/blob/main/src/networking/protocol.c): `src/networking/protocol.c`
- [Packet Types](https://github.com/rico-knots/p2pchess/blob/main/src/networking/packets.h): `src/networking/packets.h`
- [Socket Server](https://github.com/rico-knots/p2pchess/blob/main/src/networking/server.c): `src/networking/server.c`

### Other components

- **Player**
- **Remote Peer**

## Connections

- Player → Game Loop: plays
- Game Loop → Window: runs loop (evidence: `src/main.c`)
- Game Loop → Game State: creates state (evidence: `src/main.c`)
- Game Loop → Window: draws state (evidence: `src/main.c`)
- Asset Manager → Image Decoder: decodes images (evidence: `src/ui/asset_manager.c`)
- Asset Manager → OpenGL Loader: uses API
- Socket Server → Packet Protocol: deserializes packets (evidence: `src/networking/server.c`)
- Network Client → Remote Peer: communicates
- Socket Server → Remote Peer: accepts connections (evidence: `src/networking/server.c`)
