# griffi-gh/kubi architecture

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

- Interactive diagram: https://gitdiagram.com/griffi-gh/kubi
- Repository: https://github.com/griffi-gh/kubi

## Overview

##### Identify the Project Type and Purpose
Kubi is a **multithreaded voxel engine with multiplayer networking**, developed in Rust. It leverages the `wgpu` crate for rendering, indicating a focus on high-performance graphics. The project supports procedural world generation, multiplayer capabilities, and cross-platform compatibility (Windows, Linux, OSX, Android).

**Key Indicators:**
- **Project Description:** "Heavily multithreaded voxel engine with multiplayer networking."
- **Features:** Multithreading, procedural generation, multiplayer networking, cross-platform support, and a custom UI system.
- **Technologies:** Rust, `wgpu`, `hUI`.

##### Analyze the File Structure
The file tree reveals a modular architecture with distinct components:

- **Top-Level Directories:**
- `.cargo`, `.github`, `.vscode`, suggesting configuration and CI/CD setup.
- `assets-src` and `assets` for game assets like models and fonts.
- `kubi`, `kubi-server`, `kubi-shared`, `kubi-logging`: Core modules of the engine, server, shared utilities, and logging.

- **Patterns and Architectural Choices:**
- **Modular Structure:** Separation of client (`kubi`), server (`kubi-server`), shared logic (`kubi-shared`), and logging (`kubi-logging`).
- **Multithreading:** Presence of modules like `world`, `mesh`, and `networking` within `kubi-shared` indicate concurrent processing.
- **Networking:** Files under `kubi-server/src/networking` and `kubi-shared/src/networking` suggest a client-server model.
- **Rendering:** Extensive `rendering` modules within `kubi/src`, utilizing `wgpu`.

- **Configuration and Build Files:**
- `Cargo.toml` and `Cargo.lock` for Rust dependencies.
- `flake.nix` and `flake.lock` indicating usage of Nix for package management.
- `.github/workflows/build.yml` for CI/CD workflows.

##### Examine the README for Additional Insights
The README provides comprehensive details:

- **Features:** Highlight multithreading, procedural generation, networking, and cross-platform support.
- **Technical Stack:** Rust with `wgpu` for rendering, custom UI system (`hUI`), and custom logging (`kubi-logging`).
- **Build Instructions:** Separate instructions for building on desktop and Android, indicating platform-specific components.
- **In-house Libraries:** Custom libraries like `hui`, `kubi-logging`, and deprecated ones like `kubi-udp` and `kubi-pool` show the project's evolution and modularity.

**a. Identify Main Components:**
- **Client (`kubi`):** Handles rendering, input, UI, and client-side world management.
- **Server (`kubi-server`):** Manages multiplayer networking, world state, and client connections.
- **Shared (`kubi-shared`):** Contains shared logic for blocks, chunks, world generation, networking protocols.
- **Logging (`kubi-logging`):** Custom logging mechanisms.
- **Assets:** Game assets including models, fonts, and shaders.
- **UI System (`hUI`):** Handles the user interface across platforms.
- **Build and Configuration:** Managed via Cargo and Nix configurations.

**b. Determine Relationships and Interactions:**
- **Client-Server Interaction:** Clients communicate with the server for multiplayer functionalities.
- **Shared Libraries:** Both client and server utilize `kubi-shared` for common functionalities like world data and networking protocols.
- **Rendering Pipeline:** `kubi` interacts with `wgpu` for rendering, utilizing shaders and managing the rendering pipeline.
- **World Generation:** Multithreaded processes within `kubi-shared` handle procedural generation and mesh creation.
- **UI Integration:** The client integrates the `hUI` system for the immediate UI.

**c. Highlight Architectural Patterns and Design Principles:**
- **Modular Architecture:** Clear separation of concerns between client, server, and shared components.
- **Client-Server Model:** Facilitates multiplayer networking and centralized world state management.
- **Multithreading:** Enhances performance for world generation and mesh processing.
- **Cross-Platform Abstraction:** Ensures compatibility across different operating systems and devices.

**d. Include Relevant Technologies and Frameworks:**
- **Rust:** Primary programming language.
- **wgpu:** For low-level rendering.
- **hUI:** Custom UI system.
- **Nix:** For package and build management.
- **Cargo:** Rust’s package manager and build tool.
- **Custom Libraries:** `kubi-logging`, `kubi-shared`, etc.

##### Elements

- **Clear Labels for Each Component:** Name all major modules (e.g., Client, Server, Shared Libraries, Rendering Engine).
- **Rendering Components:** Highlighted to differentiate from other systems.

##### Emphasizing Detail Without Overcomplication
That all essential architectural elements are captured:

- **Technologies:** Include key technologies where they play a significant role.
- **Scalability:** Represent how the architecture supports scalability, especially in multiplayer networking.

##### Final Recommendations
- Use **notations** like UML or C4 to standardize the representation.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Nodes
    Client["Client"]:::client
    Server["Server"]:::server
    Shared["Shared Libraries"]:::shared
    Logging["Logging"]:::logging
    AssetsSrc["Source Assets"]:::assets
    Assets["Compiled Assets"]:::assets
    UISystem["UI System"]:::ui
    RenderingCode["Rendering Code"]:::rendering
    Shaders["Shaders"]:::shaders
    CargoToml["Cargo.toml"]:::config
    CargoLock["Cargo.lock"]:::config
    FlakeNix["flake.nix"]:::config
    FlakeLock["flake.lock"]:::config
    CICD["CI/CD Workflows"]:::config

    %% Subgraphs
    subgraph "Build and Configuration"
        CargoToml
        CargoLock
        FlakeNix
        FlakeLock
        CICD
    end

    %% Connections
    Client -->|"uses"| RenderingCode
    RenderingCode -->|"uses"| Shaders
    Client -->|"uses"| UISystem
    Client -->|"uses"| AssetsSrc
    Client -->|"uses"| Assets
    Client -->|"uses"| Shared
    Client -->|"communicates with"| Server
    Client -->|"logs to"| Logging
    Server -->|"uses"| Shared
    Server -->|"logs to"| Logging
    Server -->|"communicates with"| Client
    CargoToml -->|"builds"| Client
    CargoToml -->|"builds"| Server
    CargoLock -->|"builds"| Client
    CargoLock -->|"builds"| Server
    FlakeNix -->|"builds"| Client
    FlakeNix -->|"builds"| Server
    FlakeLock -->|"builds"| Client
    FlakeLock -->|"builds"| Server
    CICD -->|"builds"| Client
    CICD -->|"builds"| Server

    %% Click Events
    click Client "https://github.com/griffi-gh/kubi/tree/master/kubi/"
    click Server "https://github.com/griffi-gh/kubi/tree/master/kubi-server/"
    click Shared "https://github.com/griffi-gh/kubi/tree/master/kubi-shared/"
    click Logging "https://github.com/griffi-gh/kubi/tree/master/kubi-logging/"
    click AssetsSrc "https://github.com/griffi-gh/kubi/tree/master/assets-src/"
    click Assets "https://github.com/griffi-gh/kubi/tree/master/assets/"
    click UISystem "https://github.com/griffi-gh/kubi/tree/master/kubi/src/ui/"
    click RenderingCode "https://github.com/griffi-gh/kubi/tree/master/kubi/src/rendering/"
    click Shaders "https://github.com/griffi-gh/kubi/tree/master/kubi/shaders/"
    click CargoToml "https://github.com/griffi-gh/kubi/blob/master/Cargo.toml"
    click CargoLock "https://github.com/griffi-gh/kubi/blob/master/Cargo.lock"
    click FlakeNix "https://github.com/griffi-gh/kubi/blob/master/flake.nix"
    click FlakeLock "https://github.com/griffi-gh/kubi/blob/master/flake.lock"
    click CICD "https://github.com/griffi-gh/kubi/blob/master/.github/workflows/build.yml"

    %% Styles
    classDef client fill:#ffcccc,stroke:#333;
    classDef server fill:#ccffcc,stroke:#333;
    classDef shared fill:#ccccff,stroke:#333;
    classDef logging fill:#ffffcc,stroke:#333;
    classDef assets fill:#ffccff,stroke:#333;
    classDef ui fill:#cceeff,stroke:#333;
    classDef rendering fill:#ffe5cc,stroke:#333;
    classDef shaders fill:#d9d9d9,stroke:#333;
    classDef config fill:#e6e6e6,stroke:#333;
    
    class Client client
    class Server server
    class Shared shared
    class Logging logging
    class AssetsSrc assets
    class Assets assets
    class UISystem ui
    class RenderingCode rendering
    class Shaders shaders
    class CargoToml config
    class CargoLock config
    class FlakeNix config
    class FlakeLock config
    class CICD config
```
