# junjielyu13/tetris architecture

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

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

## Overview

##### Main Components
- Game Engine/Controller: Represented by main.py, which acts as the entry point and manages the game loop.
- Game Logic: Modules like tetris.py and Game.py are likely responsible for handling the Tetris game rules, piece movements, collisions, scoring, and other logic.
- Drawing/Rendering: drawScreen.py and drawText.py modules are targeted at rendering the game visuals (drawing the game grid, falling pieces, and text information).
- Assets & Resources: The Demo directory, along with the images directory under TetrisProject, stores screenshots or in-game graphics.
- Configuration/IDE Metadata: The .idea folder, although not directly part of the game’s runtime, provides IDE-specific setup that can be noted as development aids.

##### Relationships and Interactions
- The main.py (game entry point) initializes various components such as the game engine, graphics, and event loop.
- Game Logic components (Game.py and tetris.py) interact with the drawing modules (drawScreen.py, drawText.py) to update the game visuals based on the state changes.
- The assets in the Demo and images directories support the visual presentation of the game, possibly loaded and referenced within the drawing routines.

##### Architectural Patterns and Design Principles
- Event Loop and Real-time Rendering: The application likely follows a classic game-loop pattern where the main module repeatedly updates the game state and draws the current state.

##### Relevant Technologies and Libraries
- Python 3 is the primary language.
- Pygame is used for handling graphics, input events, and rendering.

- Link it to the “Game Logic” block which encapsulates Game.py and tetris.py.
- External libraries (Pygame) as an external dependency that supports both inputs and rendering.
- A peripheral note for resource management, showing that assets (images, demo screenshots) are loaded as part of rendering.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Main Engine
    GE["Game Engine (main.py)"]:::engine

    %% External Dependency
    PY["Pygame"]:::library

    %% Game Logic Subgraph
    subgraph "Game Logic"
        GL1["Game.py"]:::gameLogic
        GL2["tetris.py"]:::gameLogic
    end

    %% Block & Shapes Definitions Subgraph
    subgraph "Block & Shapes Definitions"
        B1["block.py"]:::block
        S1["shapes.py"]:::block
    end

    %% Rendering Components Subgraph
    subgraph "Rendering Components"
        R1["drawScreen.py"]:::rendering
        R2["drawText.py"]:::rendering
    end

    %% Assets & Resources Subgraph
    subgraph "Assets & Resources"
        IMG["Images"]:::assets
        DEMO["Demo Screenshots"]:::assets
    end

    %% Configuration/IDE
    IDE[".idea"]:::config

    %% Relationships and Data Flow
    GE -->|"manages"| GL1
    GE -->|"manages"| GL2
    GE -->|"triggers"| R1
    GE -->|"triggers"| R2
    GE -->|"uses"| PY
    GL2 -->|"uses"| B1
    GL2 -->|"uses"| S1
    R1 -->|"loads"| IMG
    R2 -->|"loads"| IMG
    R1 -->|"loads"| DEMO
    R2 -->|"loads"| DEMO
    %% Configuration is peripheral support
    GE -.->|"configured_by"| IDE

    %% Click Events
    click GE "https://github.com/junjielyu13/tetris/blob/main/TetrisProject/src/main.py"
    click GL1 "https://github.com/junjielyu13/tetris/blob/main/TetrisProject/src/Game.py"
    click GL2 "https://github.com/junjielyu13/tetris/blob/main/TetrisProject/src/tetris.py"
    click R1 "https://github.com/junjielyu13/tetris/blob/main/TetrisProject/src/drawScreen.py"
    click R2 "https://github.com/junjielyu13/tetris/blob/main/TetrisProject/src/drawText.py"
    click B1 "https://github.com/junjielyu13/tetris/blob/main/TetrisProject/src/block.py"
    click S1 "https://github.com/junjielyu13/tetris/blob/main/TetrisProject/src/shapes.py"
    click IMG "https://github.com/junjielyu13/tetris/tree/main/TetrisProject/images"
    click DEMO "https://github.com/junjielyu13/tetris/tree/main/Demo"
    click IDE "https://github.com/junjielyu13/tetris/blob/main/TetrisProject/.idea"

    %% Styles
    classDef engine fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef gameLogic fill:#ffcccb,stroke:#000,stroke-width:1px;
    classDef rendering fill:#ccffcc,stroke:#000,stroke-width:1px;
    classDef block fill:#ffebcc,stroke:#000,stroke-width:1px;
    classDef assets fill:#e0ccff,stroke:#000,stroke-width:1px;
    classDef config fill:#d3d3d3,stroke:#000,stroke-width:1px;
    classDef library fill:#ffffcc,stroke:#000,stroke-width:1px;
```
