# galaxy-vn/chemdah architecture

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

- Interactive diagram: https://gitdiagram.com/galaxy-vn/chemdah
- Repository: https://github.com/galaxy-vn/chemdah

## Overview

##### Project Type and Purpose
- Chemdah is clearly a plugin for a Minecraft server, integrating with platforms like Bukkit/Spigot.
- Its purpose is to handle complex features such as quest management, conversation systems, and support for various addons/modules (e.g., party systems, levels, realms, UI, wizard systems).
- The README indicates that the project needs to be built from source (using Gradle’s wrapper) with no pre-built jar provided. It also mentions available JavaDoc and related plugins like “Blockdb”, suggesting reliance on external data management utilities.

##### File Structure
- The top-level build files (build.gradle.kts, gradlew, settings.gradle.kts, etc.) indicate a typical Gradle-based Java/Kotlin project.
- There is both a Java and a Kotlin codebase; note that Java files (e.g., under src/main/java/ink/ptms/chemdah/library/redlib) form part of the reusable library (“redlib”) that handles core functions such as event listening, SQL integration, and backend support.
- The src/main/kotlin directory has the bulk of the development. The package structure (ink.ptms.chemdah) is divided into:
- API (exposing hooks and public events, found under …/chemdah/api and …/chemdah/api/event)
- Core (which contains engine components for conversation, database handling, and quest systems, as seen in the core directory)
- Modules (each module such as kether, level, party, realms, scenes, ui, wizard encapsulate distinct functionalities/extensions)
- Utility packages (providing extra functionality and helper classes)
- There is also a “resources” folder with configuration files (e.g., config.yml, various module and conversation configurations, and language files), indicating external configuration for runtime behavior.

##### Extract Key Architectural Elements
- Plugin Entry & Initialization:
- The entry point seems to be the Chemdah.kt file under src/main/kotlin/ink/ptms/chemdah. This is where the plugin likely initializes and registers events, modules, and API hooks.
- Core Engine Components:
- Conversation System – multiple packages under core/conversation including agents, triggers, and sessions.
- Quest Engine – a robust quest system with sub-packages for objectives (covering different kinds of game events like block interactions, entity damage, and custom event hooks) and selectors.
- Database Management – contained in core/database with support for SQL and SQLite; likely managing persistent data for quests and players.
- Library (Redlib):
- A lower-level utility library providing common functionalities for block data management, event handling, and backend implementations (including different backends such as PDCBackend and SQLiteBackend).
- Modular Extensions:
- Modules like kether (scripting/actions), level, party, realms, scenes, synchronous, UI, and wizard are encapsulated as independent components that integrate with the core engine.
- API and Event System:
- Exposed APIs and a comprehensive event system (in api/event) allow external plugins or addon developers to hook into Chemdah’s functionality.
- External Dependencies:
- Integration with external plugins (for example, the Blockdb jar, and integrations with Citizens, MythicMobs as observed in event trigger packages) is a key aspect of the design.
- Configuration Management:
- Extensive use of YAML configuration files (found in resources) that control conversation, module settings, and language resources.

1. Central “Plugin Entry Point (Chemdah.kt)” and branch out to show its immediate interactions:
- Core Engine touches: conversation, quest, database management.
- API Exposure: ChemdahAPI and event factories.
- Initialization of Modules.
- One for core functionalities (business logic, data persistence) that depend on the Redlib utilities.
- One for various modules (kether, level, party, etc.) that extend or specialize the core.
- One for configuration management, showing how YAML and other resource files feed into both Core and Modules.
3. Overlay external services and integrations:

## Diagram (Mermaid)

```mermaid
flowchart TD
    A["Chemdah Plugin Entry"]:::entry

    subgraph "API & Event System"
        B["Chemdah API"]:::api
        C["Event System"]:::api
    end

    subgraph "Core Engine"
        E["Conversation Engine"]:::core
        F["Quest Engine"]:::core
        G["Database Management"]:::core
    end

    subgraph "Modular Extensions"
        I1["Kether Module"]:::modular
        I2["Level Module"]:::modular
        I3["Party Module"]:::modular
        I4["Realms Module"]:::modular
        I5["Scenes Module"]:::modular
        I6["UI Module"]:::modular
        I7["Wizard Module"]:::modular
    end

    H["Redlib Library"]:::library
    J["Configuration & Resources"]:::config

    subgraph "External Integrations"
        K1["Blockdb"]:::external
        K2["Citizens"]:::external
        K3["MythicMobs"]:::external
    end

    %% Plugin Entry relationships
    A -->|"initializes"| B
    A -->|"initializes"| C
    A -->|"starts"| E
    A -->|"starts"| F
    A -->|"starts"| G
    A -->|"loads"| J
    A -->|"activates"| I1
    A -->|"activates"| I2
    A -->|"activates"| I3
    A -->|"activates"| I4
    A -->|"activates"| I5
    A -->|"activates"| I6
    A -->|"activates"| I7

    %% Configuration feeding into Core Engine
    J -->|"configures"| E
    J -->|"configures"| F
    J -->|"configures"| G

    %% Core Engine using Library
    E -->|"utilizes"| H
    F -->|"utilizes"| H
    G -->|"utilizes"| H

    %% Modular Extensions using Library
    I1 -->|"depends on"| H
    I2 -->|"depends on"| H
    I3 -->|"depends on"| H
    I4 -->|"depends on"| H
    I5 -->|"depends on"| H
    I6 -->|"depends on"| H
    I7 -->|"depends on"| H

    %% API & Event System interactions with External Integrations
    B -->|"integrates_with"| K1
    B -->|"integrates_with"| K2
    B -->|"integrates_with"| K3
    C -->|"triggers"| K1
    C -->|"triggers"| K2
    C -->|"triggers"| K3

    %% External Integrations can trigger events in API
    K1 -->|"notifies"| B
    K2 -->|"notifies"| C
    K3 -->|"notifies"| B

    %% Class Definitions for Colors
    classDef entry fill:#f9c,stroke:#333,stroke-width:2px;
    classDef api fill:#ff9,stroke:#333,stroke-width:2px;
    classDef core fill:#bbf,stroke:#333,stroke-width:2px;
    classDef modular fill:#bfb,stroke:#333,stroke-width:2px;
    classDef library fill:#fcf,stroke:#333,stroke-width:2px;
    classDef config fill:#cff,stroke:#333,stroke-width:2px;
    classDef external fill:#f99,stroke:#333,stroke-width:2px;

    %% Click Events
    click A "https://github.com/galaxy-vn/chemdah/blob/master/src/main/kotlin/ink/ptms/chemdah/Chemdah.kt"
    click B "https://github.com/galaxy-vn/chemdah/tree/master/src/main/kotlin/ink/ptms/chemdah/api/"
    click C "https://github.com/galaxy-vn/chemdah/tree/master/src/main/kotlin/ink/ptms/chemdah/api/event/"
    click E "https://github.com/galaxy-vn/chemdah/tree/master/src/main/kotlin/ink/ptms/chemdah/core/conversation/"
    click F "https://github.com/galaxy-vn/chemdah/tree/master/src/main/kotlin/ink/ptms/chemdah/core/quest/"
    click G "https://github.com/galaxy-vn/chemdah/tree/master/src/main/kotlin/ink/ptms/chemdah/core/database/"
    click H "https://github.com/galaxy-vn/chemdah/tree/master/src/main/java/ink/ptms/chemdah/library/redlib/"
    click I1 "https://github.com/galaxy-vn/chemdah/tree/master/src/main/kotlin/ink/ptms/chemdah/module/kether/"
    click I2 "https://github.com/galaxy-vn/chemdah/tree/master/src/main/kotlin/ink/ptms/chemdah/module/level/"
    click I3 "https://github.com/galaxy-vn/chemdah/tree/master/src/main/kotlin/ink/ptms/chemdah/module/party/"
    click I4 "https://github.com/galaxy-vn/chemdah/tree/master/src/main/kotlin/ink/ptms/chemdah/module/realms/"
    click I5 "https://github.com/galaxy-vn/chemdah/tree/master/src/main/kotlin/ink/ptms/chemdah/module/scenes/"
    click I6 "https://github.com/galaxy-vn/chemdah/tree/master/src/main/kotlin/ink/ptms/chemdah/module/ui/"
    click I7 "https://github.com/galaxy-vn/chemdah/tree/master/src/main/kotlin/ink/ptms/chemdah/module/wizard/"
    click J "https://github.com/galaxy-vn/chemdah/tree/master/src/main/resources/"
```
