# evgenyzamury/tetris_pygame architecture

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

- Interactive diagram: https://gitdiagram.com/evgenyzamury/tetris_pygame
- Repository: https://github.com/evgenyzamury/tetris_pygame

## Overview

##### Main Components
- Game Core / Engine: Represented by files such as main.py, board.py, block.py, blocks.py, and variables.py. This “Engine” manages the overall game loop, game state, collision detection, and block management.
- User Interface (UI) & Input Handling: Files like UI_statistik.py, ui_menu.py, settings_ui.py, and button.py indicate management of graphical menus, game settings and statistics, as well as capturing user actions (keyboard inputs via Pygame events).
- Audio & Multimedia: The data folder holds sounds (mp3 files) and images (e.g., left.png, right.png, play menu images) which are used by the game. The camera.py could possibly relate to UI effects or background animations.
- Persistence / Database: The presence of tetris.db and database.py, along with log_in.py, suggests that the game might store player scores, game history, or login information.
- External Dependencies & Setup: The requirements.txt file shows the dependencies (mainly Pygame). The tetris.exe is a packaged executable version.
- Auxiliary Scripts: Additional scripts like block.py vs. blocks.py may indicate different responsibilities (e.g., one for a single block definition and the other for managing a collection or the block's rotations).

##### Relationships & Interactions
- The Game Loop (central component in main.py) integrates the game core with UI components by constantly updating the board (board.py) and processing user inputs (button.py, UI_statistik.py, settings_ui.py).
- The UI layer communicates with the game engine to show updates (rendering blocks, scores, menus).
- The database component (database.py and tetris.db) receives game progress or score updates, likely triggered by interactions in main.py and auxiliary login/authentication from log_in.py.
- Multimedia assets from the data folder (images and sounds) are loaded and triggered by different game actions (block placement, line clear, rotation, etc.) through corresponding functions in modules.

##### Architectural Patterns & Important Design Principles
- Separation of Concerns: The project is divided into distinct modules for gameplay logic, UI presentation, multimedia asset management, and data persistence.
- Event-driven design: Pygame’s event loop likely drives interactions (keyboard inputs, game timing), with UI reacting to the events.
- Modular structure: Each file is responsible for a distinct part of the functionality, making the system easier to maintain and extend.

a. Create clear nodes for:
- Game Engine (main.py, board.py, block(s).py, variables.py)
- UI / Input Manager (ui_menu.py, UI_statistik.py, settings_ui.py, button.py)
- Multimedia Manager (camera.py, assets from data/image & data/sounds)
- Persistence / Database (database.py, log_in.py, tetris.db)
- Deployment/Execution (requirements.txt, tetris.exe)

- The Game Loop in the Engine is at the center and feeds update calls to the UI Manager.
- The UI components receive input and forward events to the Game Engine.
- The Audio/Multimedia Manager is invoked by game actions (e.g., when a block rotates or a line is cleared).
- Bi-directional flow between the Engine and the Database: the Engine updates player scores and possibly retrieves high scores.
- The external deployment component (such as the packaging via tetris.exe) encapsulates the game engine and related components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Deployment Layer
    requirements["requirements.txt"]:::deployment
    tetris_exe["tetris.exe"]:::deployment

    %% Game Engine Layer
    subgraph "Game Engine / Core"
        main_py["main.py"]:::engine
        board_py["board.py"]:::engine
        block_py["block.py"]:::engine
        blocks_py["blocks.py"]:::engine
        variables_py["variables.py"]:::engine
    end

    %% UI & Input Handling Layer
    subgraph "UI & Input Handling"
        ui_menu["ui_menu.py"]:::ui
        ui_statistik["UI_statistik.py"]:::ui
        settings_ui["settings_ui.py"]:::ui
        button["button.py"]:::ui
    end

    %% Multimedia & Asset Manager Layer
    subgraph "Multimedia & Asset Manager"
        camera["camera.py"]:::multimedia
        assets["data/"]:::multimedia
    end

    %% Persistence / Database Layer
    subgraph "Persistence / Database"
        database["database.py"]:::database
        log_in["log_in.py"]:::database
        tetris_db["tetris.db"]:::database
    end

    %% Connections from Deployment to Game Engine
    requirements -->|"deps"| main_py
    tetris_exe -->|"packaged"| main_py

    %% Game Engine internal connections
    main_py -->|"init_board"| board_py
    main_py -->|"create_block"| block_py
    main_py -->|"manage_blocks"| blocks_py
    main_py -->|"set_variables"| variables_py

    %% UI interactions with Game Engine
    ui_menu -->|"input"| main_py
    ui_statistik -->|"input"| main_py
    settings_ui -->|"input"| main_py
    button -->|"input"| main_py
    main_py -->|"update_UI"| ui_menu
    main_py -->|"update_UI"| ui_statistik
    main_py -->|"update_UI"| settings_ui
    main_py -->|"update_UI"| button

    %% Multimedia interactions with Game Engine
    main_py -->|"trigger_multimedia"| camera
    main_py -->|"load_assets"| assets

    %% Persistence interactions with Game Engine (bidirectional)
    main_py <-->|"score"| database
    main_py <-->|"auth"| log_in
    main_py <-->|"persist"| tetris_db

    %% Styles
    classDef engine fill:#ffccff,stroke:#990099,stroke-width:2px;
    classDef ui fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef multimedia fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef deployment fill:#fff3cd,stroke:#856404,stroke-width:2px;

    %% Click Events
    click main_py "https://github.com/evgenyzamury/tetris_pygame/blob/main/main.py"
    click board_py "https://github.com/evgenyzamury/tetris_pygame/blob/main/board.py"
    click block_py "https://github.com/evgenyzamury/tetris_pygame/blob/main/block.py"
    click blocks_py "https://github.com/evgenyzamury/tetris_pygame/blob/main/blocks.py"
    click variables_py "https://github.com/evgenyzamury/tetris_pygame/blob/main/variables.py"
    click ui_menu "https://github.com/evgenyzamury/tetris_pygame/blob/main/ui_menu.py"
    click ui_statistik "https://github.com/evgenyzamury/tetris_pygame/blob/main/UI_statistik.py"
    click settings_ui "https://github.com/evgenyzamury/tetris_pygame/blob/main/settings_ui.py"
    click button "https://github.com/evgenyzamury/tetris_pygame/blob/main/button.py"
    click camera "https://github.com/evgenyzamury/tetris_pygame/blob/main/camera.py"
    click assets "https://github.com/evgenyzamury/tetris_pygame/tree/main/data/"
    click database "https://github.com/evgenyzamury/tetris_pygame/blob/main/database.py"
    click log_in "https://github.com/evgenyzamury/tetris_pygame/blob/main/log_in.py"
    click tetris_db "https://github.com/evgenyzamury/tetris_pygame/blob/main/data/tetris.db"
    click requirements "https://github.com/evgenyzamury/tetris_pygame/blob/main/requirements.txt"
    click tetris_exe "https://github.com/evgenyzamury/tetris_pygame/blob/main/tetris.exe"
```
