# p2r3/bareiron architecture

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

- Interactive diagram: https://gitdiagram.com/p2r3/bareiron
- Repository: https://github.com/p2r3/bareiron

## Overview

bareiron is a minimalist Minecraft 1.21.8 server designed for memory-restricted devices. A client connects over TCP, progresses through protocol states, and enters play; the server processes player actions and sends protocol updates, including generated chunks. Gameplay covers movement, block changes, inventory and crafting, entities and combat. World generation and optional persistence support the session. The README also documents ESP Wi-Fi hosting and optional world upload/download over TCP. Sampled source confirms key packet, gameplay, and generation links; some unsampled subsystem wiring is left out.

Main entry points: [`src/main.c`](https://github.com/p2r3/bareiron/blob/main/src/main.c) (Server loop), [`src/procedures.c`](https://github.com/p2r3/bareiron/blob/main/src/procedures.c) (Player and gameplay rules), [`src/packets.c`](https://github.com/p2r3/bareiron/blob/main/src/packets.c) (Packet handling), [`src/worldgen.c`](https://github.com/p2r3/bareiron/blob/main/src/worldgen.c) (Terrain and chunks)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_network["Connection and protocol"]
  node_server["Server loop<br/>[main.c]"]
  node_packets["Packet handling<br/>[packets.c]"]
  node_wire["Socket and encoding tools<br/>[tools.c]"]
end

subgraph group_game["Gameplay"]
  node_players["Player and gameplay rules<br/>[procedures.c]"]
  node_crafting["Crafting recipes<br/>[crafting.c]"]
  node_state["Player and world state<br/>[globals.h]"]
end

subgraph group_world["World and persistence"]
  node_worldgen["Terrain and chunks<br/>[worldgen.c]"]
  node_structures["World structures<br/>[structures.c]"]
  node_serialize["World serialization<br/>[serialize.c]"]
end

subgraph group_platform["Platform integration"]
  node_embedded["ESP Wi-Fi<br/>[main.c]"]
end

node_client(("Minecraft client"))
node_filesystem[("Local storage")]
node_dumpclient(("TCP dump client"))

node_client -->|"connects"| node_server
node_server -->|"accepts"| node_client
node_server -->|"dispatches"| node_packets
node_packets -->|"reads and writes"| node_wire
node_server -->|"handles gameplay"| node_players
node_players -->|"sends updates"| node_packets
node_players -->|"queries terrain"| node_worldgen
node_packets -->|"builds chunks"| node_worldgen
node_players -->|"updates state"| node_state
node_embedded -.->|"starts server"| node_server
node_dumpclient -.->|"uploads world data"| node_server
node_server -.->|"persists world"| node_filesystem
node_server -.->|"serializes world"| node_serialize

click node_server "https://github.com/p2r3/bareiron/blob/main/src/main.c"
click node_packets "https://github.com/p2r3/bareiron/blob/main/src/packets.c"
click node_wire "https://github.com/p2r3/bareiron/blob/main/src/tools.c"
click node_players "https://github.com/p2r3/bareiron/blob/main/src/procedures.c"
click node_crafting "https://github.com/p2r3/bareiron/blob/main/src/crafting.c"
click node_state "https://github.com/p2r3/bareiron/blob/main/include/globals.h"
click node_worldgen "https://github.com/p2r3/bareiron/blob/main/src/worldgen.c"
click node_structures "https://github.com/p2r3/bareiron/blob/main/src/structures.c"
click node_serialize "https://github.com/p2r3/bareiron/blob/main/src/serialize.c"
click node_embedded "https://github.com/p2r3/bareiron/blob/main/src/main.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_server,node_packets,node_wire,node_client,node_dumpclient toneBlue
class node_players,node_crafting,node_state,node_filesystem toneAmber
class node_worldgen,node_structures,node_serialize toneMint
class node_embedded toneRose
```

## Components

### Connection and protocol

- [Server loop](https://github.com/p2r3/bareiron/blob/main/src/main.c): `src/main.c`
- [Packet handling](https://github.com/p2r3/bareiron/blob/main/src/packets.c): `src/packets.c`
- [Socket and encoding tools](https://github.com/p2r3/bareiron/blob/main/src/tools.c): `src/tools.c`

### Gameplay

- [Player and gameplay rules](https://github.com/p2r3/bareiron/blob/main/src/procedures.c): `src/procedures.c`
- [Crafting recipes](https://github.com/p2r3/bareiron/blob/main/src/crafting.c): `src/crafting.c`
- [Player and world state](https://github.com/p2r3/bareiron/blob/main/include/globals.h): `include/globals.h`

### World and persistence

- [Terrain and chunks](https://github.com/p2r3/bareiron/blob/main/src/worldgen.c): `src/worldgen.c`
- [World structures](https://github.com/p2r3/bareiron/blob/main/src/structures.c): `src/structures.c`
- [World serialization](https://github.com/p2r3/bareiron/blob/main/src/serialize.c): `src/serialize.c`

### Platform integration

- [ESP Wi-Fi](https://github.com/p2r3/bareiron/blob/main/src/main.c): `src/main.c`

### Other components

- **Minecraft client**
- **Local storage**
- **TCP dump client**

## Connections

- Minecraft client → Server loop: connects
- Server loop → Minecraft client: accepts
- Server loop → Packet handling: dispatches
- Packet handling → Socket and encoding tools: reads and writes
- Server loop → Player and gameplay rules: handles gameplay
- Player and gameplay rules → Packet handling: sends updates
- Player and gameplay rules → Terrain and chunks: queries terrain
- Packet handling → Terrain and chunks: builds chunks
- Player and gameplay rules → Player and world state: updates state
- ESP Wi-Fi → Server loop: starts server
- TCP dump client → Server loop: uploads world data
- Server loop → Local storage: persists world
- Server loop → World serialization: serializes world
