# eyevinn/channel-engine architecture

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

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

## Overview

##### Main Components

a. Core Engine Components:
- VOD2Live Converter
- Session Manager
- Stream Switcher
- State Management System
- Playhead Controller
- Subtitle Handler

b. Storage Components:
- Memory State Store
- Redis State Store (for HA)
- Memcached State Store

c. External Interfaces:
- HLS Input Sources (VOD/Live)
- HLS Output Stream
- API Layer

##### Key Architectural Elements

**┌─────────────────────────────────────────────┐**
- Client Layer                 │
- ┘
- ↑
**┌─────────────────────────────────────────────┐**
- Load Balancer                 │
- ┘
- ↑
**┌─────────────────────────────────────────────┐**
- Channel Engine Nodes             │
- ┤
- ┌─────────┐  ┌──────────┐  ┌────────────┐  │
- Session │  │  Stream  │  │ Playhead   │  │
- Manager │  │ Switcher │  │ Controller │  │
- ┘  └──────────┘  └────────────┘  │
- ┌─────────┐  ┌──────────┐  ┌────────────┐  │
- Subtitle │  │   Event  │  │ Preflight  │  │
- Slicer  │  │  Stream  │  │  Handler   │  │
- ┘  └──────────┘  └────────────┘  │
- ┘
- ↕
**┌─────────────────────────────────────────────┐**
- State Management                 │
- ┬─────────────┬────────────────┤
- Redis     │  Memcached  │    Memory      │
- Store     │    Store    │     Store      │
- ┴─────────────┴────────────────┘
- ↕
**┌─────────────────────────────────────────────┐**
- Input Sources                  │
- ┬─────────────┬────────────────┤
- HLS VOD    │  Live HLS   │    DRM VOD     │
- ┴─────────────┴────────────────┘

##### Important Relationships to Highlight

- High-availability setup with Redis
- Flow from VOD/Live sources through the engine to output
- Demonstrate the state management interaction
- Session management flow

##### Additional Elements

- Component types
- Connection types
- State store options
- Supported formats (HLS+TS, HLS+CMAF)
- Node.js version compatibility

##### Technical Details to Note

- Support for both muxed and demuxed streams
- DRM handling capabilities (beta)
- WebVTT subtitle support
- Live stream mixing capability
- High availability configuration

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph CL["Client Layer"]
        Client[Client Requests]
    end

    subgraph LB["Load Balancer Layer"]
        LoadBalancer["NGINX Load Balancer"]:::loadbalancer
    end

    subgraph CE["Channel Engine Nodes"]
        CoreEngine["Core Engine"]:::core
        SessionMgr["Session Manager"]:::core
        StreamSwitch["Stream Switcher"]:::core
        PlayheadCtrl["Playhead Controller"]:::core
        SubHandler["Subtitle Handler"]:::core
        EventStream["Event Stream"]:::core
        PreflightH["Preflight Handler"]:::core
        AdIntegration["Ad Integration"]:::core
    end

    subgraph SM["State Management Layer"]
        MemoryStore["Memory Store"]:::store
        RedisStore["Redis Store"]:::store
        MemcachedStore["Memcached Store"]:::store
    end

    subgraph IS["Input Sources Layer"]
        HLSVOD["HLS VOD"]:::source
        LiveHLS["Live HLS"]:::source
        DRMVOD["DRM VOD"]:::source
    end

    %% Connections
    Client --> LoadBalancer
    LoadBalancer --> CoreEngine
    CoreEngine --> SessionMgr
    CoreEngine --> StreamSwitch
    CoreEngine --> PlayheadCtrl
    CoreEngine --> SubHandler
    CoreEngine --> EventStream
    CoreEngine --> PreflightH
    CoreEngine --> AdIntegration

    SessionMgr <--> MemoryStore
    SessionMgr <--> RedisStore
    SessionMgr <--> MemcachedStore

    HLSVOD --> CoreEngine
    LiveHLS --> CoreEngine
    DRMVOD --> CoreEngine

    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef store fill:#2ecc71,stroke:#27ae60,color:white
    classDef source fill:#e67e22,stroke:#d35400,color:white
    classDef loadbalancer fill:#9b59b6,stroke:#8e44ad,color:white

    %% Click Events
    click SessionMgr "https://github.com/Eyevinn/channel-engine/blob/master/engine/session.js"
    click StreamSwitch "https://github.com/Eyevinn/channel-engine/blob/master/engine/stream_switcher.js"
    click PlayheadCtrl "https://github.com/Eyevinn/channel-engine/blob/master/engine/playhead_state.js"
    click SubHandler "https://github.com/Eyevinn/channel-engine/blob/master/engine/subtitle_slicer.js"
    click EventStream "https://github.com/Eyevinn/channel-engine/blob/master/engine/event_stream.js"
    click PreflightH "https://github.com/Eyevinn/channel-engine/blob/master/engine/preflight.js"
    click CoreEngine "https://github.com/Eyevinn/channel-engine/blob/master/engine/index.ts"
    click LoadBalancer "https://github.com/Eyevinn/channel-engine/blob/master/ha-dev/nginx-proxy-lb.conf"
    click AdIntegration "https://github.com/Eyevinn/channel-engine/blob/master/engine/ad_request.js"
    click MemoryStore "https://github.com/Eyevinn/channel-engine/blob/master/engine/memory_state_store.js"
    click RedisStore "https://github.com/Eyevinn/channel-engine/blob/master/engine/redis_state_store.js"
    click MemcachedStore "https://github.com/Eyevinn/channel-engine/blob/master/engine/memcached_state_store.js"
```
