# spkerkela/piru architecture

> Architecture diagram of the GitHub repository spkerkela/piru, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/spkerkela/piru
- Repository: https://github.com/spkerkela/piru

## Overview

##### Main Components Identification
The project appears to be a single-executable game with several distinct subsystems. Here's how to structure the main components:

Core Game Systems:
- Game Loop Controller (piru.c as entry point)
- Input System (input.c/h)
- Rendering System (sdl2.c/h)
- Time Management (time.c/h)

Game Logic:
- Player Management (player.c/h)
- Monster System (monster.c/h)
- Combat/Damage System (damage_text.c/h)
- Spell System (spell.c/h)
- Effects System (effect.c/h)

World/Environment:
- Dungeon Generation/Management (dungeon.c/h)
- Pathfinding System (pathfinding.c/h)

Utility Systems:
- Asset Management (assets.c/h)
- Math Utilities (piru_math.c/h)
- Direction Handling (direction.c/h)
- Point/Position Management (point.c/h)

##### Specific Elements

SDL2 Integration Layer:
- SDL2 and its components (SDL2-mixer, SDL2-ttf, SDL2-image) as external dependencies
- Them to the rendering and asset management systems

Game State Flow:
- How the game loop coordinates between input, update, and render phases
- How time management affects the game loop

Entity Interactions:
- Demonstrate relationships between player, monsters, and spells
- How pathfinding connects to monster AI
- Damage system interaction with entities

Level 1 (Top Level):
**[SDL2 Dependencies] ↔ [Core Game Loop] ↔ [Asset Management]**
- ↕                    ↕                ↕
**[Rendering System] ← [Game State Manager] → [World System]**

Level 2 (Detailed Systems):
**[Input Handler] → [Player System] ← [Combat System]**
- ↕
**[Monster System] ← [Pathfinding] → [Dungeon System]**

##### Technical Details to Highlight

- Asset loading and management flow
- Game loop timing and synchronization
- Entity update order and priority
- Collision detection and resolution paths
- Spell and effect propagation through the system

Remember to maintain a balance between showing enough detail to understand the system's architecture while not overwhelming the viewer with implementation-specific details. The goal is to communicate the high-level design while making the relationships between components clear and logical.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Style definitions
    classDef core fill:#a8d1f0,stroke:#333,stroke-width:2px
    classDef gameLogic fill:#90EE90,stroke:#333,stroke-width:2px
    classDef world fill:#FFE5B4,stroke:#333,stroke-width:2px
    classDef utility fill:#D3D3D3,stroke:#333,stroke-width:2px
    classDef external fill:#FFB6C1,stroke:#333,stroke-width:2px
    classDef data fill:#DDA0DD,stroke:#333,stroke-width:2px

    %% External Dependencies
    subgraph SDL["SDL2 Dependencies"]
        SDL2["SDL2 Core"]:::external
        SDL2_mixer["SDL2 Mixer"]:::external
        SDL2_ttf["SDL2 TTF"]:::external
        SDL2_image["SDL2 Image"]:::external
    end

    %% Core Systems
    GameLoop["Game Loop Controller"]:::core
    Input["Input System"]:::core
    Render["Rendering System"]:::core
    TimeManager["Time Management"]:::core

    %% Game Logic
    Player["Player Management"]:::gameLogic
    Monster["Monster System"]:::gameLogic
    Combat["Combat/Damage System"]:::gameLogic
    Spell["Spell System"]:::gameLogic
    Effect["Effects System"]:::gameLogic

    %% World/Environment
    Dungeon["Dungeon Generation"]:::world
    Pathfinding["Pathfinding System"]:::world

    %% Utility Systems
    Assets["Asset Management"]:::utility
    Math["Math Utilities"]:::utility
    Direction["Direction Handling"]:::utility
    Point["Point/Position Management"]:::utility

    %% Data Structures
    DataStructs["Data Structures"]:::data
    Enums["Enumerations"]:::data
    Constants["Constants"]:::data

    %% Relationships
    SDL2 --> Render
    SDL2_mixer --> Assets
    SDL2_ttf --> Assets
    SDL2_image --> Assets

    GameLoop --> Input
    GameLoop --> Render
    GameLoop --> TimeManager
    
    Input --> Player
    Player --> Combat
    Player --> Spell
    
    Monster --> Combat
    Monster --> Pathfinding
    Monster --> Spell
    
    Pathfinding --> Dungeon
    
    Combat --> Effect
    Spell --> Effect
    
    Assets --> Render
    Math --> Pathfinding
    Direction --> Monster
    Point --> Pathfinding
    
    DataStructs --> GameLoop
    Enums --> GameLoop
    Constants --> GameLoop

    %% Click events for component mapping
    click GameLoop "https://github.com/spkerkela/piru/blob/master/piru.c"
    click Input "https://github.com/spkerkela/piru/blob/master/input.c"
    click Render "https://github.com/spkerkela/piru/blob/master/sdl2.c"
    click TimeManager "https://github.com/spkerkela/piru/blob/master/time.c"
    click Player "https://github.com/spkerkela/piru/blob/master/player.c"
    click Monster "https://github.com/spkerkela/piru/blob/master/monster.c"
    click Combat "https://github.com/spkerkela/piru/blob/master/damage_text.c"
    click Spell "https://github.com/spkerkela/piru/blob/master/spell.c"
    click Effect "https://github.com/spkerkela/piru/blob/master/effect.c"
    click Dungeon "https://github.com/spkerkela/piru/blob/master/dungeon.c"
    click Pathfinding "https://github.com/spkerkela/piru/blob/master/pathfinding.c"
    click Assets "https://github.com/spkerkela/piru/blob/master/assets.c"
    click Math "https://github.com/spkerkela/piru/blob/master/piru_math.c"
    click Direction "https://github.com/spkerkela/piru/blob/master/direction.c"
    click Point "https://github.com/spkerkela/piru/blob/master/point.c"
    click DataStructs "https://github.com/spkerkela/piru/blob/master/structs.h"
    click Enums "https://github.com/spkerkela/piru/blob/master/enums.h"
    click Constants "https://github.com/spkerkela/piru/blob/master/constants.h"

    %% Legend
    subgraph Legend
        L1["Core Systems"]:::core
        L2["Game Logic"]:::gameLogic
        L3["World Systems"]:::world
        L4["Utility Systems"]:::utility
        L5["External Dependencies"]:::external
        L6["Data Structures"]:::data
    end
```
