# dual-iron/rwmodloader architecture

> Architecture diagram of the GitHub repository dual-iron/rwmodloader, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dual-iron/rwmodloader
- Repository: https://github.com/dual-iron/rwmodloader

## Overview

#### Purpose and deployment
Realm is a Rain World mod loader and in-game mod manager. It installs a BepInEx-based bootstrap into the game, then provides runtime loading, browser-based installation, and in-game reload support. The bundled deployment payload is under `RwBep/`, including BepInEx and Doorstop configuration (`RwBep/BepInEx/`, `RwBep/doorstop_config.ini`).

#### Executable entry points
Two C# applications form the system:
- **Installer/backend CLI**: `Backend/Program.cs` orchestrates installation, extraction, patching, downloads, and self-update behavior; its project is `Backend/Backend.csproj`.
- **In-game Realm plugin/runtime**: `Realm/Program.cs` and `Realm/EntryPoint.cs` initialize Realm inside Rain World through BepInEx. `Realm/BackendProcess.cs` bridges runtime UI actions to backend work.

#### Installation and game integration
The backend installs Realm assets, manipulates the game environment, and patches assemblies needed for compatibility:
- Archive/file installation pipeline: `Backend/IO/RealmInstaller.cs`, `Backend/IO/Extractor.cs`, `Backend/IO/Wrapper.cs`.
- Assembly transformation and metadata resolution: `Backend/Patching/AssemblyPatcher.cs`, `Backend/Patching/LegacyReferenceTransformer.cs`, `Backend/Patching/RwMetadataResolver.cs`.
- BepInEx/Unity process bootstrap is external infrastructure bundled at `RwBep/BepInEx/`; Realm itself is injected into the game process rather than serving HTTP.

#### Mod ingestion, persistence, and reload
`Realm/ModLoading/ModLoader.cs` is the central mod lifecycle coordinator. It discovers locally supplied `.zip`, `.dll`, or directory-based mods, reads Realm mod metadata, applies preferences, and refreshes mod state. Key boundaries are:
- Realm mod formats and headers: `Realm/ModLoading/RwmodFile.cs`, `Realm/ModLoading/RwmodFileHeader.cs`.
- Shared archive implementation: `Global/IO/RwmodIO.cs`, `Global/IO/RwmodHeader.cs`.
- Reload safety and game fixes: `Realm/AssemblyLoading/ReloadFixes.cs`, `Realm/ModLoading/VanillaFixes.cs`.

#### Dynamic assembly loading
Realm owns a custom assembly lifecycle rather than relying solely on default .NET loading. Assembly descriptors and pools track candidate, loaded, and reloadable mod assemblies:
`Realm/AssemblyLoading/AssemblyPool.cs`, `Realm/AssemblyLoading/LoadedAssemblyPool.cs`, and `Realm/AssemblyLoading/LoadedModAssembly.cs`.
This layer isolates mod code from the loader’s state management and enables in-game activation/reload, with known compatibility limitations for some mods.

#### In-game management UI
The runtime injects menus into Rain World for local mod management and remote browsing. `Realm/Gui/Gui.cs` provides UI coordination; menu hooks attach to the game through `Realm/Gui/Menus/ModMenuHooks.cs`. Primary surfaces are local mods (`Realm/Gui/Menus/LocalMods.cs`) and the browser (`Realm/Gui/Menus/Browser.cs`), with progress/warning presentation handled by `Realm/Logging/Progressable.cs` and `Realm/Gui/Warnings/`.

#### Remote release and browser services
The backend/runtime can retrieve release and mod-browser data over the network. The web boundary consists of download/cache/release/update concerns in `Backend/Web/Downloader.cs`, `Backend/Web/Cache.cs`, `Backend/Web/Release.cs`, and `Backend/Web/SelfUpdater.cs`. Browser UI downloads are asynchronous via `Realm/Gui/AsyncDownload.cs`; submitted browser content is associated externally with the rdb-client ecosystem mentioned in the README.

#### Shared runtime primitives
`Global/` contains cross-project contracts for results, semantic versions, temporary resources, and archive streams (`Global/Result.cs`, `Global/SemVer.cs`, `Global/IO/SpliceStream.cs`). Realm also supplies custom background job abstractions for non-blocking UI/download/loading work in `Realm/Threading/BackgroundThread.cs`, `Realm/Threading/Job.cs`, and `Realm/Threading/Task.cs`. `VirtualEnums/` is a separate extension library for safely expanding game enum-like behavior (`VirtualEnums/EnumExtender.cs`, `VirtualEnums/VirtualEnums.Impl.cs`).

Main entry points: [`Realm/EntryPoint.cs`](https://github.com/dual-iron/rwmodloader/blob/master/Realm/EntryPoint.cs) (Realm plugin entry), [`Realm/ModLoading/ModLoader.cs`](https://github.com/dual-iron/rwmodloader/blob/master/Realm/ModLoading/ModLoader.cs) (Mod loader), [`Backend/Program.cs`](https://github.com/dual-iron/rwmodloader/blob/master/Backend/Program.cs) (Backend CLI), [`Realm/Gui/Gui.cs`](https://github.com/dual-iron/rwmodloader/blob/master/Realm/Gui/Gui.cs) (In-game UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Installer backend"]
  node_backend_cli["Backend CLI<br/>C&#35; application<br/>[Program.cs]"]
  node_installer_pipeline["Install pipeline<br/>file installation<br/>[RealmInstaller.cs]"]
  node_assembly_patcher["Assembly patcher<br/>assembly transformation<br/>[AssemblyPatcher.cs]"]
  node_release_services["Release services<br/>web client<br/>[Downloader.cs]"]
end

subgraph group_runtime["Realm runtime"]
  node_realm_plugin["Realm plugin entry<br/>BepInEx plugin<br/>[EntryPoint.cs]"]
  node_backend_bridge["Backend process bridge<br/>runtime bridge<br/>[BackendProcess.cs]"]
  node_mod_loader["Mod loader<br/>mod lifecycle coordinator<br/>[ModLoader.cs]"]
  node_mod_formats["Realm mod formats<br/>mod metadata<br/>[RwmodFile.cs]"]
  node_assembly_lifecycle["Assembly lifecycle<br/>dynamic assembly loading<br/>[AssemblyPool.cs]"]
  node_reload_safety["Reload safety<br/>game compatibility<br/>[ReloadFixes.cs]"]
  node_ui_coordinator["In-game UI<br/>UI coordinator<br/>[Gui.cs]"]
  node_menu_hooks["Menu hooks<br/>game UI integration<br/>[ModMenuHooks.cs]"]
  node_local_mods_ui["Local mods UI<br/>management surface<br/>[LocalMods.cs]"]
  node_browser_ui["Browser UI<br/>remote browsing surface<br/>[Browser.cs]"]
  node_async_download["Async downloads<br/>background download<br/>[AsyncDownload.cs]"]
  node_background_jobs["Background jobs<br/>job runtime"]
end

subgraph group_shared["Shared libraries"]
  node_shared_archive["Archive I/O<br/>shared archive format<br/>[RwmodIO.cs]"]
  node_shared_primitives["Shared primitives<br/>cross-project contracts<br/>[Result.cs]"]
  node_virtual_enums["Virtual enums<br/>extension library<br/>[EnumExtender.cs]"]
end

subgraph group_external["Game bootstrap"]
  node_bepinex_bootstrap{{"BepInEx bootstrap<br/>bundled infrastructure"}}
  node_rain_world["Rain World<br/>host game process"]
end

node_backend_cli -->|"runs"| node_installer_pipeline
node_backend_cli -->|"invokes"| node_assembly_patcher
node_backend_cli -->|"uses"| node_release_services
node_installer_pipeline -->|"installs payload"| node_bepinex_bootstrap
node_assembly_patcher -->|"patches assemblies"| node_rain_world
node_bepinex_bootstrap -->|"bootstraps"| node_rain_world
node_bepinex_bootstrap -->|"loads"| node_realm_plugin
node_realm_plugin -->|"initializes"| node_mod_loader
node_realm_plugin -->|"initializes"| node_ui_coordinator
node_realm_plugin -->|"uses"| node_backend_bridge
node_mod_loader -->|"reads metadata"| node_mod_formats
node_mod_formats -->|"uses"| node_shared_archive
node_mod_loader -->|"activates and reloads"| node_assembly_lifecycle
node_mod_loader -->|"applies fixes"| node_reload_safety
node_mod_loader -->|"schedules work"| node_background_jobs
node_ui_coordinator -->|"injects through"| node_menu_hooks
node_menu_hooks -->|"attaches menus"| node_rain_world
node_ui_coordinator -->|"hosts"| node_local_mods_ui
node_ui_coordinator -->|"hosts"| node_browser_ui
node_browser_ui -->|"starts"| node_async_download
node_async_download -->|"runs on"| node_background_jobs
node_async_download -->|"retrieves content"| node_release_services
node_backend_bridge -.->|"delegates actions"| node_backend_cli
node_realm_plugin -->|"uses"| node_virtual_enums
node_backend_cli -->|"uses"| node_shared_primitives
node_realm_plugin -->|"uses"| node_shared_primitives

click node_backend_cli "https://github.com/dual-iron/rwmodloader/blob/master/Backend/Program.cs"
click node_installer_pipeline "https://github.com/dual-iron/rwmodloader/blob/master/Backend/IO/RealmInstaller.cs"
click node_assembly_patcher "https://github.com/dual-iron/rwmodloader/blob/master/Backend/Patching/AssemblyPatcher.cs"
click node_release_services "https://github.com/dual-iron/rwmodloader/blob/master/Backend/Web/Downloader.cs"
click node_realm_plugin "https://github.com/dual-iron/rwmodloader/blob/master/Realm/EntryPoint.cs"
click node_backend_bridge "https://github.com/dual-iron/rwmodloader/blob/master/Realm/BackendProcess.cs"
click node_mod_loader "https://github.com/dual-iron/rwmodloader/blob/master/Realm/ModLoading/ModLoader.cs"
click node_mod_formats "https://github.com/dual-iron/rwmodloader/blob/master/Realm/ModLoading/RwmodFile.cs"
click node_assembly_lifecycle "https://github.com/dual-iron/rwmodloader/blob/master/Realm/AssemblyLoading/AssemblyPool.cs"
click node_reload_safety "https://github.com/dual-iron/rwmodloader/blob/master/Realm/AssemblyLoading/ReloadFixes.cs"
click node_ui_coordinator "https://github.com/dual-iron/rwmodloader/blob/master/Realm/Gui/Gui.cs"
click node_menu_hooks "https://github.com/dual-iron/rwmodloader/blob/master/Realm/Gui/Menus/ModMenuHooks.cs"
click node_local_mods_ui "https://github.com/dual-iron/rwmodloader/blob/master/Realm/Gui/Menus/LocalMods.cs"
click node_browser_ui "https://github.com/dual-iron/rwmodloader/blob/master/Realm/Gui/Menus/Browser.cs"
click node_async_download "https://github.com/dual-iron/rwmodloader/blob/master/Realm/Gui/AsyncDownload.cs"
click node_background_jobs "https://github.com/dual-iron/rwmodloader/blob/master/Realm/Threading/BackgroundThread.cs"
click node_shared_archive "https://github.com/dual-iron/rwmodloader/blob/master/Global/IO/RwmodIO.cs"
click node_shared_primitives "https://github.com/dual-iron/rwmodloader/blob/master/Global/Result.cs"
click node_virtual_enums "https://github.com/dual-iron/rwmodloader/blob/master/VirtualEnums/EnumExtender.cs"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_backend_cli,node_installer_pipeline,node_assembly_patcher,node_release_services toneBlue
class node_realm_plugin,node_backend_bridge,node_mod_loader,node_mod_formats,node_assembly_lifecycle,node_reload_safety,node_ui_coordinator,node_menu_hooks,node_local_mods_ui,node_browser_ui,node_async_download,node_background_jobs toneAmber
class node_shared_archive,node_shared_primitives,node_virtual_enums toneMint
class node_bepinex_bootstrap,node_rain_world toneRose
```

## Components

### Installer backend

CLI installation and release operations.

- [Backend CLI](https://github.com/dual-iron/rwmodloader/blob/master/Backend/Program.cs): C# application · Orchestrates install, patch, download, and self-update actions. · `Backend/Program.cs`
- [Install pipeline](https://github.com/dual-iron/rwmodloader/blob/master/Backend/IO/RealmInstaller.cs): file installation · Installs, extracts, and wraps Realm assets. · `Backend/IO/RealmInstaller.cs`
- [Assembly patcher](https://github.com/dual-iron/rwmodloader/blob/master/Backend/Patching/AssemblyPatcher.cs): assembly transformation · Patches game assemblies with legacy-reference and metadata support. · `Backend/Patching/AssemblyPatcher.cs`
- [Release services](https://github.com/dual-iron/rwmodloader/blob/master/Backend/Web/Downloader.cs): web client · Downloads, caches, resolves releases, and self-updates. · `Backend/Web/Downloader.cs`

### Realm runtime

In-game plugin, loading lifecycle, and UI.

- [Realm plugin entry](https://github.com/dual-iron/rwmodloader/blob/master/Realm/EntryPoint.cs): BepInEx plugin · Initializes Realm inside the Rain World process. · `Realm/EntryPoint.cs`
- [Backend process bridge](https://github.com/dual-iron/rwmodloader/blob/master/Realm/BackendProcess.cs): runtime bridge · Connects in-game actions to backend work. · `Realm/BackendProcess.cs`
- [Mod loader](https://github.com/dual-iron/rwmodloader/blob/master/Realm/ModLoading/ModLoader.cs): mod lifecycle coordinator · Discovers mods, applies preferences, and refreshes state. · `Realm/ModLoading/ModLoader.cs`
- [Realm mod formats](https://github.com/dual-iron/rwmodloader/blob/master/Realm/ModLoading/RwmodFile.cs): mod metadata · Defines Realm mod files and headers. · `Realm/ModLoading/RwmodFile.cs`
- [Assembly lifecycle](https://github.com/dual-iron/rwmodloader/blob/master/Realm/AssemblyLoading/AssemblyPool.cs): dynamic assembly loading · Tracks candidate, loaded, and reloadable mod assemblies. · `Realm/AssemblyLoading/AssemblyPool.cs`
- [Reload safety](https://github.com/dual-iron/rwmodloader/blob/master/Realm/AssemblyLoading/ReloadFixes.cs): game compatibility · Applies reload and vanilla-game fixes. · `Realm/AssemblyLoading/ReloadFixes.cs`
- [In-game UI](https://github.com/dual-iron/rwmodloader/blob/master/Realm/Gui/Gui.cs): UI coordinator · Coordinates Realm management menus. · `Realm/Gui/Gui.cs`
- [Menu hooks](https://github.com/dual-iron/rwmodloader/blob/master/Realm/Gui/Menus/ModMenuHooks.cs): game UI integration · Attaches Realm menus to Rain World. · `Realm/Gui/Menus/ModMenuHooks.cs`
- [Local mods UI](https://github.com/dual-iron/rwmodloader/blob/master/Realm/Gui/Menus/LocalMods.cs): management surface · `Realm/Gui/Menus/LocalMods.cs`
- [Browser UI](https://github.com/dual-iron/rwmodloader/blob/master/Realm/Gui/Menus/Browser.cs): remote browsing surface · `Realm/Gui/Menus/Browser.cs`
- [Async downloads](https://github.com/dual-iron/rwmodloader/blob/master/Realm/Gui/AsyncDownload.cs): background download · Keeps browser downloads non-blocking. · `Realm/Gui/AsyncDownload.cs`
- [Background jobs](https://github.com/dual-iron/rwmodloader/blob/master/Realm/Threading/BackgroundThread.cs): job runtime · Runs loading and download work off the UI path. · `Realm/Threading/BackgroundThread.cs`

### Shared libraries

Cross-project primitives and extensions.

- [Archive I/O](https://github.com/dual-iron/rwmodloader/blob/master/Global/IO/RwmodIO.cs): shared archive format · Implements shared rwmod archive and header handling. · `Global/IO/RwmodIO.cs`
- [Shared primitives](https://github.com/dual-iron/rwmodloader/blob/master/Global/Result.cs): cross-project contracts · Provides results, versions, temporary resources, and streams. · `Global/Result.cs`
- [Virtual enums](https://github.com/dual-iron/rwmodloader/blob/master/VirtualEnums/EnumExtender.cs): extension library · Safely expands game enum-like behavior. · `VirtualEnums/EnumExtender.cs`

### Game bootstrap

Bundled and host-process integration boundary.

- **BepInEx bootstrap**: bundled infrastructure · Bootstraps Realm injection into the Unity game process.
- **Rain World**: host game process

## Connections

- Backend CLI → Install pipeline: runs
- Backend CLI → Assembly patcher: invokes
- Backend CLI → Release services: uses
- Install pipeline → BepInEx bootstrap: installs payload
- Assembly patcher → Rain World: patches assemblies
- BepInEx bootstrap → Rain World: bootstraps
- BepInEx bootstrap → Realm plugin entry: loads
- Realm plugin entry → Mod loader: initializes
- Realm plugin entry → In-game UI: initializes
- Realm plugin entry → Backend process bridge: uses
- Mod loader → Realm mod formats: reads metadata
- Realm mod formats → Archive I/O: uses
- Mod loader → Assembly lifecycle: activates and reloads
- Mod loader → Reload safety: applies fixes
- Mod loader → Background jobs: schedules work
- In-game UI → Menu hooks: injects through
- Menu hooks → Rain World: attaches menus
- In-game UI → Local mods UI: hosts
- In-game UI → Browser UI: hosts
- Browser UI → Async downloads: starts
- Async downloads → Background jobs: runs on
- Async downloads → Release services: retrieves content
- Backend process bridge → Backend CLI: delegates actions
- Realm plugin entry → Virtual enums: uses
- Backend CLI → Shared primitives: uses
- Realm plugin entry → Shared primitives: uses
