# ringtailsoftware/zigtris architecture

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

- Interactive diagram: https://gitdiagram.com/ringtailsoftware/zigtris
- Repository: https://github.com/ringtailsoftware/zigtris

## Overview

##### Main Components

a) Core Game Components:
- Main Game Loop (src/main.zig)
- Player Controller (src/player.zig)
- Stage Manager (src/stage.zig)
- Debris System (src/debris.zig)
- Decor Handler (src/decor.zig)
- Time Controller (src/time.zig)
- System (src/display.zig)

**┌─ User Interface Layer ─────────────────┐**
- Terminal Display            │
- (via mibu library)           │
- ┬───────────────────┘
- ↑
**┌─ Display Layer ────────────────────────┐**
- Display Component              │
- (Double-buffered rendering)        │
- ┬───────────────────┘
- ↑
**┌─ Game Logic Layer ─────────────────────┐**
- ┌─────────┐ ┌─────────┐ ┌─────────┐  │
- Player  │ │  Stage  │ │ Debris  │  │
- ┘ └─────────┘ └─────────┘  │
- ┌─────────┐ ┌─────────┐              │
- Decor  │ │  Time   │              │
- ┘ └─────────┘              │
- ┬───────────────────┘
- ↑
**┌─ System Layer ────────────────────────┐**
- Main Game Loop                 │
- (Input Processing)               │
- ┘

##### Component Relationships to Highlight

- System (display.zig):
- As a wrapper around the mibu terminal library
- Double-buffering mechanism with two buffer states

- Stage Component (stage.zig):
- Relationship with Player and Debris components

- Player Component (player.zig):
- Movement logic flow
- To Stage for rendering
- To Debris for collision detection

- Debris System (debris.zig):
- Connection to Stage for rendering
- Line completion detection logic
- To Player for collision checking

##### Additional Elements

- Version compatibility note (Zig 0.14.0)
- Entry points (both direct and SSH service)

Remember to indicate the build and deployment options (Docker, SSH service) as external wrapper elements around the main architecture, as they represent different ways to run the same core system.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef display fill:#2ecc71,stroke:#27ae60,color:white
    classDef gameLogic fill:#e74c3c,stroke:#c0392b,color:white
    classDef system fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef deployment fill:#f1c40f,stroke:#f39c12,color:white

    %% Deployment Layer
    subgraph Deployment
        Docker["Docker Container"]
        SSH["SSH Service"]
        Build["Zig Build System"]
    end

    %% UI Layer
    subgraph UI
        Terminal["Terminal Interface"]:::ui
        Mibu["mibu Library"]:::ui
    end

    %% Display Layer
    subgraph Display
        DisplaySystem["Display System<br/>(Double Buffered)"]:::display
    end

    %% Game Logic Layer
    subgraph GameLogic
        Player["Player Controller"]:::gameLogic
        Stage["Stage Manager"]:::gameLogic
        Debris["Debris System"]:::gameLogic
        Decor["Decor Handler"]:::gameLogic
        Time["Time Controller"]:::gameLogic
    end

    %% System Layer
    subgraph System
        MainLoop["Main Game Loop"]:::system
    end

    %% Relationships
    Docker --> Terminal
    SSH --> Terminal
    Terminal --- Mibu
    Mibu --> DisplaySystem
    DisplaySystem --> Stage
    Stage --> Player
    Stage --> Debris
    Stage --> Decor
    Player --> Debris
    MainLoop --> Player
    MainLoop --> Time
    Time --> GameLogic

    %% Click Events
    click MainLoop "https://github.com/ringtailsoftware/zigtris/blob/main/src/main.zig"
    click Player "https://github.com/ringtailsoftware/zigtris/blob/main/src/player.zig"
    click Stage "https://github.com/ringtailsoftware/zigtris/blob/main/src/stage.zig"
    click Debris "https://github.com/ringtailsoftware/zigtris/blob/main/src/debris.zig"
    click Decor "https://github.com/ringtailsoftware/zigtris/blob/main/src/decor.zig"
    click Time "https://github.com/ringtailsoftware/zigtris/blob/main/src/time.zig"
    click DisplaySystem "https://github.com/ringtailsoftware/zigtris/blob/main/src/display.zig"
    click Docker "https://github.com/ringtailsoftware/zigtris/tree/main/Dockerfile"
    click SSH "https://github.com/ringtailsoftware/zigtris/blob/main/run-as-service.sh"
    click Build "https://github.com/ringtailsoftware/zigtris/blob/main/build.zig"

    %% Legend
    subgraph Legend
        L1["UI Components"]:::ui
        L2["Display Components"]:::display
        L3["Game Logic Components"]:::gameLogic
        L4["System Components"]:::system
        L5["Deployment Components"]:::deployment
    end
```
