# bsrodrigue/rapid_shooter architecture

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

- Interactive diagram: https://gitdiagram.com/bsrodrigue/rapid_shooter
- Repository: https://github.com/bsrodrigue/rapid_shooter

## Overview

##### Project type and purpose
- This is a native C++ game/application with an integrated level-editor and entity-editor, built via CMake.
- It uses raylib (via rlImGui), ImGui for UI, cJSON for config loading, and a custom asset/code-generation pipeline.

##### Main architectural layers
A. Toolchain & Build
– CMakeLists.txt & build/ directory
– Codegen scripts (scripts/codegen/*.py)
– External libraries (external/imgui, external/rlImGui)
B. Asset & Content Pipeline
– Asset folders (assets/shaders, assets/textures)
– Configs (configs/entities/entities.json)
– scripts/codegen converting JSON + shaders + textures → C++ loader code
C. Engine & Runtime
– Core game loop (src/main.cc → game.cc)
– Subsystems:
· Entity management (entities.cc/h)
· Input & UI (rlImGui, editor UI in level_editor.cc/h)
· Physics/collision (collision.cc/h)
· Game logic (player.cc, enemy.cc, projectiles.cc, item.cc, etc.)
· Persistence (save.cc/h, json.cc/h)
D. Tool/UI Mode
– Level editor (level_editor.cc/h + level_editor_utils)
– Entity editor (editor_entities.h + UI panels via ImGui)

##### Relationships & data flows
- Build System → links External Libs + src + generated code → produces “autohacka” binary
- At runtime:
1. main() initializes subsystems (graphics, input, audio if any, config loader)
2. Config Loader parses JSON (via cJSON) → populates Entity definitions & level data
3. Asset Manager loads textures/shaders from disk → creates GPU resources
4. Game Loop iterates:
a. Input System captures user/keyboard events → forwards to Game Logic & Editor UI
b. Physics System updates collision/world state
c. Entity System updates all entities (player, enemies, items, projectiles)
e. UI System (ImGui) draws overlays & editor panels
5. Save System serializes game state back to JSON when requested

##### Architectural patterns & design principles
- Modular Subsystems: each responsibility isolated (Rendering, Physics, Input, UI, Persistence)
- Data-Driven Entities: definitions in JSON generate C++ code allowing hot edits
- Codegen Pipeline: scripts/codegen to automate repetitive loader/serializer code
- Editor integration: same engine core supports both gameplay and editing modes

##### Elements
– Build System (CMake + codegen scripts + external libs)
– Config Service (JSON loader via cJSON)
– Asset Manager (textures, shaders)
– Subsystems: Input, Physics, Entity Manager, Renderer, UI, Save/Load
– Game Loop coordinator
– Level Editor & Entity Editor modules
– Show build-time flow: codegen → compile → binary
– Show runtime data-flow: Input → Game Loop → Subsystems → Renderer/UI → Frame output
– Config & Assets → loaded into memory → used by Subsystems

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Toolchain & Build Layer
    subgraph "Toolchain & Build"
        direction TB
        BuildSystem["Build System\n(CMakeLists.txt & build/)"]:::build
        CodegenPipeline["Codegen Pipeline\n(scripts/codegen/*.py)"]:::pipeline
        ExternalLibs["External Libraries\n(external/imgui, external/rlImGui)"]:::build
    end

    %% Asset & Content Pipeline
    subgraph "Asset & Content Pipeline"
        direction TB
        ConfigService["Config Service\n(JSON Loader)"]:::data
        subgraph "Asset Manager"
            direction TB
            Shaders["Shaders\n(assets/shaders)"]:::data
            Textures["Textures\n(assets/textures)"]:::data
        end
    end

    %% Engine & Runtime
    subgraph "Engine Core (Runtime)" 
        direction TB
        GameLoop["Game Loop\n(src/main.cc, src/game.cc)"]:::runtime
        subgraph "Subsystems"
            direction TB
            InputSystem["Input System\n(src/common.cc)"]:::runtime
            Physics["Physics/Collision\n(src/collision.cc)"]:::runtime
            EntityMgr["Entity Manager\n(src/entities.cc)"]:::runtime
            Rendering["Rendering\n(src/draw.cc, src/shaders.cc, src/textures.cc)"]:::runtime
            UISubsystem["UI System\n(ImGui via rlImGui)"]:::runtime
            Persistence["Save/Load\n(src/save.cc)"]:::runtime
        end
        subgraph "Game Logic Entities"
            direction TB
            Player["Player\n(src/player.cc)"]:::runtime
            Enemy["Enemy\n(src/enemy.cc)"]:::runtime
            Projectiles["Projectiles\n(src/projectiles.cc)"]:::runtime
            Items["Items\n(src/item.cc, src/item_drop.cc)"]:::runtime
            Inventory["Inventory\n(src/inventory.cc)"]:::runtime
            Environment["Level & Env\n(src/level.cc, src/wall.cc, src/gate.cc, src/warpzone.cc)"]:::runtime
        end
    end

    %% Tool/UI Mode
    subgraph "Editor Mode"
        direction TB
        LevelEditor["Level Editor\n(src/level_editor.cc)"]:::editor
        EntityEditor["Entity Editor UI\n(include/editor_entities.h)"]:::editor
    end

    %% Build-time flow
    CodegenPipeline -->|generates| BuildSystem
    ExternalLibs -->|linked by| BuildSystem

    %% Runtime initialization
    BuildSystem -->|produces binary| GameLoop
    ConfigService -->|loads JSON| GameLoop
    Shaders -->|loaded by| GameLoop
    Textures -->|loaded by| GameLoop

    %% Game Loop orchestration
    GameLoop -->|captures| InputSystem
    GameLoop -->|updates| Physics
    GameLoop -->|updates| EntityMgr
    EntityMgr -->|manages| Player
    EntityMgr -->|manages| Enemy
    EntityMgr -->|manages| Projectiles
    EntityMgr -->|manages| Items
    EntityMgr -->|manages| Inventory
    EntityMgr -->|manages| Environment
    GameLoop -->|renders via| Rendering
    GameLoop -->|draws UI via| UISubsystem
    GameLoop -->|saves via| Persistence

    %% Editor integration
    LevelEditor -->|uses| EntityMgr
    LevelEditor -->|draws UI via| UISubsystem
    EntityEditor -->|uses| EntityMgr
    EntityEditor -->|draws UI via| UISubsystem

    %% Click Events
    click BuildSystem "https://github.com/bsrodrigue/rapid_shooter/blob/main/CMakeLists.txt"
    click CodegenPipeline "https://github.com/bsrodrigue/rapid_shooter/blob/main/scripts/codegen/entity_parsing_serializing.py"
    click CodegenPipeline "https://github.com/bsrodrigue/rapid_shooter/blob/main/scripts/codegen/shaders.py"
    click CodegenPipeline "https://github.com/bsrodrigue/rapid_shooter/blob/main/scripts/codegen/textures.py"
    click ExternalLibs "https://github.com/bsrodrigue/rapid_shooter/tree/main/external/imgui/"
    click ExternalLibs "https://github.com/bsrodrigue/rapid_shooter/tree/main/external/rlImGui/"
    click ConfigService "https://github.com/bsrodrigue/rapid_shooter/blob/main/configs/entities/entities.json"
    click Shaders "https://github.com/bsrodrigue/rapid_shooter/tree/main/assets/shaders/"
    click Shaders "https://github.com/bsrodrigue/rapid_shooter/blob/main/include/shaders.h"
    click Shaders "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/shaders.cc"
    click Textures "https://github.com/bsrodrigue/rapid_shooter/tree/main/assets/textures/"
    click Textures "https://github.com/bsrodrigue/rapid_shooter/blob/main/include/textures.h"
    click Textures "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/textures.cc"
    click GameLoop "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/main.cc"
    click GameLoop "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/game.cc"
    click EntityMgr "https://github.com/bsrodrigue/rapid_shooter/blob/main/include/entities.h"
    click Rendering "https://github.com/bsrodrigue/rapid_shooter/blob/main/include/draw.h"
    click Rendering "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/draw.cc"
    click InputSystem "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/common.cc"
    click Physics "https://github.com/bsrodrigue/rapid_shooter/blob/main/include/collision.h"
    click Physics "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/collision.cc"
    click Player "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/player.cc"
    click Enemy "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/enemy.cc"
    click Projectiles "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/projectiles.cc"
    click Items "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/item.cc"
    click Items "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/item_drop.cc"
    click Inventory "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/inventory.cc"
    click Environment "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/level.cc"
    click Environment "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/wall.cc"
    click Environment "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/gate.cc"
    click Environment "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/warpzone.cc"
    click Persistence "https://github.com/bsrodrigue/rapid_shooter/blob/main/include/save.h"
    click Persistence "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/save.cc"
    click LevelEditor "https://github.com/bsrodrigue/rapid_shooter/blob/main/include/level_editor.h"
    click LevelEditor "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/level_editor.cc"
    click LevelEditor "https://github.com/bsrodrigue/rapid_shooter/blob/main/src/level_editor_utils.cc"
    click EntityEditor "https://github.com/bsrodrigue/rapid_shooter/blob/main/include/editor_entities.h"

    %% Styles
    classDef build fill:#cccccc,stroke:#333,stroke-width:1px
    classDef pipeline fill:#ffddb3,stroke:#cc6600,stroke-width:1px
    classDef data fill:#ffe4b5,stroke:#cc6600,stroke-width:1px
    classDef runtime fill:#b3d9ff,stroke:#0066cc,stroke-width:1px
    classDef editor fill:#b3ffb3,stroke:#009900,stroke-width:1px
```
