# ali5917/captale architecture

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

- Interactive diagram: https://gitdiagram.com/ali5917/captale
- Repository: https://github.com/ali5917/captale

## Overview

##### Project type and purpose
- This is a native C++ object-oriented desktop game (“captale”) composed of multiple mini-games or “cities” (atmCity, carCity, earnCity, etc.), built as part of an OOP course.
- Key activities include initializing the game engine, loading assets (graphics, audio, fonts), driving the main game loop, switching between scenes (cities), handling input, timing, and rendering.

##### File structure
- Top level:
- main.cpp — entry point and core game loop
- headers/ — all class and module interface definitions (scene controllers, timer, message, settings, sprites)
- assets/ — grouped by scene, containing images, audio, fonts, and data files
- Makefile and .gitignore for build and version control
- Pattern: a central “Engine” or “GameManager” in main.cpp that delegates to per-scene classes (ATM City, Car City, etc.). Scenes implement a common interface (in headers/*.h). Asset loading is likely centralized or per-scene.

##### README
- Confirms it’s a game for an OOP project, no further architectural notes. We infer a modular design: core engine + pluggable scenes + shared utilities.

a. Main components
- Game Engine / GameManager (in main.cpp)
- Scene Manager (factory or controller that switches between scenes)
- Scene modules: ATM City, Car City, Custom City, Earn City, Energy City, Pong City, Space Shooter, Lobby, GameOver, Intro
- Asset Manager (loads images, audio, fonts, CSV data)
- Input Handler (keyboard/mouse events)
- Timer / Custom Timer
- Message Bus / Event System
- Settings Manager
- Sprite / Renderer subsystem
- External resource store (assets folder on disk)

b. Relationships and interactions
- Game Engine invokes Scene Manager each frame
- Scene Manager forwards update() and render() calls to the active Scene Module
- Scene Module requests assets from Asset Manager, issues playSound() or drawSprite()
- Input Handler feeds events into Message Bus or directly to the active Scene
- Timer triggers time-based events or scene transitions
- Settings Manager provides configuration (screen size, volume) to all subsystems
- Message Bus allows decoupled communication (e.g., a collision event in Space Shooter is broadcast)

c. Architectural patterns / design principles
- Strategy / Polymorphic Scene pattern: each city implements a common Scene interface
- Singleton or centralized Asset Manager and Settings Manager
- Event-driven design via Message Bus for loose coupling
- Modular folder structure: headers define interfaces, assets are externalized

d. Relevant technologies and frameworks
- Standard C++17 (or earlier)
- Makefile build system
- Custom rendering (probably SDL or OpenGL though not shown, inferred by OOP game class headers)
- CSV parsing in earnCity, WAV/MP3 audio files

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Engine and Managers
    subgraph "Core Engine"
        GE["Game Engine / GameManager"]:::core
        SM["Scene Manager"]:::core
        AM["Asset Manager"]:::core
        IH["Input Handler"]:::core
        TM["Timer / Custom Timer"]:::core
        MB["Message Bus / Event System"]:::core
        SGM["Settings Manager"]:::core
        RD["Renderer / Sprite Subsystem"]:::core
    end

    %% Scenes
    subgraph "Scene Modules"
        ATM["ATM City Scene"]:::scene
        CAR["Car City Scene"]:::scene
        CUSTOM["Custom City Scene"]:::scene
        EARN["Earn City Scene"]:::scene
        ENERGY["Energy City Scene"]:::scene
        PONG["Pong City Scene"]:::scene
        SPACE["Space Shooter Scene"]:::scene
        LOBBY["Lobby Scene"]:::scene
    end

    %% External Resources
    ER["Assets (External Resources)"]:::external

    %% Core Engine Flow
    GE -->|"delegates each frame"| SM
    SM -->|"update()/render() calls"| ATM
    SM -->|"update()/render() calls"| CAR
    SM -->|"update()/render() calls"| CUSTOM
    SM -->|"update()/render() calls"| EARN
    SM -->|"update()/render() calls"| ENERGY
    SM -->|"update()/render() calls"| PONG
    SM -->|"update()/render() calls"| SPACE
    SM -->|"update()/render() calls"| LOBBY

    %% Asset Management
    ATM -->|"requests assets"| AM
    CAR -->|"requests assets"| AM
    CUSTOM -->|"requests assets"| AM
    EARN -->|"requests assets"| AM
    ENERGY -->|"requests assets"| AM
    PONG -->|"requests assets"| AM
    SPACE -->|"requests assets"| AM
    LOBBY -->|"requests assets"| AM
    AM -->|"loads data"| ER

    %% Input and Events
    GE -->|"processInput()"| IH
    IH -->|"sends events"| MB
    TM -->|"tick() events"| MB
    MB -.->|"broadcast events"| ATM
    MB -.->|"broadcast events"| CAR
    MB -.->|"broadcast events"| CUSTOM
    MB -.->|"broadcast events"| EARN
    MB -.->|"broadcast events"| ENERGY
    MB -.->|"broadcast events"| PONG
    MB -.->|"broadcast events"| SPACE
    MB -.->|"broadcast events"| LOBBY

    %% Rendering and Settings
    GE -->|"calls render()"| RD
    ATM -->|"drawSprite()/playSound()"| RD
    CAR -->|"drawSprite()/playSound()"| RD
    CUSTOM -->|"drawSprite()/playSound()"| RD
    EARN -->|"drawSprite()/playSound()"| RD
    ENERGY -->|"drawSprite()/playSound()"| RD
    PONG -->|"drawSprite()/playSound()"| RD
    SPACE -->|"drawSprite()/playSound()"| RD
    LOBBY -->|"drawSprite()/playSound()"| RD

    SGM -->|"provides config"| GE
    SGM -->|"provides config"| AM
    SGM -->|"provides config"| RD
    SGM -->|"provides config"| IH
    SGM -->|"provides config"| TM

    %% Click Events
    click GE "https://github.com/ali5917/captale/blob/main/main.cpp"
    click SM "https://github.com/ali5917/captale/blob/main/headers/cap.h"
    click ATM "https://github.com/ali5917/captale/blob/main/headers/atmCity.h"
    click ATM "https://github.com/ali5917/captale/tree/main/assets/atmCity/"
    click CAR "https://github.com/ali5917/captale/blob/main/headers/carCity.h"
    click CAR "https://github.com/ali5917/captale/tree/main/assets/carCity/"
    click CUSTOM "https://github.com/ali5917/captale/blob/main/headers/customCity.h"
    click CUSTOM "https://github.com/ali5917/captale/tree/main/assets/customCity/"
    click EARN "https://github.com/ali5917/captale/blob/main/headers/earningCity.h"
    click EARN "https://github.com/ali5917/captale/tree/main/assets/earnCity/"
    click ENERGY "https://github.com/ali5917/captale/blob/main/headers/energyCity.h"
    click ENERGY "https://github.com/ali5917/captale/tree/main/assets/energyCity/"
    click PONG "https://github.com/ali5917/captale/blob/main/headers/pongCity.h"
    click PONG "https://github.com/ali5917/captale/tree/main/assets/pongCity/"
    click SPACE "https://github.com/ali5917/captale/blob/main/headers/spaceShooter.h"
    click SPACE "https://github.com/ali5917/captale/blob/main/headers/spaceShooterSettings.h"
    click SPACE "https://github.com/ali5917/captale/tree/main/assets/spaceShooter/"
    click LOBBY "https://github.com/ali5917/captale/blob/main/headers/lobby.h"
    click LOBBY "https://github.com/ali5917/captale/tree/main/assets/lobby/"
    click MB "https://github.com/ali5917/captale/blob/main/headers/message.h"
    click TM "https://github.com/ali5917/captale/blob/main/headers/custom_timer.h"
    click SGM "https://github.com/ali5917/captale/blob/main/headers/settings.h"
    click RD "https://github.com/ali5917/captale/blob/main/headers/sprites.h"
    click ER "https://github.com/ali5917/captale/tree/main/assets/"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef scene fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
    classDef dashed stroke:#f66,stroke-dasharray:5 5;
```
