# fleurieblumune/pyrogue architecture

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

- Interactive diagram: https://gitdiagram.com/fleurieblumune/pyrogue
- Repository: https://github.com/fleurieblumune/pyrogue

## Overview

##### Main Components
- Engine: This is the backbone of the project and is divided into several submodules:
- Core: Contains the GameLoop, InputHandler, Event management, entity management (EntityManager and Interfaces), and utility functions (pathfinding, position management, glyph provider, etc.).
- Renderer: Manages the drawing of entities, camera controls, tile management, and overall graphic rendering.
- UI (Engine/UI): Implements the menu systems and other interface components used when interacting with the game.
- Game: Contains game-specific logic and content:
- Content: Holds Assets (fonts, cards), Card management (CardFactory, CardLoader, InventoryManager, DeckManager), game data (CSV files and data loaders), and zone definitions.
- Entities: Defines all game characters and statistics (Players, NPCs, various stats and entity types).
- Zones: Manages game areas (dungeons, rooms, grids, zones) which the game loop processes.
- Systems: Implements core game mechanics such as Combat, Inventory, Turn management, LineOfSight, Stats systems.
- UI (Game/UI): Provides higher-level user interfaces like TitleScreen, PauseMenu, InventoryMenu, and other in-game menus.
- Data: Contains CSV files for cards and possibly historical or reference data (though similar CSV files exist in the Game/Content/Data, the distinction might serve different runtime purposes).

##### Relationships and Interactions
- The Main Entry Points (main.py, run_game.py) trigger the Game Loop from the Engine/Core. This loop is responsible for polling inputs (via InputHandler), processing game logic (like the Systems for Combat, Inventory, etc.), and rendering output (using Renderer).
- The Engine acts as the “runtime framework” while the Game directory contains the higher-level domain logic – such as entity behavior, zone management, and card-related features.
- Data flows from configuration and CSV data (both in Data and Game/Content/Data) into game data loaders (e.g., Data/GameData.py, DataLoader.py) to initialize game content.
- UI elements in both Engine/UI and Game/UI interact to present menus and user feedback. They connect to the underlying engine/game systems.

##### Architectural Patterns and Technologies
- Modularity: The clear split between Engine and Game highlights separation of concerns. The Engine is likely built as a reusable game framework, and the Game module builds on that framework.
- Layered Architecture: At the lowest layers are data and utility modules, above which sit the core loop and event handling, and then the game-specific systems and user interfaces.
- Design Patterns: Look for indications of MVC or Entity-Component designs – Engine/Core/Entity and EntityManager, as well as systems like turn management (suggesting a game loop tick/update process).
- Makefile commands in the README suggest a clear development and build process that ties the various components together.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Entry Point
    EP("main.py & run_game.py")

    %% Engine Subgraph
    subgraph "Engine"
        subgraph "Core"
            EngineCore("Core: GameLoop, InputHandler, Events, Entity Management, Utils")
        end
        subgraph "Renderer"
            EngineRenderer("Renderer: Camera, EntityRenderer, Renderer, TileManager")
        end
        subgraph "UI"
            EngineUI("UI: Menu System (Menu, MenuItem, MenuTypes)")
        end
    end

    %% Game Subgraph
    subgraph "Game"
        subgraph "Content"
            GameContent("Content: Assets, Cards, DataLoaders (CardFactory, CardLoader, DeckManager, InventoryManager, DataLoader, GameData)")
        end
        subgraph "Entities"
            GameEntities("Entities: Player, NPC, Stats")
        end
        subgraph "Zones"
            GameZones("Zones: DungeonZone, Room, Grid, Zone, RoomManager, TileType")
        end
        subgraph "Systems"
            GameSystems("Systems: Combat, Inventory, TurnManager, Stats Systems")
        end
        subgraph "UI"
            GameUI("UI: TitleScreen, Menus (HandPanel, InventoryMenu, PauseMenu)")
        end
    end

    %% Data Subgraph
    subgraph "Data"
        DataCSV("CSV Files: cards.csv, etc")
    end

    %% Relationships
    EP -->|"starts"| EngineCore
    EngineCore -->|"calls"| EngineRenderer
    EngineCore -->|"triggers"| GameSystems
    EngineUI -->|"syncs"| GameUI
    GameContent -->|"initializes"| GameEntities
    GameContent -->|"initializes"| GameZones
    GameContent -->|"initializes"| GameSystems
    DataCSV -->|"feeds"| GameContent

    %% Click Events
    click EngineCore "https://github.com/fleurieblumune/pyrogue/tree/main/Engine/Core"
    click EngineRenderer "https://github.com/fleurieblumune/pyrogue/tree/main/Engine/Renderer"
    click EngineUI "https://github.com/fleurieblumune/pyrogue/tree/main/Engine/UI"
    click GameContent "https://github.com/fleurieblumune/pyrogue/tree/main/Game/Content"
    click GameEntities "https://github.com/fleurieblumune/pyrogue/tree/main/Game/Content/Entities"
    click GameZones "https://github.com/fleurieblumune/pyrogue/tree/main/Game/Content/Zones"
    click GameSystems "https://github.com/fleurieblumune/pyrogue/tree/main/Game/Systems"
    click GameUI "https://github.com/fleurieblumune/pyrogue/tree/main/Game/UI"
    click DataCSV "https://github.com/fleurieblumune/pyrogue/tree/main/Data/CSV"

    %% Styles
    classDef engine fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef game fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef data fill:#d3d3d3,stroke:#000,stroke-width:2px;

    class EngineCore,EngineRenderer,EngineUI engine;
    class GameContent,GameEntities,GameZones,GameSystems,GameUI game;
    class DataCSV data;
```
