# stalexteam/restream_go architecture

> Architecture diagram of the GitHub repository stalexteam/restream_go, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/stalexteam/restream_go
- Repository: https://github.com/stalexteam/restream_go

## Overview

restream-controller is a continuous OBS-to-many-platform relay. OBS publishes one RTMP or SRT feed; the controller routes per-platform tracks, switches each output between live and prepared backup media without ending its connection, and pushes to enabled platforms. The dashboard manages sources, platforms, groups, and settings and reports status. The graph includes ingest, probing, per-platform processing, fallback, media management, and runtime control. Some subsystem links are documented only at a high level; those are dashed where source-level evidence was not shown.

Main entry points: [`internal/platform/pipeline.go`](https://github.com/stalexteam/restream_go/blob/main/internal/platform/pipeline.go) (Platform pipeline), [`internal/api/server.go`](https://github.com/stalexteam/restream_go/blob/main/internal/api/server.go) (HTTP and commands), [`internal/app/app.go`](https://github.com/stalexteam/restream_go/blob/main/internal/app/app.go) (App lifecycle), [`internal/control/manager.go`](https://github.com/stalexteam/restream_go/blob/main/internal/control/manager.go) (Control manager)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime control"]
  node_main["Daemon entry<br/>[main.go]"]
  node_app["App lifecycle<br/>[app.go]"]
  node_manager["Control manager<br/>[manager.go]"]
end

subgraph group_ingest["Ingest and routing"]
  node_mediamtx["MediaMTX"]
  node_readback["Relay readback<br/>[readback.go]"]
  node_router["Track router<br/>[route.go]"]
  node_demux["TS demux<br/>[demux.go]"]
end

subgraph group_delivery["Platform delivery"]
  node_platform_machine["Platform machine<br/>[machine.go]"]
  node_platform_pipeline["Platform pipeline<br/>[pipeline.go]"]
  node_probe["Media probing<br/>[probe.go]"]
  node_switcher["Timeline switcher<br/>[switcher.go]"]
  node_fallback_player["Backup player<br/>[player.go]"]
  node_preparer["Backup preparation<br/>[preparer.go]"]
  node_egress["RTMP egress<br/>[rtmp_push.go]"]
end

subgraph group_management["Dashboard and media"]
  node_api["HTTP and commands<br/>[server.go]"]
  node_dashboard["Dashboard UI<br/>[dashboard.js]"]
  node_settings_ui["Settings UI<br/>[config.js]"]
  node_media[("Media library<br/>[store.go]")]
end

node_obs(("OBS publisher"))
node_platforms(("Streaming platforms"))
node_browser_user(("Dashboard operator"))

node_main -->|"starts"| node_app
node_app -->|"creates"| node_manager
node_app -->|"serves through"| node_api
node_app -->|"starts and watches"| node_mediamtx
node_api -->|"handles commands"| node_manager
node_manager -->|"instantiates"| node_platform_machine
node_platform_machine -.->|"owns pipeline"| node_platform_pipeline
node_obs -->|"publishes feed"| node_mediamtx
node_mediamtx -.->|"provides readback"| node_readback
node_platform_pipeline -->|"builds relay args"| node_readback
node_platform_pipeline -.->|"demuxes transport"| node_demux
node_platform_pipeline -->|"selects tracks"| node_router
node_platform_pipeline -->|"forwards media tags"| node_switcher
node_platform_pipeline -->|"creates backup player"| node_fallback_player
node_platform_pipeline -->|"prepares backup"| node_preparer
node_fallback_player -->|"emits backup stream"| node_switcher
node_platform_pipeline -.->|"probes sources"| node_probe
node_platform_pipeline -.->|"pushes output"| node_egress
node_egress -->|"streams to"| node_platforms
node_switcher -->|"keeps output continuous"| node_platforms
node_browser_user -->|"manages stream"| node_dashboard
node_dashboard -.->|"sends commands"| node_api
node_settings_ui -.->|"configures service"| node_api
node_api -->|"uploads and serves files"| node_media
node_api -.->|"serves dashboard"| node_dashboard

click node_main "https://github.com/stalexteam/restream_go/blob/main/main.go"
click node_app "https://github.com/stalexteam/restream_go/blob/main/internal/app/app.go"
click node_manager "https://github.com/stalexteam/restream_go/blob/main/internal/control/manager.go"
click node_platform_machine "https://github.com/stalexteam/restream_go/blob/main/internal/platform/machine.go"
click node_platform_pipeline "https://github.com/stalexteam/restream_go/blob/main/internal/platform/pipeline.go"
click node_api "https://github.com/stalexteam/restream_go/blob/main/internal/api/server.go"
click node_dashboard "https://github.com/stalexteam/restream_go/blob/main/internal/web/dashboard/dashboard.js"
click node_settings_ui "https://github.com/stalexteam/restream_go/blob/main/internal/web/dashboard/config.js"
click node_media "https://github.com/stalexteam/restream_go/blob/main/internal/media/store.go"
click node_readback "https://github.com/stalexteam/restream_go/blob/main/internal/ingest/readback.go"
click node_probe "https://github.com/stalexteam/restream_go/blob/main/internal/probe/probe.go"
click node_router "https://github.com/stalexteam/restream_go/blob/main/internal/route/route.go"
click node_demux "https://github.com/stalexteam/restream_go/blob/main/internal/wire/ts/demux.go"
click node_switcher "https://github.com/stalexteam/restream_go/blob/main/internal/timeline/switcher.go"
click node_fallback_player "https://github.com/stalexteam/restream_go/blob/main/internal/fallback/player.go"
click node_preparer "https://github.com/stalexteam/restream_go/blob/main/internal/fallback/preparer.go"
click node_egress "https://github.com/stalexteam/restream_go/blob/main/internal/egress/rtmp_push.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_main,node_app,node_manager toneBlue
class node_mediamtx,node_readback,node_router,node_demux toneAmber
class node_platform_machine,node_platform_pipeline,node_probe,node_switcher,node_fallback_player,node_preparer,node_egress toneMint
class node_api,node_dashboard,node_settings_ui,node_media toneRose
class node_obs,node_platforms,node_browser_user toneIndigo
```

## Components

### Runtime control

- [Daemon entry](https://github.com/stalexteam/restream_go/blob/main/main.go): `main.go`
- [App lifecycle](https://github.com/stalexteam/restream_go/blob/main/internal/app/app.go): `internal/app/app.go`
- [Control manager](https://github.com/stalexteam/restream_go/blob/main/internal/control/manager.go): `internal/control/manager.go`

### Ingest and routing

- **MediaMTX**
- [Relay readback](https://github.com/stalexteam/restream_go/blob/main/internal/ingest/readback.go): `internal/ingest/readback.go`
- [Track router](https://github.com/stalexteam/restream_go/blob/main/internal/route/route.go): `internal/route/route.go`
- [TS demux](https://github.com/stalexteam/restream_go/blob/main/internal/wire/ts/demux.go): `internal/wire/ts/demux.go`

### Platform delivery

- [Platform machine](https://github.com/stalexteam/restream_go/blob/main/internal/platform/machine.go): `internal/platform/machine.go`
- [Platform pipeline](https://github.com/stalexteam/restream_go/blob/main/internal/platform/pipeline.go): `internal/platform/pipeline.go`
- [Media probing](https://github.com/stalexteam/restream_go/blob/main/internal/probe/probe.go): `internal/probe/probe.go`
- [Timeline switcher](https://github.com/stalexteam/restream_go/blob/main/internal/timeline/switcher.go): `internal/timeline/switcher.go`
- [Backup player](https://github.com/stalexteam/restream_go/blob/main/internal/fallback/player.go): `internal/fallback/player.go`
- [Backup preparation](https://github.com/stalexteam/restream_go/blob/main/internal/fallback/preparer.go): `internal/fallback/preparer.go`
- [RTMP egress](https://github.com/stalexteam/restream_go/blob/main/internal/egress/rtmp_push.go): `internal/egress/rtmp_push.go`

### Dashboard and media

- [HTTP and commands](https://github.com/stalexteam/restream_go/blob/main/internal/api/server.go): `internal/api/server.go`
- [Dashboard UI](https://github.com/stalexteam/restream_go/blob/main/internal/web/dashboard/dashboard.js): `internal/web/dashboard/dashboard.js`
- [Settings UI](https://github.com/stalexteam/restream_go/blob/main/internal/web/dashboard/config.js): `internal/web/dashboard/config.js`
- [Media library](https://github.com/stalexteam/restream_go/blob/main/internal/media/store.go): `internal/media/store.go`

### Other components

- **OBS publisher**
- **Streaming platforms**
- **Dashboard operator**

## Connections

- Daemon entry → App lifecycle: starts (evidence: `main.go`)
- App lifecycle → Control manager: creates (evidence: `internal/app/app.go`)
- App lifecycle → HTTP and commands: serves through (evidence: `internal/app/app.go`)
- App lifecycle → MediaMTX: starts and watches (evidence: `internal/app/app.go`)
- HTTP and commands → Control manager: handles commands
- Control manager → Platform machine: instantiates (evidence: `internal/control/manager.go`)
- Platform machine → Platform pipeline: owns pipeline
- OBS publisher → MediaMTX: publishes feed (evidence: `README.md`)
- MediaMTX → Relay readback: provides readback
- Platform pipeline → Relay readback: builds relay args (evidence: `internal/platform/pipeline.go`)
- Platform pipeline → TS demux: demuxes transport
- Platform pipeline → Track router: selects tracks (evidence: `internal/platform/pipeline.go`)
- Platform pipeline → Timeline switcher: forwards media tags (evidence: `internal/platform/pipeline.go`)
- Platform pipeline → Backup player: creates backup player (evidence: `internal/platform/pipeline.go`)
- Platform pipeline → Backup preparation: prepares backup (evidence: `internal/platform/pipeline.go`)
- Backup player → Timeline switcher: emits backup stream (evidence: `internal/fallback/player.go`)
- Platform pipeline → Media probing: probes sources
- Platform pipeline → RTMP egress: pushes output
- RTMP egress → Streaming platforms: streams to (evidence: `README.md`)
- Timeline switcher → Streaming platforms: keeps output continuous (evidence: `README.md`)
- Dashboard operator → Dashboard UI: manages stream (evidence: `README.md`)
- Dashboard UI → HTTP and commands: sends commands
- Settings UI → HTTP and commands: configures service
- HTTP and commands → Media library: uploads and serves files (evidence: `internal/api/server.go`)
- HTTP and commands → Dashboard UI: serves dashboard
