# System Architecture

This section provides an overview of how OMS operates as a system.\
It shows how events flow through OMS and how addons interact with the runtime.

***

### Overview

OMS is built around a modular, event-driven architecture:

* Forge emits low-level server events
* OMS transforms them into structured events
* Addons register features and react to these events
* Features can trigger actions that affect the system

***

### System Flow

The diagram below shows how events and components interact across the system:

{% code lineNumbers="true" expandable="true" %}

```mermaid
%%{init: {
  "theme": "neutral"
}}%%

flowchart TD

%% ===================== FORGE =====================
subgraph Forge
    FORGE_REGISTER_COMMANDS_EVENT[RegisterCommandsEvent]
    FORGE_SERVER_STARTED_EVENT[ServerStartedEvent]
    FORGE_TICK_EVENT[TickEvent.ServerTickEvent]
    FORGE_SERVER_STOPPING_EVENT[ServerStoppingEvent]
end

%% ===================== OMS =====================
subgraph OMS
    subgraph OMS_API_Internal[OMS-API Internal]
        OMS_ADDON_PREPARE_EVENT[Addon.PrepareEvent]
        OMS_SERVER_READY_EVENT[Server.ReadyEvent]
        OMS_SERVER_PRE_SHUTDOWN_EVENT[Server.PreShutdownEvent]
    end
    OMS_STOP_MANAGER[StopManager]
end

%% ===================== OMS API =====================
subgraph OMS_API[OMS-API]
    OMS_API_ADDON_REGISTER_EVENT[Addon.RegisterEvent]
    OMS_API_STARTING_EVENT[StartingEvent]
    OMS_API_TICKING_EVENT[TickingEvent]
    OMS_API_STOPPING_EVENT[StoppingEvent]
    OMS_API_STOP_REQUESTED_EVENT[StopRequestedEvent]
end

%% ===================== ADDON =====================
subgraph Addon[OMS Addon]
    ADDON_REGISTER_ACTION{{"Registering addon"}}

    subgraph ADDON_CONTEXT[AddonContext]
        FEATURE_MANAGER[FeatureManager]
    end

    subgraph FEATURE[OmsFeature]
        FEATURE_ON_STARTED[onOmsStarted]
        FEATURE_ON_TICK[onOmsTick]
        FEATURE_ON_STOPPING[onOmsStopping]
        FEATURE_ON_REGISTER_CONFIG[onOmsRegisterConfig]
        FEATURE_ON_ENABLED[onEnabled]
        FEATURE_ON_DISABLED[onDisabled]
    end
end

%% ===================== FLOW =====================

%% Registration
FORGE_REGISTER_COMMANDS_EVENT --> OMS_ADDON_PREPARE_EVENT
OMS_ADDON_PREPARE_EVENT --> OMS_API_ADDON_REGISTER_EVENT
OMS_API_ADDON_REGISTER_EVENT --> ADDON_REGISTER_ACTION
ADDON_REGISTER_ACTION --> ADDON_CONTEXT

%% Starting
FORGE_SERVER_STARTED_EVENT --> OMS_SERVER_READY_EVENT
OMS_SERVER_READY_EVENT --> OMS_API_STARTING_EVENT
OMS_API_STARTING_EVENT --> ADDON_CONTEXT

%% Ticking
FORGE_TICK_EVENT --> OMS_API_TICKING_EVENT
OMS_API_TICKING_EVENT --> ADDON_CONTEXT

%% Stopping (system)
FORGE_SERVER_STOPPING_EVENT --> OMS_SERVER_PRE_SHUTDOWN_EVENT
OMS_SERVER_PRE_SHUTDOWN_EVENT --> OMS_API_STOPPING_EVENT
OMS_API_STOPPING_EVENT --> ADDON_CONTEXT

%% Action flow
OMS_STOP_MANAGER <--> OMS_API_STOP_REQUESTED_EVENT

%% Runtime execution
FEATURE_MANAGER ==> FEATURE_ON_STARTED
FEATURE_MANAGER ==> FEATURE_ON_TICK
FEATURE_MANAGER ==> FEATURE_ON_STOPPING
FEATURE_MANAGER ==> FEATURE_ON_REGISTER_CONFIG

%% ===================== STYLES =====================

classDef system fill:#eeeeee,stroke:#757575,color:#212121;
classDef runtime fill:#d9e8ff,stroke:#3f51b5,color:#1a237e;

classDef start fill:#66bb6a,stroke:#1b5e20,stroke-width:2px,color:#0d3b12;
classDef tick fill:#42a5f5,stroke:#0d47a1,stroke-width:2px,color:#0b2a4a;
classDef stop fill:#ef5350,stroke:#b71c1c,stroke-width:2px,color:#4a0b0b;

classDef muted fill:#e0e0e0,stroke:#616161,color:#212121;

class FORGE_REGISTER_COMMANDS_EVENT,OMS_ADDON_PREPARE_EVENT,OMS_API_ADDON_REGISTER_EVENT,ADDON_REGISTER_ACTION,FEATURE_ON_REGISTER_CONFIG,FEATURE_ON_ENABLED,FEATURE_ON_DISABLED system;
class ADDON_CONTEXT,FEATURE_MANAGER,OMS_STOP_MANAGER runtime;

class FORGE_SERVER_STARTED_EVENT,OMS_SERVER_READY_EVENT,OMS_API_STARTING_EVENT,FEATURE_ON_STARTED start;
class FORGE_TICK_EVENT,OMS_API_TICKING_EVENT,FEATURE_ON_TICK tick;
class FORGE_SERVER_STOPPING_EVENT,OMS_SERVER_PRE_SHUTDOWN_EVENT,OMS_API_STOPPING_EVENT,OMS_API_STOP_REQUESTED_EVENT,FEATURE_ON_STOPPING stop;

style Forge fill:#ffffff,stroke:#9e9e9e,stroke-width:2px
style OMS fill:#e3f2fd,stroke:#64b5f6,stroke-width:2px
style OMS_API fill:#fff8e1,stroke:#fbc02d,stroke-width:2px
style Addon fill:#fff3e0,stroke:#ffb74d,stroke-width:2px

style OMS_API_Internal fill:#ede7f6,stroke:#9575cd,stroke-width:1.5px
style ADDON_CONTEXT fill:#d1c4e9,stroke:#7e57c2,stroke-width:1.5px
style FEATURE fill:#f3e5f5,stroke:#ab47bc,stroke-width:1.5px
```

{% endcode %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://conboi.gitbook.io/oms-wiki/developer-guide/core-architecture/system-architecture.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
