# bitfocus/companion-module-streamlabs-desktop architecture

> Architecture diagram of the GitHub repository bitfocus/companion-module-streamlabs-desktop, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bitfocus/companion-module-streamlabs-desktop
- Repository: https://github.com/bitfocus/companion-module-streamlabs-desktop

## Overview

This is a Bitfocus Companion module for controlling a local Streamlabs Desktop instance. The workflow begins with a Companion action, passes through the module instance and its authenticated SockJS/JSON-RPC connection, and invokes Streamlabs services; returned state and events update the in-memory mirror, which drives Companion feedbacks and variables. The README documents scene and collection control, visibility, stream/recording, replay, studio mode, audio, performance, and generated presets. The excerpts show the main orchestration and transport, but not every service call, so unsampled wiring is represented only where documented.

Main entry points: [`src/main.ts`](https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/main.ts) (Module instance), [`src/slobs/connection.ts`](https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/slobs/connection.ts) (SlobsConnection), [`src/state.ts`](https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/state.ts) (State mirror), [`src/actions.ts`](https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/actions.ts) (Action definitions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_companion["Companion controls"]
  node_companion["Companion"]
  node_actions["Action definitions<br/>[actions.ts]"]
  node_feedbacks["Feedback definitions<br/>[feedbacks.ts]"]
  node_variables["Variable definitions<br/>[variables.ts]"]
  node_presets["Generated presets<br/>[presets.ts]"]
end

subgraph group_module["Module runtime"]
  node_main["Module instance<br/>[main.ts]"]
  node_config["Connection config<br/>[config.ts]"]
  node_state["State mirror<br/>[state.ts]"]
  node_util["Status utilities<br/>[util.ts]"]
end

subgraph group_transport["API transport"]
  node_connection["SlobsConnection<br/>[connection.ts]"]
  node_protocol["Protocol types<br/>[types.ts]"]
end

subgraph group_streamlabs["Streamlabs Desktop"]
  node_desktop["Streamlabs Desktop"]
end

node_operator(("Operator"))

node_operator -->|"operates"| node_companion
node_companion -->|"invokes"| node_actions
node_actions -->|"calls actions"| node_main
node_main -->|"reads fields"| node_config
node_main -->|"creates and calls"| node_connection
node_connection -->|"JSON-RPC requests"| node_desktop
node_desktop -->|"events and replies"| node_connection
node_connection -->|"emits updates"| node_main
node_main -->|"syncs state"| node_state
node_main -->|"formats status"| node_util
node_main -->|"registers definitions"| node_actions
node_main -->|"registers definitions"| node_feedbacks
node_main -->|"registers definitions"| node_variables
node_main -->|"builds presets"| node_presets
node_feedbacks -->|"reads state"| node_state
node_variables -->|"reads sources"| node_state
node_presets -->|"reads state"| node_state
node_companion -->|"evaluates"| node_feedbacks
node_companion -->|"exposes values"| node_variables
node_companion -->|"displays"| node_presets
node_connection -->|"uses types"| node_protocol

click node_actions "https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/actions.ts"
click node_feedbacks "https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/feedbacks.ts"
click node_variables "https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/variables.ts"
click node_presets "https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/presets.ts"
click node_main "https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/main.ts"
click node_config "https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/config.ts"
click node_state "https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/state.ts"
click node_util "https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/util.ts"
click node_connection "https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/slobs/connection.ts"
click node_protocol "https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/slobs/types.ts"

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_companion,node_actions,node_feedbacks,node_variables,node_presets toneBlue
class node_main,node_config,node_state,node_util toneAmber
class node_connection,node_protocol toneMint
class node_desktop toneRose
class node_operator toneIndigo
```

## Components

### Companion controls

- **Companion**
- [Action definitions](https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/actions.ts): `src/actions.ts`
- [Feedback definitions](https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/feedbacks.ts): `src/feedbacks.ts`
- [Variable definitions](https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/variables.ts): `src/variables.ts`
- [Generated presets](https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/presets.ts): `src/presets.ts`

### Module runtime

- [Module instance](https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/main.ts): `src/main.ts`
- [Connection config](https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/config.ts): `src/config.ts`
- [State mirror](https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/state.ts): `src/state.ts`
- [Status utilities](https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/util.ts): `src/util.ts`

### API transport

- [SlobsConnection](https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/slobs/connection.ts): `src/slobs/connection.ts`
- [Protocol types](https://github.com/bitfocus/companion-module-streamlabs-desktop/blob/main/src/slobs/types.ts): `src/slobs/types.ts`

### Streamlabs Desktop

- **Streamlabs Desktop**

### Other components

- **Operator**

## Connections

- Operator → Companion: operates
- Companion → Action definitions: invokes
- Action definitions → Module instance: calls actions
- Module instance → Connection config: reads fields
- Module instance → SlobsConnection: creates and calls
- SlobsConnection → Streamlabs Desktop: JSON-RPC requests
- Streamlabs Desktop → SlobsConnection: events and replies
- SlobsConnection → Module instance: emits updates
- Module instance → State mirror: syncs state
- Module instance → Status utilities: formats status
- Module instance → Action definitions: registers definitions
- Module instance → Feedback definitions: registers definitions
- Module instance → Variable definitions: registers definitions
- Module instance → Generated presets: builds presets
- Feedback definitions → State mirror: reads state
- Variable definitions → State mirror: reads sources
- Generated presets → State mirror: reads state
- Companion → Feedback definitions: evaluates
- Companion → Variable definitions: exposes values
- Companion → Generated presets: displays
- SlobsConnection → Protocol types: uses types
