# codeonaraft/krpg architecture

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

- Interactive diagram: https://gitdiagram.com/codeonaraft/krpg
- Repository: https://github.com/codeonaraft/krpg

## Overview

##### Main Components
- Editor Module: Located in the “editor” folder, it contains its own build and configuration files, UI components (such as menus, dialogs, properties windows, etc.), and resources (styles and configuration resources).
- Game Module: Found in the “game” folder, this contains the core gameplay logic including the main game loop (game/src/main.zig), game-specific configurations, maps, objects (barrels, bread rolls, etc.), and game resources (scene files and object definitions).
- Shared Module: All common functionality, types, managers, and utility functions reside in the “shared” folder. This module includes various managers (GameManager, ObjectsManager), definitions for game objects, utility functions (such as for string and vector operations), and core types and interfaces used by both the editor and game.

##### Architecturally-Relevant File Structures
- The directory separation clearly distinguishes between the game runtime, the editor, and the common shared code. This is an indicator of modular design.
- Each module has its own build scripts (build.zig and accompanying configuration files) indicating independent build processes, while still relying on shared code.
- The presence of UI components inside the editor’s “src/ui” directory (with dialog and menu sub-folders) informs that the editor likely uses a custom UI framework possibly built on raylib (as the README mentions the Game Library raylib).
- Resources such as maps, objects, and scene files in the game module indicate that the game engine is structured to support asset loading and gameplay management using these resource files.

##### Relationships and Interaction
- The Game Module and Editor Module both interact with the Shared Module. They likely share core game logic, utility functions, data types, and managers (e.g., GameManager, ObjectsManager).
- The Editor is intended to help create or modify game content, meaning there are bi-directional interactions: the editor sends data/configurations to update game state/assets and might read or write configurations defined in the shared module.
- The game runtime utilizes external libraries, notably raylib, to handle rendering, user input, and audio.

##### Architectural Patterns/Design Principles
- Modular Architecture: Separation of game, editor, and shared libraries for better maintainability and future extension.
- MVC tendencies in the editor: There is a distinction between UI components (views) and underlying logic, indicated by separate UI files and menus/dialogs.
- Layered Structure: At a high level, the application has layers for presentation (editor UI and game rendering), business logic (managers, scene management, object manipulation), and data/configuration (resources and map files).

a. Components:
- Game Editor: Includes UI subcomponents (Menus, Dialogs, Properties, Scene Windows) and resources (styles, configuration).
- Game Runtime: Encompassing main game loop, resource management (maps, game objects like barrels and NPCs), and scene management.
- Shared Library: The core logic layer with managers, types (Basic types, GameObjects, UI types), utility functions (strings, vector math), and interfaces.
- External Services/Libraries: For example, raylib is used for rendering and input.
b. Data Flow and Interactions:
- Connections between Game and Shared modules, indicating shared managers, types, and utility functions.
- Annotations to show how resources are loaded by the game runtime from resources directories.
c. Architectural Patterns:
- Modular separation.
- Independent build/runner paths (“zig build run” in both game and editor) which allows them to be executed individually.
d. Technologies and Frameworks:
- Zig as the implementation language.
- Raylib under External Libraries as it is critical for game rendering and input handling.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Editor Module
    subgraph "Editor Module"
        E1("Build & Config"):::module
        E2("Editor Main"):::module
        subgraph "UI Components"
            E3("PropertiesWindow"):::ui
            E4("SceneWindow"):::ui
            E5("MessageBox"):::ui
            E6("OpenFileDialog"):::ui
            E7("Menu"):::ui
        end
    end

    %% Game Module
    subgraph "Game Module"
        G1("Build & Config"):::module
        G2("Game Main Loop"):::module
        G3("Resources: Maps & Objects"):::resource
    end

    %% Shared Module
    subgraph "Shared Module"
        S1("Build & Config"):::module
        S2("Managers: GameManager, ObjectsManager"):::shared
        S3("Types: GameObjects (Inventory, Item, NPC, Object, Player)"):::shared
        S4("Utility Functions & Core Types"):::shared
    end

    %% External Libraries
    subgraph "External Libraries"
        R("raylib (Rendering & Input)"):::external
    end

    %% Interactions and Data Flow
    E2 -->|"uses"| S4
    E3 -->|"updates"| S3
    E5 -->|"triggers"| S2
    G2 -->|"invokes"| S2
    G2 -->|"accesses"| S4
    G3 -->|"loads"| S4
    E2 -->|"configures"| S2
    G2 -->|"renders via"| R

    %% Click Events for Component Mapping
    click E1 "https://github.com/codeonaraft/krpg/tree/master/editor/"
    click E2 "https://github.com/codeonaraft/krpg/blob/master/editor/src/editor.zig"
    click E3 "https://github.com/codeonaraft/krpg/blob/master/editor/src/ui/PropertiesWindow.zig"
    click E4 "https://github.com/codeonaraft/krpg/blob/master/editor/src/ui/SceneWindow.zig"
    click E5 "https://github.com/codeonaraft/krpg/blob/master/editor/src/ui/dialog/MessageBox.zig"
    click E6 "https://github.com/codeonaraft/krpg/blob/master/editor/src/ui/dialog/OpenFileDialog.zig"
    click E7 "https://github.com/codeonaraft/krpg/blob/master/editor/src/ui/menu.zig"
    click G1 "https://github.com/codeonaraft/krpg/tree/master/game/"
    click G2 "https://github.com/codeonaraft/krpg/blob/master/game/src/main.zig"
    click G3 "https://github.com/codeonaraft/krpg/tree/master/game/resources/map"
    click S1 "https://github.com/codeonaraft/krpg/tree/master/shared/"
    click S2 "https://github.com/codeonaraft/krpg/tree/master/shared/src/managers"
    click S3 "https://github.com/codeonaraft/krpg/tree/master/shared/src/types/GameObjects"
    click S4 "https://github.com/codeonaraft/krpg/tree/master/shared/src/utility"

    %% Styles
    classDef module fill:#f9f,stroke:#333,stroke-width:2px;
    classDef ui fill:#bbf,stroke:#333,stroke-width:2px;
    classDef resource fill:#afa,stroke:#333,stroke-width:2px;
    classDef shared fill:#ffc,stroke:#333,stroke-width:2px;
    classDef external fill:#fcc,stroke:#333,stroke-width:2px;
```
