# goatcorp/dalamud architecture

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

- Interactive diagram: https://gitdiagram.com/goatcorp/dalamud
- Repository: https://github.com/goatcorp/dalamud

## Overview

##### Main components
- Injector and Bootstrapping Modules:
- Dalamud.Injector.Boot (C++): This module is responsible for loading the .NET Core runtime into the target process via hostfxr. It serves as the initial entry point.
- Dalamud.Injector (C#): This component then performs the DLL injection into the target process.
- Dalamud.Boot (C++): Alternatively, when not doing a full DLL injection, this component can rewrite a process’ entrypoint to start the Dalamud runtime.
- Core Framework (Managed Side):
- Dalamud (C#): The core API, game bindings, and plugin framework functionalities reside here. It is responsible for managing internal services, hooking into the game’s native data, and providing the API layer.
- Dalamud.CorePlugin (C#): A plugin used as a testbed and prototype for developing new features, demonstrating how plugins can interact with Dalamud internals.

##### Out external dependencies and libraries
- External libraries like cimgui, cimguizmo, cimplot, nlohmann-json, and others are present under the “external” and “lib” directories. Represent these as supporting libraries that the injector and core framework rely on.
- Build scripts and CI configurations (e.g., .github/workflows, build scripts, and NUKE build configuration) should also be depicted as part of the development and deployment pipeline.

##### Relationships and flow
– DLL Injection: Dalamud.Injector.Boot initiates runtime loading and hands off execution to Dalamud.Injector.
– Entry Point Rewriting: Dalamud.Boot rewrites the target process’s entrypoint to start the managed runtime.
- Once the injection is complete, the .NET Core runtime is loaded and launches the managed Dalamud component.
- The Dalamud component then initializes its services – game hooking, memory manipulation, plugin management, and API exposure – allowing plugins (including CorePlugin and any third‐party plugins) to connect.

##### Architectural patterns and technologies
- Hybrid architecture: A clear separation is visible between the native (C/C++) bootstrapping/injection components and the managed (.NET Core/C#) logic.
- Plugin extensibility: Emphasize the API layer and service interface provided by the core Dalamud framework. Mark how it interacts with game state and external game data.
- Build and deployment: Briefly note the presence of CI/CD pipelines and build scripts that automate building, signing, and testing components.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Target Process
    ffxiv["FFXIV Game (Target Process)"]:::target

    %% Native Bootstrapping Subgraph
    subgraph "Native Bootstrapping"
        injector_boot["Dalamud.Injector.Boot (Native C++)"]:::native
        boot_alt["Dalamud.Boot (Entry Point Rewrite, Native C++)"]:::native
    end

    %% Core Runtime Loader Node
    core_loader["Core Runtime Loader (.NET Core)"]:::loader

    %% Managed Runtime Subgraph
    subgraph "Managed Runtime"
        injector["Dalamud.Injector (Managed C#)"]:::managed
        core["Dalamud (Core API, Managed C#)"]:::managed
        coreplugin["Dalamud.CorePlugin (Managed Plugin Prototype)"]:::managed
    end

    %% External Dependencies Subgraph
    subgraph "External Dependencies"
        ext_ext["external (Native Libraries)"]:::external
        ext_lib["lib (Native Libraries)"]:::external
    end

    %% Build & Deployment Subgraph
    subgraph "Build & Deployment"
        github[".github (Workflows)"]:::build
        nuke[".nuke (Build Config)"]:::build
        builds["build scripts"]:::build
    end

    %%----------------------------------------------------
    %% Connections: Injection and Bootstrapping Flows

    %% FFXIV Game initiates the two boot paths
    ffxiv -->|"DLLInjection"| injector_boot
    ffxiv -->|"EntryRewrite"| boot_alt

    %% DLL Injection Flow
    injector_boot -->|"LoadRuntime"| core_loader
    core_loader --> injector

    %% Entry Point Rewriting Flow
    boot_alt --> core

    %% Managed Runtime Initialization
    injector -->|"InitializeRuntime"| core
    core -->|"InvokePluginAPI"| coreplugin

    %%----------------------------------------------------
    %% Dependencies Integration
    ext_ext -->|"supports"| injector_boot
    ext_ext -->|"supports"| boot_alt
    ext_lib -->|"supports"| injector_boot
    ext_lib -->|"supports"| boot_alt
    ext_ext -->|"assists"| core
    ext_lib -->|"assists"| core

    %% Build & Deployment Influence (dotted arrows for build pipeline)
    github ---|"builds"| injector_boot
    nuke ---|"builds"| boot_alt
    builds ---|"deploys"| core
    github ---|"builds"| injector
    nuke ---|"builds"| injector
    builds ---|"deploys"| injector

    %%----------------------------------------------------
    %% Click Events
    click injector_boot "https://github.com/goatcorp/dalamud/blob/master/Dalamud.Injector.Boot"
    click injector "https://github.com/goatcorp/dalamud/blob/master/Dalamud.Injector"
    click boot_alt "https://github.com/goatcorp/dalamud/blob/master/Dalamud.Boot"
    click core "https://github.com/goatcorp/dalamud/tree/master/Dalamud"
    click coreplugin "https://github.com/goatcorp/dalamud/blob/master/Dalamud.CorePlugin"
    click ext_ext "https://github.com/goatcorp/dalamud/tree/master/external"
    click ext_lib "https://github.com/goatcorp/dalamud/tree/master/lib"
    click github "https://github.com/goatcorp/dalamud/blob/master/.github"
    click nuke "https://github.com/goatcorp/dalamud/blob/master/.nuke"
    click builds "https://github.com/goatcorp/dalamud/blob/master/build.*"

    %%----------------------------------------------------
    %% Class Definitions for Styling
    classDef native fill:#f88,stroke:#333,stroke-width:2px,font-family:monospace;
    classDef managed fill:#bbf,stroke:#333,stroke-width:2px,font-family:monospace;
    classDef external fill:#afa,stroke:#333,stroke-width:2px,font-family:monospace;
    classDef build fill:#ffd,stroke:#333,stroke-width:2px,font-family:monospace;
    classDef target fill:#ffa,stroke:#333,stroke-width:2px,font-family:monospace;
    classDef loader fill:#fcc,stroke:#333,stroke-width:2px,font-family:monospace;
```
