# x606/modbot architecture

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

- Interactive diagram: https://gitdiagram.com/x606/modbot
- Repository: https://github.com/x606/modbot

## Overview

##### Main System Components
- Core Mod Loader (Mod Bot): This is the heart of the system. It contains modules for injecting mod code during runtime, handling mod downloads and management, patching game code, managing UI elements, and reflecting/injecting into the host game.
- Injection & Patching Modules: Found in folders such as InjectionClasses, Internal/Patches, and Internal/Reflection. These manage code injection (using techniques likely tied to Harmony and reflection) into the game process.
- Mod Handling & Utilities: Located under Mod Bot/ModHandling, ModUtilities, and ModdedUpgrades. This side of the system deals with downloading mods, managing mod metadata, handling upgrades, and providing supportive functions from the ModLibrary namespace.
- Scripting Support: The Internal/Scripting folder (with support for JavaScript and Lua script objects) shows that the system supports runtime scripting to extend functionality in a dynamic way.
- Unity Integration/Plugin: The UnityProject directory contains Unity assets, prefabs, scenes, and a “Mod-Bot Unity plugin.” This indicates that parts of the system integrate with the game’s frontend (UI, asset bundles, level editors) leveraging Unity’s rendering and asset pipelines.
- Website/API Integration: The ModBotWebsiteAPI folder indicates integration with an external website (modbot.org) for actions like the “!modsuggest <mod id>” command and scenarios where commands or mod suggestions are received from Twitch.
- External Dependencies: The UsedDlls folder (and references in the built version) is used to integrate critical dependencies from the game (e.g., Harmony, SharpZipLib, ModLibrary DLLs).

##### Interactions and Data Flow
- The Mod Handling and Utilities modules receive mod data (download info, metadata, settings) and pass it to the Core for processing. Show bidirectional flows where configuration data, mod loading, and error management are exchanged.
- The Website/API component communicates externally. Link “ModBotWebsiteAPI” with the Core to reflect the Twitch command processing and mod suggestion functionality. Show an external internet boundary labeled “modbot.org” for website interactions.

##### Architectural Patterns and Technologies
- Dependency Injection / Reflection: Note that the system uses injection techniques (as shown by Injections.cs and Reflection folders) to manage dynamic behavior.
- Integration with External Systems: Add a note regarding integration technologies such as the Harmony library for patching, and that Unity is used for front-end challenges.
- Testing: Include a nod to the ModBotUnitTests module, emphasizing that the system is also designed to be testable.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Systems
    Game["Clone Drone Game"]:::external
    WebExt["modbot.org"]:::external

    %% Injection/Patching Layer
    subgraph "Injection/Patching Layer"
        InjClasses["InjectionClasses"]:::injection
        Patches["Internal/Patches"]:::injection
        Reflection["Internal/Reflection"]:::injection
    end

    %% Core Processing Layer
    CoreMod["Core Mod Loader"]:::core

    %% Mod Handling & Utilities Layer
    subgraph "Mod Handling & Utilities"
        ModHandling["ModHandling"]:::modhandling
        ModUtilities["ModUtilities"]:::modhandling
        ModdedUpgrades["ModdedUpgrades"]:::modhandling
    end

    %% Scripting Layer
    Scripting["Scripting Support"]:::scripting

    %% Unity Integration Layer
    UnityPlugin["Unity Plugin Module"]:::unity

    %% Website/API Integration
    WebsiteAPI["Website/API Integration"]:::website

    %% External Dependencies
    Dependencies["External Dependencies"]:::dependencies

    %% Data Flow Connections
    %% External Game to Injection Modules
    Game --> InjClasses
    Game --> Patches
    Game --> Reflection

    %% Injection Modules to Core
    InjClasses --> CoreMod
    Patches --> CoreMod
    Reflection --> CoreMod

    %% External Dependencies to Injection and Core
    Dependencies --- InjClasses
    Dependencies --- CoreMod

    %% Mod Handling & Utilities bidirectional with Core
    ModHandling <--> CoreMod
    ModUtilities <--> CoreMod
    ModdedUpgrades <--> CoreMod

    %% Scripting Support to Core
    Scripting --> CoreMod

    %% Unity Integration bidirectional with Core
    CoreMod <--> UnityPlugin

    %% Website/API Integration bidirectional with Core and external web
    CoreMod <--> WebsiteAPI
    WebsiteAPI <--> WebExt

    %% Styling Classes
    classDef core fill:#a8d5ba,stroke:#333,stroke-width:1px;
    classDef injection fill:#add8e6,stroke:#333,stroke-width:1px;
    classDef modhandling fill:#f3e79b,stroke:#333,stroke-width:1px;
    classDef scripting fill:#f8bbd0,stroke:#333,stroke-width:1px;
    classDef unity fill:#ffcc80,stroke:#333,stroke-width:1px;
    classDef website fill:#d1c4e9,stroke:#333,stroke-width:1px;
    classDef external fill:#ffe0b2,stroke:#333,stroke-width:1px;
    classDef dependencies fill:#cfd8dc,stroke:#333,stroke-width:1px;

    %% Click Events
    click CoreMod "https://github.com/x606/modbot/tree/master/Mod Bot"
    click InjClasses "https://github.com/x606/modbot/tree/master/InjectionClasses"
    click Patches "https://github.com/x606/modbot/tree/master/Mod Bot/Internal/Patches"
    click Reflection "https://github.com/x606/modbot/tree/master/Mod Bot/Internal/Reflection"
    click ModHandling "https://github.com/x606/modbot/tree/master/Mod Bot/ModHandling"
    click ModUtilities "https://github.com/x606/modbot/tree/master/Mod Bot/ModUtilities"
    click ModdedUpgrades "https://github.com/x606/modbot/tree/master/Mod Bot/ModdedUpgrades"
    click Scripting "https://github.com/x606/modbot/tree/master/Mod Bot/Internal/Scripting"
    click UnityPlugin "https://github.com/x606/modbot/tree/master/UnityProject/Assets/Mod-Bot Unity plugin"
    click WebsiteAPI "https://github.com/x606/modbot/tree/master/ModBotWebsiteAPI"
    click Dependencies "https://github.com/x606/modbot/tree/master/UsedDlls"
```
