# santiagoruiz1314/arkanoid architecture

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

- Interactive diagram: https://gitdiagram.com/santiagoruiz1314/arkanoid
- Repository: https://github.com/santiagoruiz1314/arkanoid

## Overview

##### Main Components
- Game Core: This central module encompasses overall game state management, game state changes (start, pause, game over, win states), benchmarking routines, and high-level game logic (found in Assets/Scripts/Game).
- Input Management: Capture and process different devices’ inputs (keyboard, mouse, touch). This includes components such as PaddleInputData and dedicated input processing systems.
- Entity Systems (DOTS/ECS-based):
- Ball Systems – managing ball behaviors including spawning, collision resolution, ball loss, speed increases, etc.
- Block Systems – handling block spawning, hit detection, destruction, and the associated events.
- Paddle Systems – managing paddle movement, input processing, collision interactions, and death states.
- Laser and Power-ups Systems – cover power-up logic (Catch, Enlarge, Laser, etc.) and laser firing mechanisms.
- Audio Systems – manage sound playback for events such as ball loss, hits, power-up notifications, etc.
- Rendering Systems – utilizing specific shaders (e.g. UnlitST shader) and texture animations to achieve a retro look.
- Level Management – handling level loading, despawning, settings, and spatial configurations.
- UI Systems: Leveraging Unity’s UI scripts to show game panels, title screens, and HUD elements.
- Utilities and Helpers: Systems in Assets/Scripts/Utils that deal with cross-cutting concerns like math, refresh-rate adjustments, and general game logic utilities.

##### Relationships and Interactions
- Data flows in a DOTS/ECS architecture tend to be unidirectional, with clearly defined systems processing data from entities (components) in parallel.
- Inputs (from keyboard, mouse, or touch) are fed into the Paddle Input and other user input systems. This input alters component states which trigger corresponding behaviors (like moving the paddle or starting ball motion).
- The collisions and interactions (ball hitting blocks, paddle ball link, laser interactions) use DOTS Physics to detect and propagate events between relevant systems (e.g., BallCollisionResolvingSystem outputs events that the Blocks’ systems then consume).
- Rendering is decoupled from game logic: Although the ECS data is adjusted by various systems, the Rendering Systems retrieve the latest data (from components like MaterialColorData) to refresh the on-screen visuals.
- Audio systems subscribe to game events (ball lost, power-up received, level start, etc.) and trigger sound playback accordingly.
- The Level Management system coordinates the orchestration of game entities per level, ensuring the right prefabs (from Assets/Prefabs) are instantiated and managed.

##### Architectural Patterns and Design Principles
- Data-Oriented Programming: The project is structured to minimize random memory access by structuring components solely on “data” (components) with many systems iterating over them.
- Event-Driven Architecture: Many of the interactions (e.g., hit events, system triggers) are managed by posting events (found in Assets/Scripts/Events) that drive behavior in other systems.
- Separation of Concerns: While all systems work as part of a unified ECS setup, groups (e.g., Ball, Blocks, UI, Audio) are clearly defined in separate folders, indicating their focused responsibilities.
- Multithreading and Performance Optimization: With Jobs and Burst Compilation, the design emphasizes parallel processing and low-level performance tuning.

##### Including Relevant Technologies
- DOTS/ECS, Jobs System, Burst Compiler for simulation.
- URP and ShaderLab/HLSL for rendering.
- DOTS Physics for collision detection.
- C# as the primary programming language.
- External libraries or services if applicable (although the primary focus is on internal DOTS components).

- Ball, Blocks, Paddle, Laser, Power-Ups, and Level Systems.
- “Input Systems” feeding into “Game Core.”
- “DOTS Physics” interconnected with Ball/Block/Paddle systems.
- “Rendering Layer (URP & Shaders)” linked from the Game Core.
- “Audio Systems” receiving event-driven triggers from Game Systems.
- “UI Systems” from the game state changes and input feedback.
- “Utility Systems” supporting various subsystems.
- Optionally, demarcate the Benchmark Mode as interfacing with multiple systems to stress test performance.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    subgraph "Input Layer"
        IN["Input Systems"]:::input
    end

    %% Game Logic Layer
    subgraph "Game Logic Layer"
        GC["Game Core (ECS Based)"]:::core
        IM["Input Management"]:::input
        PI["PaddleInput"]:::input
        BS["Ball Systems"]:::ecs
        BLS["Block Systems"]:::ecs
        PS["Paddle Systems"]:::ecs
        LS["Laser Systems"]:::ecs
        PUS["Power-Ups Systems"]:::ecs
        LM["Level Management"]:::level
        PREF["Prefabs"]:::level
        UT["Utilities & Helpers"]:::utils
    end

    %% Physics & Collision Layer
    subgraph "Physics & Collision"
        DP["DOTS Physics"]:::physics
    end

    %% Rendering Layer
    subgraph "Rendering Layer"
        RS["Rendering Systems"]:::render
    end

    %% Audio & UI Layer
    subgraph "Audio & UI"
        AU["Audio Systems"]:::audio
        UI["UI Systems"]:::ui
    end

    %% Connections between Layers
    IN -->|"inputs"| IM
    IM -->|"provides"| PI
    PI --> PS

    GC -->|"governs"| BS
    GC -->|"governs"| BLS
    GC -->|"governs"| PS
    GC -->|"governs"| LS
    GC -->|"governs"| PUS
    GC -->|"governs"| LM

    LM -->|"instantiates"| PREF

    %% Interactions with DOTS Physics
    BS -->|"collision_events"| DP
    BLS -->|"collision_events"| DP
    PS -->|"collision_events"| DP
    LS -->|"physics_signals"| DP
    PUS -->|"physics_signals"| DP

    %% Physics outputs to Rendering, Audio and UI
    DP -->|"state_updates"| RS
    DP -->|"triggers"| AU
    DP -->|"triggers"| UI

    %% Direct Game Core influence on Rendering
    GC -->|"state_updates"| RS

    %% Utility influence (supporting various subsystems)
    UT --- BS
    UT --- BLS
    UT --- PS
    UT --- LS
    UT --- PUS
    UT --- LM

    %% Click Events
    click GC "https://github.com/santiagoruiz1314/arkanoid/tree/main/Assets/Scripts/Game"
    click IM "https://github.com/santiagoruiz1314/arkanoid/tree/main/Assets/Scripts/Game/Components"
    click PI "https://github.com/santiagoruiz1314/arkanoid/tree/main/Assets/Scripts/Paddle/Components"
    click BS "https://github.com/santiagoruiz1314/arkanoid/tree/main/Assets/Scripts/Ball"
    click BLS "https://github.com/santiagoruiz1314/arkanoid/tree/main/Assets/Scripts/Blocks"
    click PS "https://github.com/santiagoruiz1314/arkanoid/tree/main/Assets/Scripts/Paddle"
    click LS "https://github.com/santiagoruiz1314/arkanoid/tree/main/Assets/Scripts/Laser"
    click PUS "https://github.com/santiagoruiz1314/arkanoid/tree/main/Assets/Scripts/PowerUps"
    click AU "https://github.com/santiagoruiz1314/arkanoid/tree/main/Assets/Scripts/Audio"
    click RS "https://github.com/santiagoruiz1314/arkanoid/tree/main/Assets/Scripts/Rendering"
    click LM "https://github.com/santiagoruiz1314/arkanoid/tree/main/Assets/Scripts/Level"
    click PREF "https://github.com/santiagoruiz1314/arkanoid/tree/main/Assets/Prefabs"
    click UI "https://github.com/santiagoruiz1314/arkanoid/tree/main/Assets/Scripts/UI"
    click UT "https://github.com/santiagoruiz1314/arkanoid/tree/main/Assets/Scripts/Utils"

    %% Styles
    classDef core fill:#AED6F1,stroke:#5DADE2,stroke-width:2px;
    classDef ecs fill:#D4E6F1,stroke:#85C1E9,stroke-width:2px;
    classDef level fill:#F9E79F,stroke:#F4D03F,stroke-width:2px;
    classDef physics fill:#ABEBC6,stroke:#58D68D,stroke-width:2px;
    classDef render fill:#F5B7B1,stroke:#EC7063,stroke-width:2px;
    classDef audio fill:#F9E79F,stroke:#F7DC6F,stroke-width:2px;
    classDef ui fill:#E8DAEF,stroke:#AF7AC5,stroke-width:2px;
    classDef input fill:#FAD7A0,stroke:#F5B041,stroke-width:2px;
    classDef utils fill:#D2B4DE,stroke:#BB8FCE,stroke-width:2px;
```
