# artzor/gotetris architecture

> Architecture diagram of the GitHub repository artzor/gotetris, 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/artzor/gotetris
- Repository: https://github.com/artzor/gotetris

## Overview

##### Main Components
- Entry Point: Represent main.go as the starting point that sets up the game.
- Rendering Engine: Illustrate the integration with the Pixel library, which is responsible for drawing graphics, managing the game loop, and handling input.
- Algorithms: Highlight the flood fill algorithm used for row clearing as a sub-component within the game logic, as it’s a key part of the game’s functionality.
- (Optional) Input Handling: Although not explicitly separated in the code, consider delineating input handling (keyboard events, etc.) as part of the rendering/game loop layer if needed.

##### Relationships and Interactions
- Game Loop: Show a loop where the rendering engine (via the Pixel library) continually updates the game state and checks for user input.
- Data Flow: Clearly demonstrate that the game logic processes input (user commands) and updates the game state, which then triggers a render call to the Pixel-based engine.

##### Architectural Patterns and Design Principles
- Modularization: Emphasize the separation between the main application flow, game mechanics, and rendering. This separation allows for easier testing and potential upgrades.
- Event-driven Loop: Indicate the event/game loop that fetches input events, propagates those events to update the game state, and then issues rendering commands.
- External Library Integration: Clearly mention the external dependency on the Pixel library which handles graphical rendering along with input and possibly timing functions.

##### Relevant Technologies and Frameworks
- Programming Language: Go for application logic and system structure.
- Graphics Library: Pixel for rendering and game loop controls.
- Flood Fill Algorithm: As a key algorithm for clearing rows, name it explicitly in your design.

##### Elements
- Core game mechanics (game logic and algorithms).
- External dependencies (Pixel library).
- Application entry point and auxiliary components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    A("Entry Point (main.go)"):::entry

    subgraph "Game Package"
        GC("Game Core (game.go)"):::gameModule
        SH("Shapes Handler (shapes.go)"):::gameModule
        FF("Flood Fill Algorithm"):::algorithm
    end

    R("Rendering & Input (Pixel)"):::rendering

    A -->|"initialize"| GC
    A -->|"initialize"| R
    GC -->|"contains"| SH
    GC -->|"uses"| FF
    GC -->|"updates"| R
    R -->|"captures"| GC

    click A "https://github.com/artzor/gotetris/blob/master/main.go"
    click GC "https://github.com/artzor/gotetris/blob/master/game/game.go"
    click SH "https://github.com/artzor/gotetris/blob/master/game/shapes.go"
    click FF "https://github.com/artzor/gotetris/blob/master/game/game.go"
    click R "https://github.com/artzor/gotetris/blob/master/main.go"

    classDef entry fill:#FFEEAD,stroke:#333,stroke-width:2px;
    classDef gameModule fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef algorithm fill:#F5B7B1,stroke:#333,stroke-width:2px;
    classDef rendering fill:#D5F5E3,stroke:#333,stroke-width:2px;
```
