# dawidg81/sn architecture

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

- Interactive diagram: https://gitdiagram.com/dawidg81/sn
- Repository: https://github.com/dawidg81/sn

## Overview

Supernova is a Minecraft Classic/ClassiCube multiplayer server. A client connects and identifies; the server validates its protocol, authentication and ban status, sends the world and player state, then handles chat, commands, movement and block updates. World data is loaded and saved locally, while a separate heartbeat advertises the server to ClassiCube. The graph reflects the sampled C implementation and README; physics is described as TODO, not an implemented stage.

Main entry points: [`src/game.h`](https://github.com/dawidg81/sn/blob/master/src/game.h) (Session handler), [`src/player.h`](https://github.com/dawidg81/sn/blob/master/src/player.h) (Player state & policy), [`src/level.h`](https://github.com/dawidg81/sn/blob/master/src/level.h) (Level data & transfer), [`src/main.c`](https://github.com/dawidg81/sn/blob/master/src/main.c) (Startup & lifecycle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server Runtime"]
  node_main["Startup &amp; lifecycle<br/>[main.c]"]
  node_listener["TCP listener<br/>[socket.h]"]
  node_sessions["Session handler<br/>[game.h]"]
  node_commands["Chat commands<br/>[cmds.h]"]
end

subgraph group_protocol["Client Protocol"]
  node_player["Player state &amp; policy<br/>[player.h]"]
  node_packets["Packet encoding<br/>[server.h]"]
  node_codec["Wire-format helpers<br/>[network_utils.h]"]
end

subgraph group_world["World State"]
  node_level["Level data &amp; transfer<br/>[level.h]"]
  node_worldfile[("World save file<br/>[level.bin]")]
end

subgraph group_services["Authentication &amp; Discovery"]
  node_crypto["MD5 verification<br/>[crypt.h]"]
  node_salt["Server salt<br/>[attr.h]"]
  node_heartbeat["Server heartbeat<br/>[heartbeat.h]"]
end

node_operator(("Server operator"))
node_client(("Game client"))
node_directory["ClassiCube directory"]

node_operator -->|"starts server"| node_main
node_main -->|"initializes and loads"| node_level
node_main -->|"opens listener"| node_listener
node_main -->|"starts heartbeat"| node_heartbeat
node_main -->|"starts connection loop"| node_sessions
node_client -->|"connects and sends packets"| node_sessions
node_sessions -->|"parses and checks player"| node_player
node_sessions -->|"checks verification hash"| node_crypto
node_sessions -->|"uses server salt"| node_salt
node_sessions -->|"sends level"| node_level
node_sessions -->|"sends player packets"| node_packets
node_sessions -->|"dispatches slash commands"| node_commands
node_sessions -->|"applies block updates"| node_player
node_commands -->|"checks admin status"| node_player
node_commands -->|"saves world"| node_level
node_player -->|"writes block changes"| node_level
node_player -->|"decodes packet fields"| node_codec
node_packets -->|"encodes packet fields"| node_codec
node_level -->|"encodes dimensions"| node_codec
node_level -->|"reads and writes"| node_worldfile
node_heartbeat -->|"counts connected players"| node_player
node_heartbeat -->|"advertises server"| node_directory
node_sessions -->|"sends world and updates"| node_client

click node_main "https://github.com/dawidg81/sn/blob/master/src/main.c"
click node_listener "https://github.com/dawidg81/sn/blob/master/src/socket.h"
click node_sessions "https://github.com/dawidg81/sn/blob/master/src/game.h"
click node_commands "https://github.com/dawidg81/sn/blob/master/src/cmds.h"
click node_player "https://github.com/dawidg81/sn/blob/master/src/player.h"
click node_packets "https://github.com/dawidg81/sn/blob/master/src/server.h"
click node_codec "https://github.com/dawidg81/sn/blob/master/src/network_utils.h"
click node_crypto "https://github.com/dawidg81/sn/blob/master/src/crypt.h"
click node_salt "https://github.com/dawidg81/sn/blob/master/src/attr.h"
click node_heartbeat "https://github.com/dawidg81/sn/blob/master/src/heartbeat.h"
click node_level "https://github.com/dawidg81/sn/blob/master/src/level.h"
click node_worldfile "https://github.com/dawidg81/sn/blob/master/level.bin"

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_listener,node_sessions,node_commands,node_client toneBlue
class node_player,node_packets,node_codec toneAmber
class node_level,node_worldfile,node_operator toneMint
class node_crypto,node_salt,node_heartbeat toneRose
class node_directory toneIndigo
```

## Components

### Server Runtime

- [Startup & lifecycle](https://github.com/dawidg81/sn/blob/master/src/main.c): `src/main.c`
- [TCP listener](https://github.com/dawidg81/sn/blob/master/src/socket.h): `src/socket.h`
- [Session handler](https://github.com/dawidg81/sn/blob/master/src/game.h): `src/game.h`
- [Chat commands](https://github.com/dawidg81/sn/blob/master/src/cmds.h): `src/cmds.h`

### Client Protocol

- [Player state & policy](https://github.com/dawidg81/sn/blob/master/src/player.h): `src/player.h`
- [Packet encoding](https://github.com/dawidg81/sn/blob/master/src/server.h): `src/server.h`
- [Wire-format helpers](https://github.com/dawidg81/sn/blob/master/src/network_utils.h): `src/network_utils.h`

### World State

- [Level data & transfer](https://github.com/dawidg81/sn/blob/master/src/level.h): `src/level.h`
- [World save file](https://github.com/dawidg81/sn/blob/master/level.bin): `level.bin`

### Authentication & Discovery

- [MD5 verification](https://github.com/dawidg81/sn/blob/master/src/crypt.h): `src/crypt.h`
- [Server salt](https://github.com/dawidg81/sn/blob/master/src/attr.h): `src/attr.h`
- [Server heartbeat](https://github.com/dawidg81/sn/blob/master/src/heartbeat.h): `src/heartbeat.h`

### Other components

- **Server operator**
- **Game client**
- **ClassiCube directory**

## Connections

- Server operator → Startup & lifecycle: starts server (evidence: `src/main.c`)
- Startup & lifecycle → Level data & transfer: initializes and loads (evidence: `src/main.c`)
- Startup & lifecycle → TCP listener: opens listener (evidence: `src/main.c`)
- Startup & lifecycle → Server heartbeat: starts heartbeat (evidence: `src/main.c`)
- Startup & lifecycle → Session handler: starts connection loop (evidence: `src/main.c`)
- Game client → Session handler: connects and sends packets (evidence: `src/game.h`)
- Session handler → Player state & policy: parses and checks player (evidence: `src/game.h`)
- Session handler → MD5 verification: checks verification hash (evidence: `src/game.h`)
- Session handler → Server salt: uses server salt (evidence: `src/game.h`)
- Session handler → Level data & transfer: sends level (evidence: `src/game.h`)
- Session handler → Packet encoding: sends player packets (evidence: `src/game.h`)
- Session handler → Chat commands: dispatches slash commands (evidence: `src/game.h`)
- Session handler → Player state & policy: applies block updates (evidence: `src/player.h`)
- Chat commands → Player state & policy: checks admin status (evidence: `src/cmds.h`)
- Chat commands → Level data & transfer: saves world (evidence: `src/cmds.h`)
- Player state & policy → Level data & transfer: writes block changes (evidence: `src/player.h`)
- Player state & policy → Wire-format helpers: decodes packet fields (evidence: `src/player.h`)
- Packet encoding → Wire-format helpers: encodes packet fields (evidence: `src/server.h`)
- Level data & transfer → Wire-format helpers: encodes dimensions (evidence: `src/level.h`)
- Level data & transfer → World save file: reads and writes (evidence: `src/level.h`)
- Server heartbeat → Player state & policy: counts connected players (evidence: `src/heartbeat.h`)
- Server heartbeat → ClassiCube directory: advertises server (evidence: `src/heartbeat.h`)
- Session handler → Game client: sends world and updates (evidence: `src/game.h`)
