# scope-sl/scope architecture

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

- Interactive diagram: https://gitdiagram.com/scope-sl/scope
- Repository: https://github.com/scope-sl/scope

## Overview

##### Project Type and Purpose
- The project is essentially a modding API and client aimed at facilitating mod development and integration for the SCP:SL game.
- The structure indicates a modular architecture with distinct responsibilities split across API functionality, event hooking/patching, asset management, and a custom loader along with an installer. This is characteristic of a client-side mod framework.

##### Main Components
a. Client Core: This comprises the central executable entry given by Scope.Client – this is where the client logic and integration with the game live (for example, the “ClientComponent.cs” and the main “Scope.Client.csproj” file).
b. API Module:
– Contains directories like “API/Enums”, “API/Extensions”, “API/Features”, “API/Interfaces”, and “API/Features/Packets.”
– These provide enumeration constants, utility extensions (for data handling and reflection), core modding features (such as mod management, coroutine support, hardware interfacing, logging, etc.), and packet definitions for communication between the mod client and possibly the game or other mod components.
c. Events Subsystem:
– Organized under “Events,” this subsystem handles a range of functionalities including event arguments (e.g., client connection events, scene loading, game state events) and event handlers.
– It also contains several “Patches” directories (for Authentication, MainMenu, QueryProcessor, TransmissionNetwork) that likely use runtime patching or hooking to intercept game processes.
d. Loader Module:
– Under “Loader,” key classes such as “BepInExLoader.cs”, “Loader.cs”, and configuration management files (e.g., “Config.cs”, “Paths.cs”) indicate a dedicated component responsible for loading and injecting the mod or handling the mod’s initialization sequence.
– It also includes support files (like the “UnhollowerSupport” folder) enhancing compatibility or integration with underlying game frameworks.
e. AssetBundle Management:
– The “AssetBundle” directory holds classes for managing asset bundles (e.g., “Il2CppAssetBundle.cs”, “Il2CppAssetBundleManager.cs”), which suggests this component deals with dynamic resource loading, likely required for mod assets.
f. Installer:
– A separate project under “Scope.Installer” deals with the installation process (for example, setting up the mod client and ensuring all components are correctly deployed).
g. Supporting/Configuration Files:
– Files like .editorconfig, .gitignore, and StyleCop settings indicate standard coding practices but are peripheral to architecture.
– The solution file (Scope.sln) ties the multiple projects together.

##### Relationships and Interactions
- The Loader is central to bootstrapping the client—all API modules, event modules, and asset bundle managers are loaded/initialized through it.
- The API provides the core modding “language” that mod developers will use. It interacts with the Client Core to intercept or modify game behavior.
- The Events Subsystem provides hooks and patching layers to modify game behavior dynamically. Its patches (e.g., Authentication patches, QueryProcessor patches) are applied at various points in the game’s execution.
- The AssetBundle Management component works in tandem with the API and Loader to load external assets required by mods.
- The Installer operates at a separate level (likely pre-install or a bootstrapper) to deploy the client and associated modules.

##### Architectural Patterns and Design Principles
- Modularity: Every functional area (API, Events, Loader, AssetBundle, Installer) is contained in its own module. The directory structure suggests a high level of separation of concerns.
- Extension Points: With plenty of interfaces (e.g., IConfig, IMod) and extension classes, the project is designed for extensibility.
- Patching/Hooking: The Events/Patches directories indicate runtime patches to inject custom behavior into pre-existing workflows—an essential design choice for game modding.
- Clear Dependency Injection: Although the explicit dependency injection framework isn’t spelled out, the separation implies that components likely communicate through well-defined APIs and interfaces.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Nodes
    Installer["Installer"]:::installer
    Loader["Loader Module"]:::loader
    ClientCore["Client Core"]:::core
    APIModule["API Module"]:::api
    EventsSub["Events Subsystem"]:::events
    AssetBundle["AssetBundle Management"]:::assetbundle

    %% Relationships from Installer
    Installer -->|"deploys"| Loader
    Installer -->|"deploys"| ClientCore

    %% Relationships from Loader Module
    Loader -->|"bootstraps"| ClientCore
    Loader -->|"initializes"| APIModule
    Loader -->|"initializes"| EventsSub
    Loader -->|"initializes"| AssetBundle

    %% Relationships from API Module
    APIModule -->|"modifies"| ClientCore
    APIModule -->|"triggers"| EventsSub
    APIModule -->|"requestsAssets"| AssetBundle

    %% Styles
    classDef installer fill:#FAD7A0,stroke:#D68910,stroke-width:2px
    classDef loader fill:#D5F5E3,stroke:#27AE60,stroke-width:2px
    classDef core fill:#F5B7B1,stroke:#C0392B,stroke-width:2px
    classDef api fill:#AED6F1,stroke:#2980B9,stroke-width:2px
    classDef events fill:#F9E79F,stroke:#F1C40F,stroke-width:2px
    classDef assetbundle fill:#D2B4DE,stroke:#8E44AD,stroke-width:2px

    %% Click Events
    click ClientCore "https://github.com/scope-sl/scope/blob/master/Scope.Client/ClientComponent.cs"
    click APIModule "https://github.com/scope-sl/scope/tree/master/Scope.Client/API"
    click EventsSub "https://github.com/scope-sl/scope/tree/master/Scope.Client/Events"
    click Loader "https://github.com/scope-sl/scope/tree/master/Scope.Client/Loader"
    click AssetBundle "https://github.com/scope-sl/scope/tree/master/Scope.Client/AssetBundle"
    click Installer "https://github.com/scope-sl/scope/blob/master/Scope.Installer"
```
