# mrmystery-official/starlight-dev architecture

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

- Interactive diagram: https://gitdiagram.com/mrmystery-official/starlight-dev
- Repository: https://github.com/mrmystery-official/starlight-dev

## Overview

##### Project type and purpose
- AINB Editor (visual node-based AI behavior editor)
- Editor (scene/actor placement and manipulation)
- Actor Editor (basic actor creation/customization)
- It uses OpenGL for rendering, ImGui for the UI, and a collection of bundled third-party libraries for math, BVH construction, navigation mesh generation, file dialogs, and asset formats.

##### File structure
- Top level:
- MapEditor.sln + Main.cpp → entry point
- MapEditor/… .cpp/.h → core modules organized by feature (ActorMgr, SceneMgr/Creator/Exporter, NavMeshGenerator, Asset readers/writers, UI classes)
- MapEditor/Assets → built-in models, shaders, fonts, textures used at runtime
- MapEditor/Libraries → bundled external libraries (GLFW, Glad, GLM, stb, zstd)
- MapEditor/imgui + imgui_node_editor + imgui_gizmo → GUI frameworks/extensions
- MapEditor/recastnavigation, bvh, meshDecimation → navigation and acceleration-structure engines
- No separate “frontend” vs. “backend” directories—this is a single C++ codebase, but it naturally separates into layers:

##### Extract README insights
- Describes user workflows (point & click configuration of RomFS and model dumps, then restart with proper paths).

##### Main components
A. UI Layer
- ImGui core + extensions (node editor, gizmo)
- PopupMgr + UI*.cpp classes handle user interactions
B. Core Application & Editor Logic
- Editor (Editor.cpp/h) orchestrates sub-tools
- SceneMgr / SceneCreator / SceneExporter
- ActorMgr / AssetManagers (TextureMgr, ShaderMgr, BufferObject, etc.)
- NavMeshGenerator + BVHBuilder for pathfinding geometry
- BinaryVectorReader/Writer, Bfres, EXB, MSBT, SARC, RESTBL modules parse and write game formats
- PhiveWrapper, PhiveMaterialData, PhiveNavMesh for physics integration
C. Rendering & Graphics
- GLFW window + input
- Glad + OpenGL calls via BufferObject / VAO / VBO / FramebufferMgr
- Shaders loaded from Assets/Shaders
D. Third-Party Libraries
- Math & linear algebra: GLM
- Compression: zstd
- Image loading/writing: stb_image, stb_image_write
- Navigation: recastnavigation (Recast + Detour)
- BVH: custom bvh folder
- Mesh decimation: meshDecimation
- File dialogs: tinyfiledialogs
E. File System & External Data
- User-supplied RomFS dump, model dump folders
- Local “Assets” shipped with the app
- Config files (EditorConfig, PreferencesConfig, NodeEditor.json, imgui.ini)

##### Relationships & interactions
- UI → Core Editor Logic: User clicks menu or tools → PopupMgr/UI classes call Editor APIs
- Core Logic → Data Parsers: Editor invokes BinaryVectorReader, Bfres, MSBT, etc. to load or modify game data
- Core Logic → Asset Managers: AssetManagers prepare GPU resources from loaded data
- Asset Managers → Rendering: BufferObject/VAO/VBO push to GPU; ShaderMgr selects and binds shaders
- Core Logic → NavMeshGenerator/BVHBuilder → recastnavigation: For physics/navigation previews
- Core Logic → Exporter: Write modified scenes or AINB graphs back to game formats
- File System ↔ Data Parsers & Exporter: read/write files on disk

##### Architectural patterns & design principles
- Layered architecture:
- UI at the top
- Application logic in the middle (tool/controllers, scene graph)
- Rendering engine & data parsing at the bottom
- Modular feature components: each tool (AINB, Map, Actor) has its own “manager” classes and UI handlers
- Resource management: centralized managers for shaders, textures, buffers
- Use of dependency inversion: core modules depend on abstract data-reader interfaces (BinaryVectorReader) allowing new file formats to be pluggable

##### Detailed element checklist
- Which modules depend on which parsers or managers
- Main data flows (load, modify, render, export) with arrowheads
- ImGui-based UI components separately from core logic

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        direction TB
        ImGuiCore["ImGui Core"]:::ui
        NodeEditor["ImGui Node Editor"]:::ui
        Gizmo["ImGui Gizmo"]:::ui
        PopupMgr["PopupMgr & Panels"]:::ui
        UIWidgets["UI Widgets & Tools"]:::ui
    end

    %% Core Logic
    subgraph "Core Application & Editor Logic"
        direction TB
        Main["Main.cpp"]:::core
        Editor["Editor.cpp/.h"]:::core
        SceneMgr["SceneMgr"]:::core
        SceneCreator["SceneCreator"]:::core
        SceneExporter["SceneExporter"]:::core
        ActorMgr["ActorMgr"]:::core
        AINBEditor["AINB Editor"]:::core
        DataParsers["Data Parsers & Writers"]:::core
        Phive["Phive Integration"]:::core
    end

    %% Rendering Engine
    subgraph "Rendering & Graphics Engine"
        direction TB
        GLFW_Glad["GLFW & Glad"]:::render
        GPUResources["BufferObject/VAO/VBO/FramebufferMgr"]:::render
        ShaderMgr["Shader & ShaderMgr"]:::render
        MeshCam["Mesh & Camera"]:::render
    end

    %% Third-Party Libraries
    subgraph "Third-Party Libraries"
        direction TB
        GLM["GLM (Math)"]:::third
        STB["stb_image / stb_image_write"]:::third
        ZSTD["zstd"]:::third
        FileDialog["tinyfiledialogs"]:::third
        Recast["Recast & Detour"]:::third
        BVH["BVH Construction"]:::third
        MeshDec["Mesh Decimation"]:::third
    end

    %% External Data & File System
    subgraph "File System & External Data"
        direction TB
        Assets["Built-in Assets"]:::fs
        Configs["Config Files"]:::fs
        RomFS["RomFS & Model Dumps"]:::fs
    end

    %% Connections
    ImGuiCore -->|uses| Editor
    NodeEditor -->|uses| Editor
    Gizmo -->|uses| Editor
    PopupMgr -->|invokes| Editor
    UIWidgets -->|invokes| Editor

    Editor -->|orchestrates| SceneMgr
    Editor -->|orchestrates| ActorMgr
    Editor -->|orchestrates| AINBEditor
    SceneMgr -->|creates/exports| SceneCreator
    SceneMgr -->|creates/exports| SceneExporter
    Editor -->|loads/writes| DataParsers
    Editor -->|integrates| Phive

    Editor -->|renders via| GLFW_Glad
    GLFW_Glad -->|initializes| GPUResources
    GPUResources -->|binds| ShaderMgr
    GPUResources -->|draws| MeshCam

    DataParsers -->|read/write| RomFS
    SceneExporter -->|writes| RomFS
    DataParsers -->|reads| Assets
    Editor -->|reads| Configs

    GLFW_Glad -->|links| GLM
    GPUResources -->|uses| STB
    ShaderMgr -->|compresses| ZSTD
    UIWidgets -->|dialogs| FileDialog
    SceneMgr -->|navmesh| Recast
    SceneMgr -->|bvh| BVH
    SceneMgr -->|decimation| MeshDec

    %% Click Events
    click ImGuiCore "https://github.com/mrmystery-official/starlight-dev/tree/main/MapEditor/imgui/"
    click NodeEditor "https://github.com/mrmystery-official/starlight-dev/tree/main/MapEditor/imgui_node_editor/"
    click Gizmo "https://github.com/mrmystery-official/starlight-dev/tree/main/MapEditor/imgui_gizmo/"
    click PopupMgr "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/PopupMgr.cpp"
    click UIWidgets "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/UI.cpp"
    click Main "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/Main.cpp"
    click Editor "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/Editor.cpp"
    click SceneMgr "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/SceneMgr.cpp"
    click SceneCreator "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/SceneCreator.cpp"
    click SceneExporter "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/SceneExporter.cpp"
    click ActorMgr "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/ActorMgr.cpp"
    click AINBEditor "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/AINB.cpp"
    click DataParsers "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/BinaryVectorReader.cpp"
    click Phive "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/PhiveWrapper.cpp"
    click GLFW_Glad "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/glad.c"
    click GPUResources "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/BufferObject.cpp"
    click ShaderMgr "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/ShaderMgr.cpp"
    click MeshCam "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/Camera.cpp"
    click GLM "https://github.com/mrmystery-official/starlight-dev/tree/main/MapEditor/Libraries/include/glm/"
    click STB "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/Libraries/include/stb/stb_image.h"
    click ZSTD "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/Libraries/include/zstd.h"
    click FileDialog "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/tinyfiledialogs.c"
    click Recast "https://github.com/mrmystery-official/starlight-dev/tree/main/MapEditor/recastnavigation/recast/"
    click BVH "https://github.com/mrmystery-official/starlight-dev/tree/main/MapEditor/bvh/"
    click MeshDec "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/meshDecimation/mdMeshDecimator.cpp"
    click Assets "https://github.com/mrmystery-official/starlight-dev/tree/main/MapEditor/Assets/"
    click Configs "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/EditorConfig.cpp"
    click RomFS "https://github.com/mrmystery-official/starlight-dev/blob/main/MapEditor/NodeEditor.json"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366D6,color:#0366D6;
    classDef core fill:#E6F4EA,stroke:#28A745,color:#28A745;
    classDef render fill:#FFF4E5,stroke:#D9822B,color:#D9822B;
    classDef third fill:#F0F0F0,stroke:#6A737D,color:#6A737D;
    classDef fs fill:#F5EBDD,stroke:#8A3FFC,color:#8A3FFC
```
