# idomoz/bloonstd architecture

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

- Interactive diagram: https://gitdiagram.com/idomoz/bloonstd
- Repository: https://github.com/idomoz/bloonstd

## Overview

##### Project Type and Core Purpose
- The project is a game that implements a 2D tower defense, relying on an Entity–Component–System (ECS) architecture.
- The README outlines game assets, level data, and dependencies on SDL2 and Boost, informing you that the rendering, input, physics, and game logic are tightly integrated through the ECS.

##### Analyzing the File Structure
- Top-Level Organization:
– Scripts folder: Contains Python scripts to convert levels, maps, and tower data. These indicate preprocessing tools that generate or adapt the assets for game use.
– Src folder: The core C++ source code is located here.
– There is also a CMakeLists.txt for build configuration.
- Inside the src folder:
– Game core files (Game.cpp, Game.h, main.cpp) establish the main loop and central game management.
– Components folder: Contains individual component header files (e.g., Position, Velocity, AttackSpeed) defining attributes for the ECS.
– Systems folder: Contains implementations of various game systems (e.g., BloonsSpawnSystem, CollisionSystem, MovementSystem, RenderSystem) that process entities and their components.
– Other support files (Entity.cpp/h, GameData.cpp/h, Physics.cpp/h, System.cpp/h) that integrate the ECS and game logic.

##### Key Components
a. Core Game Engine:
– Main game loop: Represented by main.cpp and Game.cpp.
– CMake build system: Indicate CMakeLists.txt as the project build configuration.
b. Entity–Component–System Architecture:
– Entities: Represent game objects, managed in files like Entity.cpp/h.
– Components: Represented by files in src/components (e.g., Position, Velocity, AttackSpeed, etc.). They define the attributes of each entity.
c. Assets and Data Management:
– Note the existence of scripts that convert and preprocess these assets.
d. External Dependencies:
– SDL2 and its auxiliary libraries (SDL2_image, SDL2_gfx, SDL2_ttf) for rendering, input, and font caching (notably, SDL_FontCache).
– Boost library: Used to support additional functionalities.
– Illustrate how these libraries interface with the game engine.

##### Relationships and Interactions
– From the main game loop to the various systems.
– Between systems and the entity/component storage (the ECS core).
– The RenderSystem’s interaction with SDL2 libraries.
– The asset loader (likely within LoadLevelSystem or a dedicated resource manager) connecting game level data and graphics assets.
- Preprocessing scripts (convert_levels.py, convert_maps.py, convert_towers.py) as external steps to generate or modify asset files, which are then consumed by the game at runtime.

##### Architectural Patterns and Design Principles
- ECS pattern:
– Separate components (data) from systems (logic) and entities (game objects).
- Modular design:
– Systems are designed to handle separate aspects such as rendering, movement, collision, damage, event handling, etc.
- Use of CMake suggests cross-platform build modularity.
- Integration of SDL2 indicates reliance on event-driven programming for user input and rendering.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Game Engine Subgraph
    subgraph "Game Engine"
        GameLoop["Main Game Loop (Game.cpp, main.cpp)"]:::engine
        CMake["Build Configuration (CMakeLists.txt)"]:::engine
    end

    %% ECS Architecture Subgraph
    subgraph "ECS Architecture"
        Entities["Entities (Entity.cpp/h)"]:::ecs
        Components["Components (src/components)"]:::ecs
        Systems["Systems (src/systems)"]:::ecs
    end

    %% Asset Management Subgraph
    subgraph "Asset Management"
        Assets["Assets & Game Data (assets)"]:::assets
        Preprocessing["Asset Preprocessing Scripts (scripts)"]:::assets
    end

    %% External Dependencies Subgraph
    subgraph "External Dependencies"
        SDL["SDL2 & SDL_FontCache (src/SDL_FontCache.c/h)"]:::external
        Boost["Boost Library"]:::external
    end

    %% Relationships
    GameLoop -->|"initializes"| Systems
    GameLoop -->|"manages"| Entities
    GameLoop -->|"loads"| Assets
    Systems -->|"updates"| Entities
    Systems -->|"processes"| Components
    Systems -->|"renders via"| SDL
    Systems -->|"utilizes"| Boost
    Preprocessing -->|"generates"| Assets

    %% Click Events
    click GameLoop "https://github.com/idomoz/bloonstd/blob/master/src/main.cpp"
    click CMake "https://github.com/idomoz/bloonstd/blob/master/CMakeLists.txt"
    click Entities "https://github.com/idomoz/bloonstd/blob/master/src/Entity.cpp"
    click Components "https://github.com/idomoz/bloonstd/tree/master/src/components"
    click Systems "https://github.com/idomoz/bloonstd/tree/master/src/systems"
    click Assets "https://github.com/idomoz/bloonstd/tree/master/assets"
    click Preprocessing "https://github.com/idomoz/bloonstd/tree/master/scripts"
    click SDL "https://github.com/idomoz/bloonstd/blob/master/src/SDL_FontCache.c"

    %% Styles
    classDef engine fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef ecs fill:#ccffcc,stroke:#00cc00,stroke-width:2px;
    classDef assets fill:#ccccff,stroke:#0000cc,stroke-width:2px;
    classDef external fill:#ffffcc,stroke:#cccc00,stroke-width:2px;
```
