# educ8s/cpp-tetris-game-with-raylib architecture

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

- Interactive diagram: https://gitdiagram.com/educ8s/cpp-tetris-game-with-raylib
- Repository: https://github.com/educ8s/cpp-tetris-game-with-raylib

## Overview

##### Project Type & Purpose
- The project is a game application (Tetris) built in C++.
- It leverages raylib for rendering graphics, handling inputs, and playing sound, making it cross-platform (Windows, macOS, Linux).
- The purpose is not only to provide a playable Tetris game but also to serve as an educational resource for learning game development with raylib.

##### Key Components
- Game Engine / Main Loop: At the core, there's a main game loop (likely in src/main.cpp) that initializes the window, handles the game loop, and processes input and updates.
- Game Logic Modules:
- Grid: Represented by src/grid.cpp and src/grid.h that likely manages the Tetris game board.
- Game Management: src/game.cpp and src/game.h probably coordinate overall game state, collision detection, line clearing, and score management.
- Provided by src/position.cpp and src/position.h, which might handle the coordinates or movement logic of blocks.
- Multimedia Integration:
- raylib: Acts as the framework for graphics, input, and audio system integration.
- Assets: The Font directory and Sounds directory (clear.mp3, music.mp3, rotate.mp3) represent the asset resources used by the game.
- Build & Configuration:
- Makefile: Indicates build instructions.
- .code-workspace and .vscode: Indicate development environment configuration.

##### Architectural Relationships & Data Flow
- Central Game Loop (src/main.cpp) controls overall flow – initialization, updating game state, rendering, and cleanup.
- The Game component (from game.cpp/h) orchestrates behavior by interacting with:
- Grid: Maintains state of the game board.
- Blocks & Blocks Logic: Determines how Tetris pieces behave.
- Audio: Calls to raylib’s audio functions triggered upon game events (sound files in the Sounds folder).
- Input Handling: Through raylib APIs, the game listens for user input (e.g., moving or rotating blocks) and passes control to the game logic.

##### Architectural Patterns / Design Principles
- Separation of Concerns: Input, game state, rendering, and audio are separated logically, making the system easier to maintain.
- Reusability: The use of libraries like raylib abstracts the multimedia functions while the custom modules handle game-specific logic.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Domain/Game Logic Layer
    subgraph "Domain/Game Logic"
        GL["Game Loop"]:::domain
        GM["Game Manager"]:::domain
        GR["Grid Manager"]:::domain
        BM["Block Manager"]:::domain
        CM["Colors Module"]:::domain
        PM["Position Module"]:::domain
    end

    %% Multimedia Layer
    subgraph "Multimedia Layer"
        RL["raylib"]:::multimedia
    end

    %% Assets
    subgraph "Assets"
        FA["Font Assets"]:::assets
        SA["Sound Assets"]:::assets
    end

    %% Build & Configuration
    subgraph "Build & Configuration"
        MF["Makefile"]:::build
        IC["IDE Config (.vscode & main.code-workspace)"]:::build
    end

    %% Relationships
    RL -->|"Input"| GL
    GL -->|"StateUpdate"| GM
    GM -->|"GridUpdate"| GR
    GM -->|"BlockUpdate"| BM
    GM -->|"ColorInfo"| CM
    GM -->|"PosUpdate"| PM
    GL -->|"RenderCall"| RL
    GM -->|"AudioCall"| RL
    RL -->|"FontLoad"| FA
    RL -->|"SoundLoad"| SA
    MF -->|"Build"| GL
    IC -->|"DevConfig"| GL

    %% Click Events
    click GL "https://github.com/educ8s/cpp-tetris-game-with-raylib/blob/main/src/main.cpp"
    click GR "https://github.com/educ8s/cpp-tetris-game-with-raylib/blob/main/src/grid.cpp"
    click BM "https://github.com/educ8s/cpp-tetris-game-with-raylib/blob/main/src/block.cpp"
    click GM "https://github.com/educ8s/cpp-tetris-game-with-raylib/blob/main/src/game.cpp"
    click CM "https://github.com/educ8s/cpp-tetris-game-with-raylib/blob/main/src/colors.cpp"
    click PM "https://github.com/educ8s/cpp-tetris-game-with-raylib/blob/main/src/position.cpp"
    click FA "https://github.com/educ8s/cpp-tetris-game-with-raylib/tree/main/Font"
    click SA "https://github.com/educ8s/cpp-tetris-game-with-raylib/tree/main/Sounds"
    click MF "https://github.com/educ8s/cpp-tetris-game-with-raylib/tree/main/Makefile"
    click IC "https://github.com/educ8s/cpp-tetris-game-with-raylib/blob/main/.vscode"

    %% Styles
    classDef domain fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef multimedia fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef assets fill:#FFF9C4,stroke:#F57F17,stroke-width:2px;
    classDef build fill:#F0F4C3,stroke:#7CB342,stroke-width:2px;
```
