# feresr/super-mario-bros architecture

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

- Interactive diagram: https://gitdiagram.com/feresr/super-mario-bros
- Repository: https://github.com/feresr/super-mario-bros

## Overview

##### Project Type & Purpose
- This is a native (and wasm‐ported) 2D game written in C++ using SDL2.
- It employs an Entity-Component-System (ECS) architecture, with multiple “scenes” (Intro, Game, Editor).

##### File Structure
- Top-level build: CMakeLists.txt, cmake/*.cmake, vendor/ (SDL2 find-modules).
- Core include/ and src/ directories: ECS core, Components, Systems, Scenes, Game entry point, Asset managers.
- assets/: audio files, map layouts.
- maplayout/: level data.

##### README Insights
- Confirms no external engine, pure C++ & SDL2.
- Highlights ECS inspired by redxdev/ECS.
- Mentions three scenes and multiple systems (physics, render, sound, etc.).

##### Main Components
a. **Game Application** (Main.cpp → Game.cpp)
- Initializes SDL2 subsystems (video, audio, input).
- Loads assets via TextureManager & SoundManager.
- Creates ECS world (EntityManager, ComponentStorage, SystemManager).
- SceneManager controlling IntroScene, GameScene, EditorScene.

b. **ECS Core**
- EntityManager: tracks entity IDs.
- Component Storage: arrays/maps keyed by entity.
- SystemManager: iterates over systems each frame.

c. **Systems** (Update Loop)
- Input System → generates events/commands.
- PhysicsSystem → updates positions, collisions via AABB.
- PlayerSystem, EnemySystem, FlagSystem → game logic.
- MapSystem → tile loading & streaming from maplayout/.
- AnimationSystem → sprite frame updates.
- SoundSystem → triggers sounds via SoundManager.
- ScoreSystem → updates score UI.
- CallbackSystem, EditorSystem → hooks & editor-specific logic.

d. **Scenes**
- IntroScene → splash screen.
- GameScene → actual gameplay loop.
- EditorScene → level editor UI and interactions.

e. **Asset Managers**
- TextureManager: loads and caches SDL_Textures from disk.
- SoundManager: loads and plays WAV/MIDI via SDL_mixer.

f. **External Libraries**
- SDL2 (window, input), SDL2_image, SDL2_mixer, SDL2_ttf.

g. **Data Stores**
- assets/music/*.wav
- assets/world1-1 map files
- maplayout/ custom level definitions

##### Relationships & Data Flow
- **Startup**: Main → Game.Init → SDL_Init → AssetManagers load → ECS registered → SceneManager loads initial scene.
- **Game Loop** (each frame):
1. Poll SDL events → InputSystem → update component state
2. Update all Systems in sequence (Physics → AI → Map → Animation → Score → Sound)
4. SceneManager may swap Scenes on signals
- **Asset Access**: Systems request TextureManager/SoundManager for resources.
- **Scene ↔ ECS**: Scenes configure which Systems are active, spawn Entities with Components.

##### Architectural Patterns & Principles
- ECS decouples data (Components) from behavior (Systems).
- Scene-based state management (finite state machine for screens).
- Resource caching via manager singletons.
- Modular CMake build for cross-platform and wasm.

##### Final Checklist
- All **components** identified above included and labeled.
- Optionally, annotate with file paths (e.g., Systems correspond to include/systems/*.h & src/systems/*.cpp).

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External & Build
    subgraph "Build & External" 
        direction TB
        CMake["CMakeLists.txt"]:::external
        CMakeModules["cmake/FindSDL2*.cmake"]:::external
        Vendor["vendor/"]:::external
        SDL["SDL2, SDL2_image, SDL2_mixer, SDL2_ttf"]:::external
    end

    %% Game Application
    subgraph "Game Application" 
        direction TB
        Main["Main.cpp"]:::core
        GameApp["Game.cpp\\nGame.h"]:::core
    end

    %% Asset Managers
    subgraph "Asset Managers"
        direction TB
        TexMgr["TextureManager"]:::manager
        SoundMgr["SoundManager"]:::manager
    end

    %% ECS Core
    subgraph "ECS Core"
        direction TB
        EntityMgr["EntityManager"]:::core
        CompStorage["ComponentStorage"]:::core
        SysMgr["SystemManager"]:::core
    end

    %% Scenes
    subgraph "Scenes"
        direction TB
        Intro["IntroScene"]:::scene
        GameScene["GameScene"]:::scene
        Editor["EditorScene"]:::scene
    end

    %% Systems
    subgraph "Systems"
        direction TB
        InputSys["InputSystem"]:::system
        PhysicsSys["PhysicsSystem"]:::system
        PlayerSys["PlayerSystem"]:::system
        EnemySys["EnemySystem"]:::system
        FlagSys["FlagSystem"]:::system
        MapSys["MapSystem"]:::system
        AnimSys["AnimationSystem"]:::system
        SoundSys["SoundSystem"]:::system
        ScoreSys["ScoreSystem"]:::system
        RenderSys["RenderSystem"]:::system
        CallbackSys["CallbackSystem"]:::system
        EditorSys["EditorSystem"]:::system
        TileSys["TileSystem"]:::system
    end

    %% Data Layers
    subgraph "Data Layers"
        direction TB
        AudioAssets["assets/music/"]:::external
        TileAssets["assets/world1-1/"]:::external
        MapLayout["maplayout/"]:::external
    end

    %% Connections
    CMake --> SDL
    Main -->|initializes| GameApp
    GameApp -->|loads| SDL
    GameApp -->|uses| TexMgr
    GameApp -->|uses| SoundMgr
    GameApp -->|creates| EntityMgr
    GameApp -->|creates| CompStorage
    GameApp -->|creates| SysMgr
    GameApp -->|initializes| Intro
    SceneManager["SceneManager"]:::core
    GameApp --> SceneManager
    SceneManager --> Intro
    SceneManager --> GameScene
    SceneManager --> Editor

    %% Game Loop Flow
    MainLoop["Game Loop"]:::core
    SceneManager --> MainLoop
    MainLoop --> InputSys
    InputSys -->|events| CompStorage
    MainLoop --> PhysicsSys
    PhysicsSys -->|updates AABB| CompStorage
    MainLoop --> PlayerSys
    MainLoop --> EnemySys
    MainLoop --> FlagSys
    MainLoop --> MapSys
    MainLoop --> AnimSys
    MainLoop --> ScoreSys
    MainLoop --> SoundSys
    MainLoop --> RenderSys
    MainLoop --> CallbackSys
    MainLoop --> EditorSys
    MainLoop --> TileSys

    %% Asset Requests
    PhysicsSys -->|collision data| AABBComp["AABB Component"]:::core
    RenderSys -->|draw| TexMgr
    SoundSys -->|play| SoundMgr
    MapSys -->|load| MapLayout
    TexMgr --> AudioAssets
    SoundMgr --> AudioAssets
    TexMgr --> TileAssets

    %% Click Events
    click Main "https://github.com/feresr/super-mario-bros/blob/master/src/Main.cpp"
    click GameApp "https://github.com/feresr/super-mario-bros/blob/master/src/Game.cpp"
    click GameApp "https://github.com/feresr/super-mario-bros/blob/master/include/Game.h"
    click ecs "https://github.com/feresr/super-mario-bros/blob/master/include/ecs/ecs.h"
    click AABBComp "https://github.com/feresr/super-mario-bros/blob/master/include/AABB.h"
    click AABBComp "https://github.com/feresr/super-mario-bros/blob/master/src/AABB.cpp"
    click Components "https://github.com/feresr/super-mario-bros/blob/master/include/Components.h"
    click Constants "https://github.com/feresr/super-mario-bros/blob/master/include/Constants.h"
    click TileType "https://github.com/feresr/super-mario-bros/blob/master/include/TileType.h"
    click SceneBase "https://github.com/feresr/super-mario-bros/blob/master/include/scenes/Scene.h"
    click Intro "https://github.com/feresr/super-mario-bros/blob/master/include/scenes/IntroScene.h"
    click GameScene "https://github.com/feresr/super-mario-bros/blob/master/include/scenes/GameScene.h"
    click Editor "https://github.com/feresr/super-mario-bros/blob/master/include/scenes/EditorScene.h"
    click Intro "https://github.com/feresr/super-mario-bros/blob/master/src/scenes/IntroScene.cpp"
    click GameScene "https://github.com/feresr/super-mario-bros/blob/master/src/scenes/GameScene.cpp"
    click Editor "https://github.com/feresr/super-mario-bros/blob/master/src/scenes/EditorScene.cpp"
    click AnimSys "https://github.com/feresr/super-mario-bros/blob/master/include/systems/AnimationSystem.h"
    click AnimSys "https://github.com/feresr/super-mario-bros/blob/master/src/systems/AnimationSystem.cpp"
    click CallbackSys "https://github.com/feresr/super-mario-bros/blob/master/include/systems/CallbackSystem.h"
    click CallbackSys "https://github.com/feresr/super-mario-bros/blob/master/src/systems/CallbackSystem.cpp"
    click EditorSys "https://github.com/feresr/super-mario-bros/blob/master/include/systems/EditorSystem.h"
    click EditorSys "https://github.com/feresr/super-mario-bros/blob/master/src/systems/EditorSystem.cpp"
    click EnemySys "https://github.com/feresr/super-mario-bros/blob/master/include/systems/EnemySystem.h"
    click EnemySys "https://github.com/feresr/super-mario-bros/blob/master/src/systems/EnemySystem.cpp"
    click FlagSys "https://github.com/feresr/super-mario-bros/blob/master/include/systems/FlagSystem.h"
    click FlagSys "https://github.com/feresr/super-mario-bros/blob/master/src/systems/FlagSystem.cpp"
    click MapSys "https://github.com/feresr/super-mario-bros/blob/master/include/systems/MapSystem.h"
    click MapSys "https://github.com/feresr/super-mario-bros/blob/master/src/systems/MapSystem.cpp"
    click PhysicsSys "https://github.com/feresr/super-mario-bros/blob/master/include/systems/PhysicsSystem.h"
    click PhysicsSys "https://github.com/feresr/super-mario-bros/blob/master/src/systems/PhysicsSystem.cpp"
    click PlayerSys "https://github.com/feresr/super-mario-bros/blob/master/include/systems/PlayerSystem.h"
    click PlayerSys "https://github.com/feresr/super-mario-bros/blob/master/src/systems/PlayerSystem.cpp"
    click RenderSys "https://github.com/feresr/super-mario-bros/blob/master/include/systems/RenderSystem.h"
    click RenderSys "https://github.com/feresr/super-mario-bros/blob/master/src/systems/RenderSystem.cpp"
    click ScoreSys "https://github.com/feresr/super-mario-bros/blob/master/include/systems/ScoreSystem.h"
    click ScoreSys "https://github.com/feresr/super-mario-bros/blob/master/src/systems/ScoreSystem.cpp"
    click SoundSys "https://github.com/feresr/super-mario-bros/blob/master/include/systems/SoundSystem.h"
    click SoundSys "https://github.com/feresr/super-mario-bros/blob/master/src/systems/SoundSystem.cpp"
    click TileSys "https://github.com/feresr/super-mario-bros/blob/master/include/systems/TileSystem.h"
    click TileSys "https://github.com/feresr/super-mario-bros/blob/master/src/systems/TileSystem.cpp"
    click TexMgr "https://github.com/feresr/super-mario-bros/blob/master/include/TextureManager.h"
    click TexMgr "https://github.com/feresr/super-mario-bros/blob/master/src/TextureManager.cpp"
    click SoundMgr "https://github.com/feresr/super-mario-bros/blob/master/include/SoundManger.h"
    click SoundMgr "https://github.com/feresr/super-mario-bros/blob/master/src/SoundManager.cpp"
    click CMake "https://github.com/feresr/super-mario-bros/blob/master/CMakeLists.txt"
    click CMakeModules "https://github.com/feresr/super-mario-bros/blob/master/cmake/FindSDL2.cmake"
    click Vendor "https://github.com/feresr/super-mario-bros/tree/master/vendor/"
    click SDL "https://github.com/feresr/super-mario-bros/blob/master/cmake/FindSDL2_image.cmake"
    click SDL "https://github.com/feresr/super-mario-bros/blob/master/cmake/FindSDL2_mixer.cmake"
    click SDL "https://github.com/feresr/super-mario-bros/blob/master/cmake/FindSDL2_ttf.cmake"

    %% Styles
    classDef core fill:#D0E6FF,stroke:#0366D6
    classDef system fill:#DFFFE0,stroke:#28A745
    classDef scene fill:#FFE6CC,stroke:#D96400
    classDef manager fill:#EBD0FF,stroke:#6F42C1
    classDef external fill:#F0F0F0,stroke:#6A737D;background:#F0F0F0
    class MainLoop core
    class SceneManager core
    class ecs core
    class AABBComp core
    class Components core
    class Constants core
    class TileType core
    class SceneBase scene
```
