# bbugday/tetris architecture

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

- Interactive diagram: https://gitdiagram.com/bbugday/tetris
- Repository: https://github.com/bbugday/tetris

## Overview

##### Main Components
- Application / Entry Point: Highlight the main entry (from Main.cpp) where the Application class in Application.cpp is initialized. This component is responsible for setting up the game window and managing the overall game loop.
- Game Core: Indicate the Game module (Game.cpp/Game.h) that contains the central logic for handling gameplay and the game loop.
- State Management: Mark the State components such as MenuState, GameState, EndState, and the StateStack. These represent the different screens or modes of the game, and the state stack pattern is used to manage transitions.
- Resource Handling: Include the ResourceHandling module (ResourceHolder and ResourceIdentifiers) which is used to load and manage game assets like textures, fonts, and other resources needed for rendering.
- Piece Handling: Represent the Piece component (Piece.h) that likely encapsulates the Tetris pieces’ logic.

##### Relationships and Interactions
- That the Main/Entry Point initializes the Application.
- The Application is responsible for creating the window (via SFML) and initializing the Game Core.
- The piece logic, likely used from within the GameState, should be depicted as part of the game loop that computes moves, piece rotations, and collision detections.

##### Architectural Patterns and Design Principles
- Separation between the game’s core logic and resource management. This separation supports decoupling and better scalability.
- Game loop as a central design element that continuously updates states and renders using SFML.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Application Layer
    M["Main/Entry"]:::entry
    APP["Application"]:::app

    %% Game Core Layer
    GC["Game Core"]:::game
    PH["Piece Handling"]:::piece

    %% State Management
    subgraph "State Management"
        SS["State Stack"]:::state
        MS["MenuState"]:::state
        GS["GameState"]:::state
        ES["EndState"]:::state
    end

    %% Resource Handling
    RH["Resource Handling"]:::resource

    %% External Dependencies
    SFML["SFML"]:::external

    %% Connections
    M -->|"initializes"| APP
    APP -->|"creates"| GC
    APP -->|"uses"| SFML
    GC -->|"manages"| SS
    GC -->|"uses_piece_logic"| PH
    GC -->|"renders_with"| SFML
    RH -->|"provides_assets_to"| GC
    RH -->|"provides_assets_to"| MS
    RH -->|"provides_assets_to"| GS
    RH -->|"provides_assets_to"| ES
    SS -->|"transitions_to"| MS
    SS -->|"transitions_to"| GS
    SS -->|"transitions_to"| ES

    %% Click Events
    click M "https://github.com/bbugday/tetris/blob/main/tetris/src/Main.cpp"
    click APP "https://github.com/bbugday/tetris/blob/main/tetris/src/Application.cpp"
    click GC "https://github.com/bbugday/tetris/blob/main/tetris/src/Game.cpp"
    click PH "https://github.com/bbugday/tetris/blob/main/tetris/src/Piece.h"
    click MS "https://github.com/bbugday/tetris/blob/main/tetris/src/State/MenuState.cpp"
    click GS "https://github.com/bbugday/tetris/blob/main/tetris/src/State/GameState.cpp"
    click ES "https://github.com/bbugday/tetris/blob/main/tetris/src/State/EndState.cpp"
    click SS "https://github.com/bbugday/tetris/blob/main/tetris/src/State/StateStack.cpp"
    click RH "https://github.com/bbugday/tetris/blob/main/tetris/src/ResourceHandling/ResourceHolder.h"
    click SFML "https://github.com/bbugday/tetris/blob/main/Dependencies/SFML-2.5.1"

    %% Styles
    classDef entry fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef app fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef game fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef state fill:#FFFF99,stroke:#333,stroke-width:2px;
    classDef resource fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef external fill:#FFA500,stroke:#333,stroke-width:2px;
    classDef piece fill:#F0E68C,stroke:#333,stroke-width:2px;
```
