# kennethlove/hangry-games architecture

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

- Interactive diagram: https://gitdiagram.com/kennethlove/hangry-games
- Repository: https://github.com/kennethlove/hangry-games

## Overview

##### Main Components

a) User Interface Layer:
- Web GUI (Dioxus-based frontend)
- CLI Interface
Both should be represented as separate entry points

b) Core Application Layer:
- Game Engine
- Simulation Logic
- Event System

c) Data Layer:
- PostgreSQL Database
- Diesel ORM Interface

##### Key Architectural Elements

**[User Interface Layer]**

**[Application Layer]**

**[Data Access Layer]**

**[Database Layer]**

##### Component Relationships

a) Frontend Components:
- Components hierarchy from src/gui/components/
- Router.rs to individual components
- State management (states.rs)

b) Core Game Logic:
- Models/ directory components
- Relationship between tributes/, events/, and games/ modules
- Action flow from user input to game state changes

##### Specific Implementation Details

- Blue rectangles: User interface components
- Green rectangles: Core game logic
- Yellow diamonds: Data models
- Red rectangles: Database components

##### Key Flows to Highlight

a) Game Creation Flow:
**CLI/GUI → Game Engine → Models → Database**

b) Simulation Flow:
**Game Engine → Events → Actions → State Updates → Database**

##### Important Subsystems

- Tribute management system (src/tributes/)
- Event handling system (src/events.rs)
- Area management (src/areas.rs)
- Item system (src/items.rs)

##### Database Schema Relationships

Entity relationships between:
- Games
- Tributes
- Areas
- Actions
- Items
- Events
- Logs

##### Technical Stack Indicators

- Rust
- Dioxus
- PostgreSQL
- Diesel ORM
- Tailwind CSS

Remember to show the development environment setup (Docker/devcontainer) as a separate supporting component, as indicated by the .devcontainer directory.

This architecture should emphasize the event-driven nature of the game simulation while showing clear separation of concerns between UI, business logic, and data persistence layers.

## Diagram (Mermaid)

```mermaid
graph TB
    subgraph UI["User Interface Layer"]
        GUI["Web GUI"]
        CLI["CLI Interface"]
        COMP["GUI Components"]
        ROUTER["Router"]
        STATE["State Management"]
        
        GUI --> COMP
        GUI --> ROUTER
        GUI --> STATE
    end

    subgraph CORE["Core Game Engine"]
        GAME["Game Logic"]
        EVENT["Event System"]
        MSG["Message System"]
    end

    subgraph TRIBUTE["Tribute System"]
        TRIB_MGMT["Tribute Management"]
        TRIB_ACT["Tribute Actions"]
        TRIB_AI["Tribute AI"]
        TRIB_STATUS["Tribute Status"]
        
        TRIB_MGMT --> TRIB_ACT
        TRIB_MGMT --> TRIB_AI
        TRIB_MGMT --> TRIB_STATUS
    end

    subgraph WORLD["World Systems"]
        AREAS["Area Management"]
        ITEMS["Item System"]
        ITEM_GEN["Item Generation"]
        ANIMALS["Animal System"]
    end

    subgraph DATA["Data Layer"]
        DB_INT["Database Interface"]
        SCHEMA["Schema Definition"]
        MODELS["Data Models"]
        MIGRATIONS["Database Migrations"]
    end

    subgraph DB["Database Layer"]
        POSTGRES[(PostgreSQL)]
    end

    UI --> CORE
    CORE --> TRIBUTE
    CORE --> WORLD
    CORE --> DATA
    DATA --> DB

    classDef frontend fill:#3b82f6
    classDef core fill:#22c55e
    classDef data fill:#f59e0b
    classDef db fill:#ef4444

    class GUI,CLI,COMP,ROUTER,STATE frontend
    class GAME,EVENT,MSG,TRIB_MGMT,TRIB_ACT,TRIB_AI,TRIB_STATUS,AREAS,ITEMS,ITEM_GEN,ANIMALS core
    class DB_INT,SCHEMA,MODELS,MIGRATIONS data
    class POSTGRES db

    click GUI "https://github.com/kennethlove/hangry-games/tree/main/src/gui/"
    click CLI "https://github.com/kennethlove/hangry-games/blob/main/src/cli.rs"
    click COMP "https://github.com/kennethlove/hangry-games/tree/main/src/gui/components/"
    click ROUTER "https://github.com/kennethlove/hangry-games/blob/main/src/gui/router.rs"
    click STATE "https://github.com/kennethlove/hangry-games/blob/main/src/gui/states.rs"
    click GAME "https://github.com/kennethlove/hangry-games/blob/main/src/games.rs"
    click EVENT "https://github.com/kennethlove/hangry-games/blob/main/src/events.rs"
    click MSG "https://github.com/kennethlove/hangry-games/blob/main/src/messages.rs"
    click TRIB_MGMT "https://github.com/kennethlove/hangry-games/tree/main/src/tributes/"
    click TRIB_ACT "https://github.com/kennethlove/hangry-games/blob/main/src/tributes/actions.rs"
    click TRIB_AI "https://github.com/kennethlove/hangry-games/blob/main/src/tributes/brains.rs"
    click TRIB_STATUS "https://github.com/kennethlove/hangry-games/blob/main/src/tributes/statuses.rs"
    click AREAS "https://github.com/kennethlove/hangry-games/blob/main/src/areas.rs"
    click ITEMS "https://github.com/kennethlove/hangry-games/blob/main/src/items.rs"
    click ITEM_GEN "https://github.com/kennethlove/hangry-games/blob/main/src/item_name_generator.rs"
    click ANIMALS "https://github.com/kennethlove/hangry-games/blob/main/src/animals.rs"
    click DB_INT "https://github.com/kennethlove/hangry-games/blob/main/src/db.rs"
    click SCHEMA "https://github.com/kennethlove/hangry-games/blob/main/src/schema.rs"
    click MODELS "https://github.com/kennethlove/hangry-games/tree/main/src/models/"
    click MIGRATIONS "https://github.com/kennethlove/hangry-games/tree/main/hangry_games/migrations/"
```
