# schedulelua/schedulelua-framework architecture

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

- Interactive diagram: https://gitdiagram.com/schedulelua/schedulelua-framework
- Repository: https://github.com/schedulelua/schedulelua-framework

## Overview

##### Main components
- Loader & Host (MelonLoader / Unity) – the game engine entry point
- Core Framework – manages module registration, error handling, mod lifecycle
- Lua Engine (MoonSharp) – hosts and executes user scripts
- API Registry & Modules – C# bindings exposed to Lua (API/Base, Core, Economy, Law, NPC, Player, UI, etc.)
- Mod Management – discovers, loads, and configures Lua mods (Core/Framework/Mods)
- User Scripts & Resources – Lua files and example mods in Resources/
- External Dependencies – Unity types (proxies), MelonPreferences, MoonSharp library

##### Relationships and data flows
- Game Launch → MelonLoader initializes ScheduleLua (ModCore.cs)
- ModCore → Core Framework sets up ApiRegistry
- Core → registers each ILuaApiModule (all API/* folders)
- ApiRegistry ↔ MoonSharp: injects C# modules into the Lua environment
- Lua Engine → loads scripts from Resources/ and user folders → executes on game events
- Lua scripts → call API modules → proxy calls to Unity engine (via TypeProxies)
- UI modules (API/UI & API/Apps) → create in-game dialogs, phones, windows
- Mod Manager UI (Core/Framework/Mods/ManagerUI) ↔ MelonPreferences for config
- Error Handler intercepts script exceptions → logs via Unity console

##### Architectural patterns
- Plugin / Module registry – each API is an independent module implementing ILuaApiModule
- Proxy pattern – Unity engine types are wrapped by “Proxy” classes to safe-expose methods/properties
- Event-driven – Lua scripts subscribe to game events (day changes, player updates)
- Hot-Reload – Watcher in Core Framework triggers re-execution of scripts at runtime

##### Technologies & frameworks to call out
- MoonSharp (.NET Lua interpreter)
- MelonLoader (Unity mod loader)
- Unity Engine (Schedule I game types)
- C# .NET Standard (project code)
- MelonPreferences (config storage)

##### Essential elements to capture
- The startup sequence (MelonLoader → ModCore → ApiRegistry → Lua VM)
- Module registration and injection into the Lua context
- Script loading and hot-reload loop
- API calls flowing through proxies into Unity engine
- Error handling path

Putting it all together:
– Show API Modules calling “Unity Engine (Proxies)” as needed.
– Off to the side, show “Mod Manager UI” talking to “MelonPreferences (Config)”.
– Finally, annotate hot-reload and error-handler loops around the Lua VM.

## Diagram (Mermaid)

```mermaid
flowchart TD
    classDef core fill:#ADD8E6,stroke:#000
    classDef api fill:#90EE90,stroke:#000
    classDef lua fill:#FFA500,stroke:#000
    classDef external fill:#D3D3D3,stroke:#000

    subgraph "Host Environment"
        ML["MelonLoader"]:::external
        UE["Unity Engine"]:::external
        ML --> UE

        subgraph "Core Framework"
            MC["ModCore"]:::core
            AR["ApiRegistry"]:::core
            EH["Error Handler"]:::core
            HR["Hot-Reload & Script Host"]:::core

            MC --> AR
            AR --> HR
            HR --> AR
            EH --> MC
        end

        ML --> MC
    end

    subgraph "API Modules"
        Base["Base API Modules"]:::api
        CoreAPI["Core API & Proxies"]:::api
        AppsUI["Apps & UI Modules"]:::api
        Economy["EconomyAPI"]:::api
        Law["LawAPI"]:::api
        NPC["NPCAPI"]:::api
        Player["PlayerAPI"]:::api
        Scene["SceneAPI"]:::api
        World["World APIs"]:::api
        Registry["Registry & Commands"]:::api
        Windows["Windows API"]:::api
    end

    AR --> Base
    AR --> CoreAPI
    AR --> AppsUI
    AR --> Economy
    AR --> Law
    AR --> NPC
    AR --> Player
    AR --> Scene
    AR --> World
    AR --> Registry
    AR --> Windows

    subgraph "Lua Engine"
        VM["MoonSharp VM"]:::external
        US["User Lua Scripts"]:::lua
    end

    AR --> VM
    VM -->|"loads & executes"| US
    US --> AR

    subgraph "Mod Management"
        MM["Mod Manager"]:::core
        MUI["Manager UI"]:::core
        MCFS["Config Storage"]:::core

        MM --> MUI
        MUI --> MCFS
    end

    MUI -->|"uses"| MP["MelonPreferences"]:::external

    %% Proxies calls to Unity Engine
    Base --> UE
    CoreAPI --> UE
    AppsUI --> UE
    Economy --> UE
    Law --> UE
    NPC --> UE
    Player --> UE
    Scene --> UE
    World --> UE
    Registry --> UE
    Windows --> UE

    %% Hot-reload and error loops
    HR --> US
    EH --> US

    %% Click Events
    click MC "https://github.com/schedulelua/schedulelua-framework/blob/main/ModCore.cs"
    click AR "https://github.com/schedulelua/schedulelua-framework/blob/main/Core/Framework/ApiRegistry.cs"
    click EH "https://github.com/schedulelua/schedulelua-framework/blob/main/Core/Framework/LuaScriptErrorHandler.cs"
    click HR "https://github.com/schedulelua/schedulelua-framework/blob/main/Core/Framework/LuaAPI.cs"
    click HR "https://github.com/schedulelua/schedulelua-framework/blob/main/Core/Framework/LuaScript.cs"
    click MM "https://github.com/schedulelua/schedulelua-framework/blob/main/Core/Framework/Mods/ModManager.cs"
    click MUI "https://github.com/schedulelua/schedulelua-framework/blob/main/Core/Framework/Mods/ManagerUI/ModManagerUIController.cs"
    click MCFS "https://github.com/schedulelua/schedulelua-framework/blob/main/Core/Framework/Mods/ManagerUI/ModManagerConfigStorage.cs"
    click Base "https://github.com/schedulelua/schedulelua-framework/tree/main/API/Base"
    click CoreAPI "https://github.com/schedulelua/schedulelua-framework/tree/main/API/Core"
    click AppsUI "https://github.com/schedulelua/schedulelua-framework/tree/main/API/Apps"
    click Economy "https://github.com/schedulelua/schedulelua-framework/blob/main/API/Economy/EconomyAPI.cs"
    click Law "https://github.com/schedulelua/schedulelua-framework/blob/main/API/Law/LawAPI.cs"
    click NPC "https://github.com/schedulelua/schedulelua-framework/blob/main/API/NPC/NPCAPI.cs"
    click Player "https://github.com/schedulelua/schedulelua-framework/blob/main/API/Player/PlayerAPI.cs"
    click Scene "https://github.com/schedulelua/schedulelua-framework/blob/main/API/Scene/SceneAPI.cs"
    click World "https://github.com/schedulelua/schedulelua-framework/blob/main/API/World/TimeAPI.cs"
    click Registry "https://github.com/schedulelua/schedulelua-framework/blob/main/API/Registry/RegistryAPI.cs"
    click Windows "https://github.com/schedulelua/schedulelua-framework/blob/main/API/Windows/WindowsAPI.cs"
    click US "https://github.com/schedulelua/schedulelua-framework/tree/main/Resources"
```
