# andreivasiliu/cybersub architecture

> Architecture diagram of the GitHub repository andreivasiliu/cybersub, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/andreivasiliu/cybersub
- Repository: https://github.com/andreivasiliu/cybersub

## Overview

##### Main Components

A. Core Game Engine Layer
- Macroquad Framework Integration
- Game Loop Controller
- Resource Management System

B. Rendering System
- Shader Pipeline (multiple .glsl files indicate sophisticated rendering)
- UI System (ui.rs)

C. Game State Management
- Physics Engine (water.rs, collisions.rs)
- Object Management (objects.rs)
- State Controller (state.rs)
- Input Handler (input.rs)

D. Platform-Specific Components
- WASM Build Pipeline
- Native Desktop Build Pipeline
- Client-Server Architecture (client.rs, server.rs)

**[Platform Layer (Web/Desktop)]**
- ↕
**[Core Engine Layer]**
- ↕
**[Game Systems Layer]**
- ↕
**[Resource Layer]**

##### Key Relationships to Highlight

- Data flow between game_state components
- Shader pipeline's interaction with the rendering system
- Demonstrate the platform-specific compilation targets
- Resource loading and management paths

##### Component Relationships

**[Input Handler] → [Game State] → [Physics Engine]**
- ↕
**[Resource Manager] ← [Renderer] → [Shader Pipeline]**

##### Technical Details

- Macroquad as the primary framework
- WASM/JavaScript bridge for web deployment
- WebGL shader implementation
- Grid-based water simulation system

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style Definitions
    classDef core fill:#2196F3,stroke:#1565C0,color:white
    classDef render fill:#4CAF50,stroke:#2E7D32,color:white
    classDef state fill:#FF9800,stroke:#EF6C00,color:white
    classDef platform fill:#9C27B0,stroke:#6A1B9A,color:white
    classDef physics fill:#F44336,stroke:#C62828,color:white
    classDef resource fill:#795548,stroke:#4E342E,color:white
    classDef shader fill:#00BCD4,stroke:#00838F,color:white

    subgraph Core["Core Game Engine"]
        GameLoop["Game Loop Controller"]:::core
        ResourceMgr["Resource Management"]:::core
    end

    subgraph Render["Rendering System"]
        DrawSys["Drawing System"]:::render
        UISys["UI System"]:::render
        
        subgraph Shaders["Shader Pipeline"]
            Vertex["Vertex Shader"]:::shader
            Water["Water Shader"]:::shader
            Rocks["Rocks Shader"]:::shader
            Shadows["Shadows Shader"]:::shader
            PointLight["Point Light Shader"]:::shader
            Highlight["Highlight Shader"]:::shader
            Walls["Walls Shader"]:::shader
            Wires["Wires Shader"]:::shader
            Sonar["Sonar Shader"]:::shader
        end
    end

    subgraph GameState["Game State Management"]
        StateCtrl["State Controller"]:::state
        InputHandler["Input Handler"]:::state
        ObjMgr["Object Management"]:::state
        
        subgraph Physics["Physics Engine"]
            WaterSim["Water Simulation"]:::physics
            Collisions["Collision System"]:::physics
        end
    end

    subgraph Platform["Platform Layer"]
        WASM["WASM Build"]:::platform
        Desktop["Desktop Build"]:::platform
        Client["Client"]:::platform
        Server["Server"]:::platform
    end

    subgraph Additional["Additional Systems"]
        SaveLoad["Save/Load System"]:::resource
        SonarSys["Sonar System"]:::state
        WireSys["Wire System"]:::state
        ShadowSys["Shadow System"]:::state
    end

    %% Relationships
    GameLoop --> StateCtrl
    InputHandler --> StateCtrl
    StateCtrl --> Physics
    StateCtrl --> ObjMgr
    ResourceMgr --> DrawSys
    DrawSys --> Shaders
    Physics --> DrawSys
    ObjMgr --> DrawSys
    StateCtrl --> SaveLoad
    SonarSys --> DrawSys
    WireSys --> DrawSys
    ShadowSys --> DrawSys
    Client --> Server
    
    %% Click Events
    click GameLoop "https://github.com/andreivasiliu/cybersub/blob/master/src/app.rs"
    click ResourceMgr "https://github.com/andreivasiliu/cybersub/blob/master/src/resources.rs"
    click DrawSys "https://github.com/andreivasiliu/cybersub/blob/master/src/draw.rs"
    click UISys "https://github.com/andreivasiliu/cybersub/blob/master/src/ui.rs"
    click Vertex "https://github.com/andreivasiliu/cybersub/blob/master/src/vertex.glsl"
    click Water "https://github.com/andreivasiliu/cybersub/blob/master/src/water.glsl"
    click Rocks "https://github.com/andreivasiliu/cybersub/blob/master/src/rocks.glsl"
    click Shadows "https://github.com/andreivasiliu/cybersub/blob/master/src/shadows.glsl"
    click PointLight "https://github.com/andreivasiliu/cybersub/blob/master/src/pointlight.glsl"
    click Highlight "https://github.com/andreivasiliu/cybersub/blob/master/src/highlight.glsl"
    click Walls "https://github.com/andreivasiliu/cybersub/blob/master/src/walls.glsl"
    click Wires "https://github.com/andreivasiliu/cybersub/blob/master/src/wires.glsl"
    click WaterSim "https://github.com/andreivasiliu/cybersub/blob/master/src/game_state/water.rs"
    click Collisions "https://github.com/andreivasiliu/cybersub/blob/master/src/game_state/collisions.rs"
    click ObjMgr "https://github.com/andreivasiliu/cybersub/blob/master/src/game_state/objects.rs"
    click StateCtrl "https://github.com/andreivasiliu/cybersub/blob/master/src/game_state/state.rs"
    click InputHandler "https://github.com/andreivasiliu/cybersub/blob/master/src/input.rs"
    click Client "https://github.com/andreivasiliu/cybersub/blob/master/src/client.rs"
    click Server "https://github.com/andreivasiliu/cybersub/blob/master/src/server.rs"
    click WASM "https://github.com/andreivasiliu/cybersub/blob/master/docs/cybersub.wasm"
    click SaveLoad "https://github.com/andreivasiliu/cybersub/blob/master/src/saveload.rs"
    click SonarSys "https://github.com/andreivasiliu/cybersub/blob/master/src/game_state/sonar.rs"
    click Sonar "https://github.com/andreivasiliu/cybersub/blob/master/src/sonar.glsl"
    click WireSys "https://github.com/andreivasiliu/cybersub/blob/master/src/game_state/wires.rs"
    click ShadowSys "https://github.com/andreivasiliu/cybersub/blob/master/src/shadows.rs"
```
