# eerimoq/moblin architecture

> Architecture diagram of the GitHub repository eerimoq/moblin, 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/eerimoq/moblin
- Repository: https://github.com/eerimoq/moblin

## Overview

##### Main Components and Their Roles
- Mobile iOS Client (Main App)
- UI Layer (“Moblin/View” and “Moblin/Settings”) that includes controls, stream overlays, quick buttons, and video effects.
- Media Pipeline Layer (“Moblin/Media” and HaishinKit integration) responsible for capturing video/audio, applying effects, encoding (H.264/AVC, H.265/HEVC), and streaming.
- Integration modules (“Moblin/Integrations”) that handle communication with external platforms (Twitch, YouTube, Kick, AfreecaTv, etc.), chat, alerts, and messaging.
- Settings / Configuration and deep link handling (see Moblin Settings URL, Moblin/Various/Settings.swift) that drive runtime customization.

- Companion and Extended Components:
- Moblin Watch: A watchOS companion, with a lightweight version of status display, chat and control aspects.
- Moblin Widget: Provides quick overview and possibly streaming status or shortcuts.
- Screen Recording Module (“Moblin Screen Recording” directory) that might handle broadcast extension or similar.

- Common Functionality:
- Shared Utility and common view resources under “Common” (localization, reusable UI components).
- Utilities, helper scripts, and build settings for development and maintenance.

##### Architectural Relationships / Data Flow
- UI components (arranged using view and settings modules) interact with the media pipeline to trigger capture, encoding, and streaming.
- Media Pipeline (leveraging HaishinKit modules) processes audio/video streams and applies video effects before forwarding them to external streaming endpoints.
- Integration modules (organized under Moblin/Integrations) send and receive data (chat messages, viewer counts, alerts) to/from third-party streaming platforms via their APIs (using, for example, WebSocket for OBS control, REST/HTTP API for Twitch, etc.).
- Settings and deep link components allow external configuration (via URL encoded JSON) and load preferences that adjust the media pipeline behavior and UI options.
- Companion apps (Watch and Widget) connect to the main app via local network communication (or via shared services) to display previews or send control commands.

##### Key Patterns and Principles
- Separation of concerns: Divide the system into distinct modules – media handling, UI/interactions, integrations, and settings.
- Modular design: Each integration (e.g., Twitch, YouTube, etc.) has its dedicated directory, suggesting plug‐in style extensibility.
- Event-driven communication: UI actions trigger changes in the media engine and integration modules, with many directional flows (e.g., from chat to alert generation).

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "Mobile iOS Client"
        UI["User Interface (Moblin/View & Moblin/View/Settings)"]:::ui
        Media["Media Pipeline & Engine (Moblin/Media + HaishinKit)"]:::media
        Integrations["Integration Modules (Moblin/Integrations)"]:::integration
        Settings["Configuration & DeepLink (Moblin/Various/Settings.swift, MoblinSettingsUrl.swift)"]:::config
    end

    subgraph "Companion Modules"
        Watch["Moblin Watch"]:::companion
        Widget["Moblin Widget"]:::companion
    end

    Screen["Screen Recording (Moblin Screen Recording)"]:::screen
    Common["Shared & Common Resources (Common)"]:::common

    subgraph "External Services"
        ExtTwitch["Twitch API"]:::external
        ExtYouTube["YouTube API"]:::external
        ExtKick["Kick API"]:::external
        ExtOBS["OBS WebSocket"]:::external
    end

    %% Integration Modules Detailed Breakdown
    subgraph "Integration Modules Breakdown"
        Twitch["Twitch Integration (Moblin/Platforms/Twitch)"]:::integration
        YouTube["YouTube Integration (Moblin/Platforms/YouTube)"]:::integration
        Kick["Kick Integration (Moblin/Platforms/Kick)"]:::integration
        Emotes["Emotes Integration (Moblin/Integrations/Emotes)"]:::integration
        Tesla["Tesla Integration (Moblin/Integrations/Tesla)"]:::integration
        DJI["DJI Integration (Moblin/Integrations/Dji)"]:::integration
        Others["Other Integrations (Moblin/Integrations/CatPrinter, Moblin/Integrations/HeartRateDevice, etc.)"]:::integration
    end

    %% Data Flow Connections
    UI -->|"triggers"| Media
    UI -->|"updates"| Settings
    Settings -->|"configures"| Media

    Media -->|"streams:RTMP/SRT/SRTLA"| ExtTwitch
    Media -->|"streams:RTMP/SRT/SRTLA"| ExtYouTube
    Media -->|"streams:RTMP/SRT/SRTLA"| ExtKick

    Integrations --> Twitch
    Integrations --> YouTube
    Integrations --> Kick
    Integrations --> Emotes
    Integrations --> Tesla
    Integrations --> DJI
    Integrations --> Others

    Twitch -->|"calls"| ExtTwitch
    YouTube -->|"calls"| ExtYouTube
    Kick -->|"calls"| ExtKick

    Integrations -->|"OBSControl(WebSocket)"| ExtOBS

    UI -->|"shares"| Common
    Media -->|"shares"| Common
    Integrations -->|"shares"| Common

    UI -->|"status/control"| Watch
    UI -->|"status/control"| Widget

    Media -->|"captures recording"| Screen

    %% Click Events
    click UI "https://github.com/eerimoq/moblin/tree/main/Moblin/View"
    click UI "https://github.com/eerimoq/moblin/tree/main/Moblin/View/Settings"
    click Settings "https://github.com/eerimoq/moblin/blob/main/Moblin/Various/Settings.swift"
    click Settings "https://github.com/eerimoq/moblin/blob/main/Moblin/Various/MoblinSettingsUrl.swift"
    click Media "https://github.com/eerimoq/moblin/tree/main/Moblin/Media"
    click Media "https://github.com/eerimoq/moblin/tree/main/Moblin/Media/HaishinKit"
    click Integrations "https://github.com/eerimoq/moblin/tree/main/Moblin/Integrations"
    click Twitch "https://github.com/eerimoq/moblin/tree/main/Moblin/Platforms/Twitch"
    click YouTube "https://github.com/eerimoq/moblin/tree/main/Moblin/Platforms/YouTube"
    click Kick "https://github.com/eerimoq/moblin/tree/main/Moblin/Platforms/Kick"
    click Emotes "https://github.com/eerimoq/moblin/tree/main/Moblin/Integrations/Emotes"
    click Tesla "https://github.com/eerimoq/moblin/tree/main/Moblin/Integrations/Tesla"
    click DJI "https://github.com/eerimoq/moblin/tree/main/Moblin/Integrations/Dji"
    click Others "https://github.com/eerimoq/moblin/tree/main/Moblin/Integrations/CatPrinter"
    click Others "https://github.com/eerimoq/moblin/tree/main/Moblin/Integrations/HeartRateDevice"
    click Watch "https://github.com/eerimoq/moblin/tree/main/Moblin Watch"
    click Widget "https://github.com/eerimoq/moblin/tree/main/Moblin Widget"
    click Screen "https://github.com/eerimoq/moblin/tree/main/Moblin Screen Recording"
    click Common "https://github.com/eerimoq/moblin/tree/main/Common"

    %% Styles
    classDef ui fill:#D0E6FF,stroke:#0B5394,stroke-width:2px,rx:5,ry:5;
    classDef media fill:#FFE599,stroke:#BF9000,stroke-width:2px,rx:5,ry:5;
    classDef integration fill:#D9EAD3,stroke:#274E13,stroke-width:2px,rx:5,ry:5;
    classDef config fill:#F4CCCC,stroke:#990000,stroke-width:2px,rx:5,ry:5;
    classDef companion fill:#EAD1DC,stroke:#99004D,stroke-width:2px,rx:5,ry:5;
    classDef screen fill:#FCE5CD,stroke:#993300,stroke-width:2px,rx:5,ry:5;
    classDef common fill:#D9D2E9,stroke:#6A0DAD,stroke-width:2px,rx:5,ry:5;
    classDef external fill:#C9DAF8,stroke:#27408B,stroke-width:2px,rx:5,ry:5;
```
