# orurh/c_tetris architecture

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

- Interactive diagram: https://gitdiagram.com/orurh/c_tetris
- Repository: https://github.com/orurh/c_tetris

## Overview

##### Project Type and Purpose
- The project is an implementation of the Tetris game with a command-line interface (CLI). The README and file structure confirm that the core game logic (such as handling Tetris gameplay and FSM states) is separated from the GUI, which is implemented using CLI components.
- The README highlights game controls, a detailed FSM (Finite State Machine) with states like INIT, ACTIVE, PAUSE, SPAWN, GAMEOVER, and DESTROYED, and usage commands. This indicates that the central purpose is to manage game states and user inputs.

##### File Structure Analysis
- Key directories:
- tetris/: Contains core game logic files (api.c, figures.c, s21_tetris.c, etc.) that implement the engine and FSM.
- gui/cli/: Holds CLI-specific files (interface.c/h, main.c, userinput.c) that serve as the view layer for user interaction.
- test/: Contains unit tests.
- Other files (Makefile, Doxyfile, and suppression files) indicate build configuration, documentation generation, and memory analysis.
- The structure shows a clear separation between game logic (tetris/) and the user interface (gui/cli/).

##### README Insights
- It also explains the Makefile commands, which can help in understanding how the project is built, tested, and deployed.

a. Main Components:
- Game Engine (Tetris Core): Represented by the "tetris" module. This component handles the game logic, the FSM, and key functions like generating and moving Tetris figures.
- CLI Interface: Represented by the "gui/cli" module. This includes the main entry point and modules that handle user input and output.
- Testing Module: Represented by the "test" directory. This component verifies the game logic and behavior.
- Build and Deployment: The Makefile and associated files (e.g., suppression files, Doxyfile) are part of the build process, documentation, and debugging.

b. Relationships and Interactions:
- The CLI Interface interacts with the Game Engine by sending user commands (like start, pause, move, rotate) to the Tetris engine.
- Testing modules simulate interactions and validate behavior between these layers.
- The build system (Makefile) compiles both modules and connects them for deployment in the bin/ folder.

c. Architectural Patterns and Design Principles:
- Separation of Concerns: The game logic and UI are in distinct modules. Clear boundaries are maintained between user input (CLI) and game state manipulation.
- Finite State Machine Pattern: Central to game logic, ensuring robust transitions between states (INIT, ACTIVE, PAUSE, SPAWN, GAMEOVER, DESTROYED).
- Modular Design: Independent components that can be built, tested, and maintained separately.

d. Relevant Technologies and Frameworks:
- C programming language for core logic and CLI.
- Makefile for build automation.
- Doxygen (Doxyfile) for documentation.
- Valgrind suppression files for memory leak checks.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer: CLI Interface"
        CLI["CLI Interface"]:::cli
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer: Game Engine"
        ENGINE["Tetris Core (Game Engine)"]:::engine
        subgraph "Finite State Machine (FSM)"
            INIT["INIT"]:::fsm
            ACTIVE["ACTIVE"]:::fsm
            PAUSE["PAUSE"]:::fsm
            SPAWN["SPAWN"]:::fsm
            GAMEOVER["GAMEOVER"]:::fsm
            DESTROYED["DESTROYED"]:::fsm
            INIT -->|"toActive"| ACTIVE
            ACTIVE -->|"toPause"| PAUSE
            PAUSE -->|"toActive"| ACTIVE
            ACTIVE -->|"toSpawn"| SPAWN
            ACTIVE -->|"toGameover"| GAMEOVER
            GAMEOVER -->|"toDestroyed"| DESTROYED
        end
        FSM_DEF["FSM Definition"]:::fsmNote
        ENGINE -->|"includes"| FSM_DEF
    end

    %% Testing Suite
    subgraph "Testing Suite"
        TEST["Unit Tests"]:::test
    end

    %% Build/Deployment Tools
    subgraph "Build/Deployment Tools"
        MAKEFILE["Makefile"]:::build
        DOXYFILE["Doxyfile"]:::build
        SUPPRESS["Suppressions"]:::build
    end

    %% Connections between layers
    CLI -->|"userCommand()"| ENGINE
    ENGINE -->|"updateDisplay()"| CLI
    TEST -->|"validate()"| ENGINE
    MAKEFILE -->|"build"| ENGINE
    MAKEFILE -->|"build"| CLI
    MAKEFILE -->|"buildTest"| TEST

    %% Click Events
    click ENGINE "https://github.com/orurh/c_tetris/tree/develop/tetris/"
    click FSM_DEF "https://github.com/orurh/c_tetris/blob/develop/Fsm_states.txt"
    click CLI "https://github.com/orurh/c_tetris/tree/develop/gui/cli/"
    click TEST "https://github.com/orurh/c_tetris/blob/develop/test/tests_s21_tetris.c"
    click MAKEFILE "https://github.com/orurh/c_tetris/tree/develop/Makefile"
    click DOXYFILE "https://github.com/orurh/c_tetris/tree/develop/Doxyfile"
    click SUPPRESS "https://github.com/orurh/c_tetris/tree/develop/suppressins/"

    %% Styles
    classDef engine fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef cli fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef fsm fill:#FFA07A,stroke:#000,stroke-width:1px;
    classDef fsmNote fill:#FFB6C1,stroke:#000,stroke-width:1px,stroke-dasharray: 5 5;
    classDef test fill:#FFFF99,stroke:#000,stroke-width:2px;
    classDef build fill:#D3D3D3,stroke:#000,stroke-width:2px;
```
