# monibuca/engine architecture

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

- Interactive diagram: https://gitdiagram.com/monibuca/engine
- Repository: https://github.com/monibuca/engine

## Overview

##### Main Components
- Plugin Mechanism: The engine supports plugins for both publishing and subscribing. Include a distinct “Plugin Manager” node (referencing plugin.go) which interacts with other modules via well-defined interfaces (like the authentication interfaces).
- Codec Processing: There is a dedicated “Codec” module (directory “codec” and “track”) that handles media processing such as H264/H265 processing, MP4 and MPEG-TS packaging, AVCC, RTP and AnnexB formats. Represent this as one or more nodes; you might even cluster them under a “Media Codec & Track Processing” group.
- Configuration and Authentication: The “config” directory and the configuration in the README indicate a centralized configuration management system. Include a “Configuration Manager” node that interacts with:
- HTTP API settings (e.g., API endpoints for config retrieval, update, etc.)
- Global and per-plugin configuration resolution (note the override mechanism described).
- HTTP API & Middleware: The project includes an HTTP service component (http.go and HTTP middleware handling in the README). Represent this as an “HTTP API Server” node, with details about API endpoints (stream state, system info, replay endpoints, plugin info, etc.) and middleware adding extra layers (authentication or logging middleware).

##### Relationships and Data Flow
- The “HTTP API Server” communicates with the “Configuration Manager” (e.g., for config hot updates) and accesses stream and plugin data.
- The “Plugin Manager” interacts with both the “Engine Core” (to manage stream events, publishing/subscription changes, and authentication) and external plugins (offering additional functionalities).
- The “Media Codec & Track Processing” module is tightly coupled with the “Engine Core” for encoding/decoding and encapsulation operations.
- Utility modules provide callbacks and shared functions that support almost every layer (from logging in the core to error handling in the plugin system).

##### Architectural Patterns and Design Principles
- Modular Design: Clearly separate components (e.g., codec, config, plugin, HTTP API) to emphasize the maintenance and extension capabilities.
- Configuration Override Hierarchy: Represent the layered approach (parameters in the request → plugin configuration → global configuration) by annotating the Configuration Manager’s responsibilities.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Streaming Engine Components"
        HTTP_API["HTTP API Server"]:::api
        ConfigM["Configuration Manager"]:::config
        EngineCore["Engine Core"]:::core
        PluginMgr["Plugin Manager"]:::plugin
        MediaCodec["Media Codec & Track Processing"]:::codec
        UtilityMods["Utility Modules"]:::util
    end

    %% Relationships
    HTTP_API -->|"config_update"| ConfigM
    HTTP_API -->|"stream_control"| EngineCore
    ConfigM -->|"config_data"| EngineCore

    EngineCore -->|"plugin_events"| PluginMgr
    PluginMgr -->|"auth_publish"| EngineCore

    EngineCore -->|"media_processing"| MediaCodec
    MediaCodec -->|"media_feedback"| EngineCore

    EngineCore -->|"util_calls"| UtilityMods
    PluginMgr -->|"util_calls"| UtilityMods
    HTTP_API -->|"util_calls"| UtilityMods
    ConfigM -->|"util_calls"| UtilityMods
    MediaCodec -->|"util_calls"| UtilityMods

    %% Click Events for Component Mapping
    click EngineCore "https://github.com/monibuca/engine/blob/v4/main.go"
    click PluginMgr "https://github.com/monibuca/engine/blob/v4/plugin.go"
    click MediaCodec "https://github.com/monibuca/engine/tree/v4/codec/"
    click MediaCodec "https://github.com/monibuca/engine/tree/v4/track/"
    click ConfigM "https://github.com/monibuca/engine/tree/v4/config/"
    click HTTP_API "https://github.com/monibuca/engine/blob/v4/http.go"
    click HTTP_API "https://github.com/monibuca/engine/blob/v4/config/http.go"
    click UtilityMods "https://github.com/monibuca/engine/tree/v4/common/"
    click UtilityMods "https://github.com/monibuca/engine/tree/v4/util/"
    click UtilityMods "https://github.com/monibuca/engine/tree/v4/log/"

    %% Styles
    classDef core fill:#f9f,stroke:#333,stroke-width:2px;
    classDef plugin fill:#ccf,stroke:#333,stroke-width:2px;
    classDef config fill:#cfc,stroke:#333,stroke-width:2px;
    classDef api fill:#fcf,stroke:#333,stroke-width:2px;
    classDef codec fill:#cff,stroke:#333,stroke-width:2px;
    classDef util fill:#ffc,stroke:#333,stroke-width:2px;
```
