# gianlourbano/brown architecture

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

- Interactive diagram: https://gitdiagram.com/gianlourbano/brown
- Repository: https://github.com/gianlourbano/brown

## Overview

##### Project type and purpose
- This is a monolithic C++ “Brown” game engine plus a terminal‐based 2D game built on top of it.
- The engine provides an ECS framework, core services (event, time, memory, debug), graphics (ncurses via window/framebuffer), input, math, and a small custom STL.

##### Top-level file structure analysis
- Game/src/engine: the engine core.
· core: ECS (entities, components, systems)
· event, time, memory, debug, math, std utilities
· graphics (window & framebuffer)
· input
· engine.cpp/h (initialization & main loop), state manager
- Game/src/assets: game content & logic
· items & inventory
· map_gen (level/world generators)
· scripts (NPC, boss, doors, UI controllers, player, projectiles, AI)
· states (menu, room, inventory, game over)
- Game/src/main.cpp: entry point
- Makefile & ncurses dependency

##### Key insights from README
- Built with g++/make, relies on ncurses ≥ 6
- Single binary, runs in terminal
- WASD movement, T shooting, I for inventory, M for world advance

##### Components
a. Main Application Layer
- Entry Point (main.cpp)
- Makefile / Build System (g++/ncurses)
b. Engine Core (blue)
- Initialization & Game Loop
- Core Services: EventManager, Time, MemoryAllocator, Debugger
- ECS Framework
· EntityManager, ComponentManager, SystemManager
· Systems: RenderSystem, AnimationSystem, UI_System, ScriptsSystem
- Graphics Subsystem
· Window, Framebuffer (ncurses adapter)
- Input Subsystem
- Math & Custom Std Utilities
c. Game Layer (green)
- & World Generators
- Scriptable Logic: NPC, boss, door controllers, AI, healthbar, score, inventory renderer, projectile logic
- Item & Inventory Model
- State Manager & Game States
· MenuState, RoomState, InventoryState, GameOverState
d. External Dependencies (gray)
- ncurses library

##### Interactions & Data Flow
1. Build System compiles all engine + game code → executable
2. main.cpp → Engine::init() → load assets via AssetLoader
3. Engine’s Game Loop (update):
­ a. InputSubsystem polls keyboard → EventManager
­ b. EventManager dispatches to ECS / ScriptSystem / UI
­ c. ECS Framework updates all registered Systems in order (AI/scripts → animation → UI → render)
­ d. Game-specific systems (map_gen, item pickup, state transitions) run via ScriptsSystem & custom controllers
­ e. RenderSystem draws to Framebuffer/Window via ncurses
­ f. Time service enforces delta / frame rate
4. StateManager switches between game states (menu, room, inventory, game over)

##### Architectural Patterns & Principles
- Layered Architecture: Engine Core ← Game Layer ← main
- ECS for decoupled game logic
- Single Responsibility: each subsystem (graphics, input, memory) isolated
- Event-driven within the core loop
- Custom memory & std for tighter control and portability

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Build System and Entry
    Makefile["Makefile"]:::build
    Executable["Game Executable"]:::external
    maincpp["main.cpp"]:::build

    Makefile -->|compiles| Executable
    Executable -->|starts| maincpp

    click Makefile "https://github.com/gianlourbano/brown/tree/main/Game/Makefile"
    click maincpp "https://github.com/gianlourbano/brown/blob/main/Game/src/main.cpp"

    %% Engine Core
    subgraph "Engine Core"
        direction TB
        InitLoop["Initialization & Game Loop"]:::engine
        subgraph "Core Services"
            direction TB
            EventMgr["EventManager"]:::engine
            TimeSvc["Time Service"]:::engine
            MemAlloc["MemoryAllocator"]:::engine
            Debugger["Debugger"]:::engine
        end
        subgraph "ECS Framework"
            direction TB
            EntityMgr["EntityManager"]:::engine
            CompMgr["ComponentManager"]:::engine
            SysMgr["SystemManager"]:::engine
            ComponentArr["ComponentArray"]:::engine
            subgraph "Entities"
                Entity["Entity"]:::engine
                ScriptEntity["ScriptableEntity"]:::engine
            end
            subgraph "Systems"
                RenderSys["RenderSystem"]:::engine
                AnimSys["AnimationSystem"]:::engine
                UISys["UI System"]:::engine
                ScriptsSys["Scripts System"]:::engine
            end
        end
        subgraph "Graphics Subsystem"
            direction TB
            Window["Window (ncurses adapter)"]:::engine
            Framebuffer["Framebuffer"]:::engine
        end
        InputSys["Input Subsystem"]:::engine
        subgraph "Math & Std Utils"
            direction TB
            MathMod["Math Module"]:::engine
            StdUtils["Custom STL Utilities"]:::engine
        end
        StateMgrCore["StateManager"]:::engine
    end

    InitLoop --> EventMgr
    InitLoop --> TimeSvc
    InitLoop --> MemAlloc
    InitLoop --> Debugger
    InitLoop --> EntityMgr
    InitLoop --> InputSys

    EventMgr --> CompMgr
    CompMgr --> SysMgr
    SysMgr --> RenderSys
    SysMgr --> AnimSys
    SysMgr --> UISys
    SysMgr --> ScriptsSys

    RenderSys --> Window
    Window --> Framebuffer

    InputSys --> EventMgr

    TimeSvc --> InitLoop

    StateMgrCore -->|manages| InitLoop

    click InitLoop "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/engine.cpp"
    click InitLoop "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/engine.hpp"
    click EventMgr "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/core/event/event_manager.hpp"
    click TimeSvc "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/core/time/time.hpp"
    click MemAlloc "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/memory/allocator.cpp"
    click MemAlloc "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/memory/allocator.hpp"
    click Debugger "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/debug/debugger.cpp"
    click Debugger "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/debug/debugger.hpp"
    click CompMgr "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/core/ECS/component_manager.hpp"
    click EntityMgr "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/core/ECS/entity_manager.hpp"
    click SysMgr "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/core/ECS/system_manager.hpp"
    click Entity "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/core/ECS/entity/entity.hpp"
    click ScriptEntity "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/core/ECS/entity/scriptable_entity.cpp"
    click ScriptEntity "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/core/ECS/entity/scriptable_entity.hpp"
    click ComponentArr "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/core/ECS/component_array.hpp"
    click RenderSys "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/core/ECS/systems/render_system.cpp"
    click RenderSys "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/core/ECS/systems/render_system.hpp"
    click AnimSys "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/core/ECS/systems/animation_system.cpp"
    click AnimSys "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/core/ECS/systems/animation_system.hpp"
    click UISys "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/core/ECS/systems/UI_system.cpp"
    click UISys "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/core/ECS/systems/UI_system.hpp"
    click ScriptsSys "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/core/ECS/systems/scripts_system.cpp"
    click ScriptsSys "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/core/ECS/systems/scripts_system.hpp"
    click Window "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/graphics/window/window.cpp"
    click Window "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/graphics/window/window.hpp"
    click Framebuffer "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/graphics/framebuffer/framebuffer.cpp"
    click Framebuffer "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/graphics/framebuffer/framebuffer.hpp"
    click InputSys "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/input/input.cpp"
    click InputSys "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/input/input.hpp"
    click MathMod "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/math/math.cpp"
    click MathMod "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/math/math.hpp"
    click MathMod "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/math/vec2.hpp"
    click MathMod "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/math/mat.hpp"
    click StdUtils "https://github.com/gianlourbano/brown/tree/main/Game/src/engine/std/"

    %% Game Layer
    subgraph "Game Layer"
        direction TB
        AssetLoader["Asset Loader"]:::game
        subgraph "Assets"
            direction TB
            Colors["Colors & Palettes"]:::game
            Sprites["Sprites"]:::game
            Tiles["Tiles & Tilemaps"]:::game
        end
        MapGen["Map & World Generators"]:::game
        subgraph "Scripts & Controllers"
            direction TB
            ScriptLogic["Scriptable Logic"]:::game
        end
        ItemsModel["Items & Inventory Model"]:::game
        StateMgrGame["Game States & State Manager"]:::game
    end

    maincpp --> InitLoop
    InitLoop --> AssetLoader
    AssetLoader --> Colors
    AssetLoader --> Sprites
    AssetLoader --> Tiles
    AssetLoader --> MapGen
    MapGen --> ScriptLogic
    ScriptLogic --> ScriptsSys
    ScriptLogic --> ItemsModel
    ItemsModel --> ScriptsSys
    ScriptsSys --> RenderSys
    ScriptsSys --> UISys
    StateMgrGame -->|states| StateMgrCore

    click Colors "https://github.com/gianlourbano/brown/blob/main/Game/src/assets/colors/color.map"
    click Colors "https://github.com/gianlourbano/brown/blob/main/Game/src/assets/colors/palette.color"
    click Sprites "https://github.com/gianlourbano/brown/tree/main/Game/src/assets/sprites/"
    click Tiles "https://github.com/gianlourbano/brown/tree/main/Game/src/assets/tiles/"
    click MapGen "https://github.com/gianlourbano/brown/blob/main/Game/src/assets/map_gen/level_generator.cpp"
    click MapGen "https://github.com/gianlourbano/brown/blob/main/Game/src/assets/map_gen/level_generator.hpp"
    click MapGen "https://github.com/gianlourbano/brown/blob/main/Game/src/assets/map_gen/world_generator.cpp"
    click MapGen "https://github.com/gianlourbano/brown/blob/main/Game/src/assets/map_gen/world_generator.hpp"
    click ItemsModel "https://github.com/gianlourbano/brown/tree/main/Game/src/assets/items/"
    click ItemsModel "https://github.com/gianlourbano/brown/blob/main/Game/src/assets/inventory/inventory.cpp"
    click ItemsModel "https://github.com/gianlourbano/brown/blob/main/Game/src/assets/inventory/inventory.hpp"
    click ItemsModel "https://github.com/gianlourbano/brown/blob/main/Game/src/assets/inventory/item.hpp"
    click ScriptLogic "https://github.com/gianlourbano/brown/tree/main/Game/src/assets/scripts/"

    click StateMgrGame "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/state.cpp"
    click StateMgrGame "https://github.com/gianlourbano/brown/blob/main/Game/src/engine/state.hpp"
    click StateMgrGame "https://github.com/gianlourbano/brown/blob/main/Game/src/assets/states/menu_state.hpp"
    click StateMgrGame "https://github.com/gianlourbano/brown/blob/main/Game/src/assets/states/room_state.cpp"
    click StateMgrGame "https://github.com/gianlourbano/brown/blob/main/Game/src/assets/states/room_state.hpp"
    click StateMgrGame "https://github.com/gianlourbano/brown/blob/main/Game/src/assets/states/inventory_state.cpp"
    click StateMgrGame "https://github.com/gianlourbano/brown/blob/main/Game/src/assets/states/inventory_state.hpp"
    click StateMgrGame "https://github.com/gianlourbano/brown/blob/main/Game/src/assets/states/game_over.cpp"
    click StateMgrGame "https://github.com/gianlourbano/brown/blob/main/Game/src/assets/states/game_over.hpp"
    click StateMgrGame "https://github.com/gianlourbano/brown/blob/main/Game/src/assets/states/boss_room_state.hpp"

    %% External Dependencies
    ncurses["ncurses Library"]:::external
    ExternalBuild["g++, Make"]:::external

    Makefile --> ExternalBuild
    ExternalBuild --> ncurses
    ncurses --> Window

    classDef engine fill:#d0e1f9,stroke:#0872c4,color:#000
    classDef game fill:#d0f9d0,stroke:#2b8a00,color:#000
    classDef external fill:#f0f0f0,stroke:#666,color:#000
    classDef build fill:#f9e2d0,stroke:#c45f00,color:#000
```
