# stefanwerfling/sacredbamboo architecture

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

- Interactive diagram: https://gitdiagram.com/stefanwerfling/sacredbamboo
- Repository: https://github.com/stefanwerfling/sacredbamboo

## Overview

##### Project type and purpose
- This is a single‐binary, C‐based lobby server for a multiplayer game. It accepts client connections, manages lobbies/sessions, and routes players into game instances.

##### File structure
- Top level:
- LICENSE
- README.md
- work/
– GameServer.c  (the main server code)
– Readme.md     (any local notes)

- There are no separate frontend or database subfolders, so the architecture is a standalone backend service.

##### README for additional insights
- The README simply states “Lobby Server.” It implies responsibilities: listen on network ports, handle client messaging, maintain lobby state, and potentially spawn or hand off to game instances.

##### Main components & their relationships
a. Components to show:
1. External Game Clients
2. Network Listener Module (inside GameServer)
3. Session/Lobby Manager Module
4. Message Parser/Dispatcher
5. Game Instance Spawner or Hand-off Interface
6. (Optional) Persistence or Configuration Loader
7. (Optional) Logging/Monitoring Subsystem

b. Interactions and data flows:
- Clients → TCP/UDP socket → Network Listener
- Network Listener → raw packets → Message Parser
- Parser → command events → Lobby Manager
- Lobby Manager ↔ in-memory session store
- Lobby Manager → spawn new game → Game Instance Spawner
- All modules → logging API → Logging Subsystem

c. Architectural patterns & principles:
- Event‐driven Reactor pattern for network I/O
- Modular separation: I/O layer, parsing layer, state management layer
- In-memory storage for minimal latency (no external DB by default)
- Optional plugin points: configurable hand-off to other game servers

d. Key technologies & libraries:
- C sockets API (BSD sockets)
- Select()/epoll() or similar event loop
- Dia for diagramming (sacred_gameserver.dia)
- Standard C library for config and logging

##### Diagramming recommendations
- Blue for I/O modules
- Green for core logic (Lobby Manager)
- Orange for auxiliary services (Logging, Config)
- Related modules in a lightly shaded container labeled “GameServer Process.”

##### Detail level & essential elements

[Game Clients] ──TCP/UDP──> [Network Listener] ──> [Message Parser] ──> [Lobby Manager] ──> [Game Instance Spawner]
↘
└─> [Logging Subsystem]
↘
└─> [Configuration Loader]

## Diagram (Mermaid)

```mermaid
flowchart TD
    ExternalClients(["Game Clients"]):::external

    subgraph "GameServer Process"
        NetworkListener["Network Listener Module"]:::io
        MessageParser["Message Parser/Dispatcher"]:::io
        LobbyManager["Session/Lobby Manager Module"]:::core
        GameSpawner["Game Instance Spawner"]:::core
        ConfigLoader["Configuration Loader"]:::aux
        Logging["Logging/Monitoring Subsystem"]:::aux
    end

    subgraph Documentation
        README["Project README"]:::doc
        LocalNotes["Local Notes (Readme)"]:::doc
        DiaDraft["Diagram Draft (.dia)"]:::doc
        License["LICENSE File"]:::doc
    end

    ExternalClients -->|"TCP/UDP Packet"| NetworkListener
    NetworkListener -->|"Raw Packet"| MessageParser
    MessageParser -->|"Command Event"| LobbyManager
    LobbyManager -->|"Spawn Request"| GameSpawner

    NetworkListener -->|"Log API Call"| Logging
    MessageParser -->|"Log API Call"| Logging
    LobbyManager -->|"Log API Call"| Logging
    GameSpawner -->|"Log API Call"| Logging

    NetworkListener -->|"Config Read"| ConfigLoader
    MessageParser -->|"Config Read"| ConfigLoader
    LobbyManager -->|"Config Read"| ConfigLoader
    GameSpawner -->|"Config Read"| ConfigLoader

    README -->|"provides overview"| NetworkListener
    LocalNotes -->|"local notes"| NetworkListener
    DiaDraft -->|"existing draft"| NetworkListener
    License -->|"license info"| NetworkListener

    click NetworkListener "https://github.com/stefanwerfling/sacredbamboo/blob/main/work/GameServer.c"
    click MessageParser "https://github.com/stefanwerfling/sacredbamboo/blob/main/work/GameServer.c"
    click LobbyManager "https://github.com/stefanwerfling/sacredbamboo/blob/main/work/GameServer.c"
    click GameSpawner "https://github.com/stefanwerfling/sacredbamboo/blob/main/work/GameServer.c"
    click ConfigLoader "https://github.com/stefanwerfling/sacredbamboo/blob/main/work/GameServer.c"
    click Logging "https://github.com/stefanwerfling/sacredbamboo/blob/main/work/GameServer.c"
    click DiaDraft "https://github.com/stefanwerfling/sacredbamboo/blob/main/work/sacred_gameserver.dia"
    click README "https://github.com/stefanwerfling/sacredbamboo/blob/main/README.md"
    click LocalNotes "https://github.com/stefanwerfling/sacredbamboo/blob/main/work/Readme.md"
    click License "https://github.com/stefanwerfling/sacredbamboo/tree/main/LICENSE"

    classDef external fill:#CCCCFF,stroke:#333,stroke-width:1px
    classDef io fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef core fill:#90EE90,stroke:#333,stroke-width:1px
    classDef aux fill:#FFA500,stroke:#333,stroke-width:1px
    classDef doc fill:#F5F5F5,stroke:#333,stroke-width:1px
```
