# pyrite-dev/nishbox architecture

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

- Interactive diagram: https://gitdiagram.com/pyrite-dev/nishbox
- Repository: https://github.com/pyrite-dev/nishbox

## Overview

##### Project type and purpose
- This is “NishBox,” a multiplayer sandbox game written in C. It follows a classic client-server architecture, powered by a shared game engine and asset pipeline.
- The README confirms it’s a networked game with nightly builds via Jenkins and uses Premake5 as its build generator.

##### File structure
- Top-level directories
- data/ → all runtime assets (fonts, textures, music, scripts, sound)
- engine/ → shared engine code (graphics, input, audio, scripting)
- src/client/ → client entry point and UI code (main.c)
- src/server/ → server entry point and authoritative game logic (main.c)
- tool/ → shell scripts for cleaning, formatting, packaging, tooling (format.sh, pack.sh, etc.)
- Build scripts
- premake5.lua → defines project targets
- Jenkinsfile → CI pipeline
- BUILDING.md → build instructions
- Configs and assets
- data/scripts/*.lua → Lua scripts loaded at runtime by the engine
- data/font, data/music, data/sound, data/texture → various asset subdirectories

##### README for additional insights
- Multiplayer sandbox game
- Stack: Premake5 for project generation
- Jenkins for nightly build

a. Main components
1. Game Client
– Loads assets (textures, fonts, audio, Lua scripts)
– Renders graphics, handles user input
– Network module to communicate with server
2. Game Server
– Headless engine instance handling world state
– Runs authoritative game logic via Lua scripts
– Broadcasts state updates to clients
3. Shared Engine Module
– Core sub-systems (rendering, audio, input, scripting)
– Exposed to both client and server
4. Asset Repository
– data/ folder with fonts, textures, audio, scripts, configs
5. Build & Dev Tools
– Premake5 → generates build files for makefiles/Visual Studio
– tool/*.sh scripts → automate cleaning, formatting, packaging
6. CI Pipeline (Jenkins)
– Triggers on commits
– Runs build, tests, packaging → produces nightly binaries

b. Relationships and interactions

c. Architectural patterns/design principles
– Client-Server separation of concerns
– Shared library approach for the engine (code reuse)
– Scripting extensibility via Lua (data-driven design)
– Modular asset pipeline (fonts, textures, sound, music, scripts)

d. Key technologies/frameworks
– C language core
– Lua scripting
– Premake5 for project generation
– Shell scripts for tooling
– Jenkins for CI

##### Elements
- from Client ↔ Server (network flow)
- from both Client/Server → Assets (I/O)
- from Build Tools → Engine/Client/Server (compilation)
- from Jenkins → Build Tools (CI trigger)
- Build/dev components (Premake, tool scripts, Jenkins) in another
- External dependencies (Lua) in a third

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Development Layer"
        Jenkins["Jenkins Pipeline"]:::ci
        Premake["premake5.lua"]:::build
        BuildInst["BUILDING.md"]:::build
        Tool["tool/"]:::build
        RC["Windows RC (nishbox.rc)"]:::build
    end

    Jenkins --> Premake
    Jenkins --> Tool
    BuildInst --> Premake
    Tool --> Premake

    subgraph "Build Artifacts"
        ClientBin["Client Binary"]:::runtime
        ServerBin["Server Binary"]:::runtime
    end

    Premake --> ClientBin
    Premake --> ServerBin
    Tool --> ClientBin
    Tool --> ServerBin

    subgraph "Runtime Layer"
        Engine["Shared Engine Library"]:::runtime
        Client["Game Client"]:::runtime
        Server["Game Server"]:::runtime
        subgraph "Assets (data/)"
            Font["Fonts"]:::data
            Texture["Textures"]:::data
            Sound["Sounds"]:::data
            Music["Music"]:::data
            Scripts["Lua Scripts"]:::ext
        end
    end

    ClientBin --> Client
    ServerBin --> Server
    Engine --> Client
    Engine --> Server
    Client <-->|"UDP/TCP"| Server
    Client -->|"loads assets"| Font
    Client -->|"loads assets"| Texture
    Client -->|"loads assets"| Sound
    Client -->|"loads assets"| Music
    Client -->|"loads scripts"| Scripts
    Server -->|"loads assets"| Font
    Server -->|"loads assets"| Texture
    Server -->|"loads assets"| Sound
    Server -->|"loads assets"| Music
    Server -->|"loads scripts"| Scripts
    Scripts -.->|"scripting engine"| Engine

    click Client "https://github.com/pyrite-dev/nishbox/blob/master/src/client/main.c"
    click RC "https://github.com/pyrite-dev/nishbox/blob/master/src/nishbox.rc"
    click Server "https://github.com/pyrite-dev/nishbox/blob/master/src/server/main.c"
    click Engine "https://github.com/pyrite-dev/nishbox/tree/master/engine/"
    click Font "https://github.com/pyrite-dev/nishbox/tree/master/data/font/"
    click Texture "https://github.com/pyrite-dev/nishbox/tree/master/data/texture/"
    click Sound "https://github.com/pyrite-dev/nishbox/tree/master/data/sound/"
    click Music "https://github.com/pyrite-dev/nishbox/tree/master/data/music/"
    click Scripts "https://github.com/pyrite-dev/nishbox/blob/master/data/scripts/*.lua"
    click Premake "https://github.com/pyrite-dev/nishbox/blob/master/premake5.lua"
    click BuildInst "https://github.com/pyrite-dev/nishbox/blob/master/BUILDING.md"
    click Tool "https://github.com/pyrite-dev/nishbox/tree/master/tool/"
    click Jenkins "https://github.com/pyrite-dev/nishbox/tree/master/Jenkinsfile"

    classDef runtime fill:#f9f,stroke:#333,stroke-width:1px
    classDef build fill:#bbf,stroke:#333,stroke-width:1px
    classDef ci fill:#bfb,stroke:#333,stroke-width:1px
    classDef data fill:#fbf,stroke:#333,stroke-width:1px
    classDef ext fill:#ffb,stroke:#333,stroke-width:1px
```
