# roflcoopter/viseron architecture

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

- Interactive diagram: https://gitdiagram.com/roflcoopter/viseron
- Repository: https://github.com/roflcoopter/viseron

## Overview

#### Purpose and startup
Viseron is a self-hosted, local NVR and computer-vision system: it ingests camera streams, runs configurable detection/recognition pipelines, records media and events, and exposes browser and integration interfaces. Python application startup is `viseron/__main__.py`, with core orchestration in `viseron/__init__.py`. Container deployments run the application as a supervised service via `rootfs/etc/services.d/viseron/run`.

#### Core runtime and extensibility
The backend is a Python component/domain architecture. Configuration and component loading are centered on `viseron/config.py`, `viseron/components/__init__.py`, and `viseron/domain_registry.py`. Components provide concrete adapters (for example FFmpeg/GStreamer cameras, detector backends, storage, webserver, notifications); domains define shared semantic contracts such as camera, motion, object detection, recognition, and NVR. This separates vendor/runtime integrations from downstream event and entity behavior.

#### Video ingestion and camera lifecycle
Camera components acquire and decode streams through FFmpeg or GStreamer: `viseron/components/ffmpeg/camera.py`, `viseron/components/ffmpeg/stream.py`, and `viseron/components/gstreamer/pipeline.py`. They feed shared frames and camera-domain events through `viseron/domains/camera/shared_frames.py` and `viseron/domains/camera/events.py`. The camera boundary is where external RTSP/media pipelines become internal frames, stream outputs, recordings, and detector inputs.

#### Analytics and event pipeline
Motion and AI providers implement domain-specific processing over camera frames. Motion implementations include `viseron/components/background_subtractor/motion_detector.py` and `viseron/components/mog2/motion_detector.py`; object detection adapters include `viseron/components/yolo/object_detector.py`, `viseron/components/edgetpu/object_detector.py`, and `viseron/components/codeprojectai/object_detector.py`. Results are represented in domains such as `viseron/domains/object_detector/detected_object.py` and drive NVR/event behavior in `viseron/components/nvr/nvr.py`. The internal data-stream component (`viseron/components/data_stream/__init__.py`) is the likely fan-out boundary between producers and consumers.

#### Recording, persistence, and retention
Camera recording/fragment handling is split between `viseron/domains/camera/recorder.py`, `viseron/domains/camera/fragmenter.py`, and stream-provider recorders such as `viseron/components/ffmpeg/recorder.py`. The storage component owns database models, queries, migrations, and tiered media retention: `viseron/components/storage/models.py`, `viseron/components/storage/queries.py`, and `viseron/components/storage/tier_handler.py`. PostgreSQL is provisioned in the container runtime (`rootfs/etc/services.d/postgres/run`), while media is served through tier-aware handlers.

#### HTTP, realtime API, and frontend
The webserver component exposes authenticated REST endpoints, streaming/static media, and WebSocket commands: `viseron/components/webserver/api/v1`, `viseron/components/webserver/websocket_api/commands.py`, and `viseron/components/webserver/tiered_file_handler.py`. A Vite/React frontend starts at `frontend/src/index.tsx` and composes routes in `frontend/src/App.tsx`; it calls backend APIs under `frontend/src/lib/api` and uses `frontend/src/lib/websockets.ts` for realtime updates. Primary UI surfaces cover live cameras, events, recordings, configuration, tuning, users, and profiles.

#### Deployment and external boundaries
Docker is the primary delivery model (`docker/Dockerfile`), with platform/GPU-specific images under `docker/amd64-cuda`, `docker/aarch64`, and `docker/jetson-nano`. The runtime also supervises nginx and go2rtc (`rootfs/etc/services.d/nginx/run`, `rootfs/etc/services.d/go2rtc/run`) alongside PostgreSQL and Viseron. External integrations include MQTT/Home Assistant (`viseron/components/mqtt/homeassistant`), notification services such as Discord/Telegram/webhooks, and remote AI services including CodeProjectAI, DeepStack, and CompreFace.

Main entry points: [`rootfs/etc/services.d/viseron/run`](https://github.com/roflcoopter/viseron/blob/dev/rootfs/etc/services.d/viseron/run) (Service supervisor), [`viseron/__main__.py`](https://github.com/roflcoopter/viseron/blob/dev/viseron/__main__.py) (Viseron application), [`viseron/components/__init__.py`](https://github.com/roflcoopter/viseron/blob/dev/viseron/components/__init__.py) (Component loader), [`viseron/components/ffmpeg/camera.py`](https://github.com/roflcoopter/viseron/blob/dev/viseron/components/ffmpeg/camera.py) (Camera ingest)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Container runtime"]
  node_docker["Docker image<br/>deployment"]
  node_supervisor["Service supervisor<br/>service launcher<br/>[run]"]
  node_postgres[("PostgreSQL<br/>database service<br/>[run]")]
  node_go2rtc["go2rtc<br/>stream service<br/>[run]"]
end

subgraph group_core["Python core"]
  node_app{{"Viseron application<br/>Python runtime<br/>[__main__.py]"}}
  node_configuration["Configuration<br/>config loader<br/>[config.py]"]
  node_component_loader["Component loader<br/>extension registry<br/>[__init__.py]"]
  node_domain_registry["Domain registry<br/>semantic contracts<br/>[domain_registry.py]"]
end

subgraph group_media["Media and analytics"]
  node_camera_ingest["Camera ingest<br/>FFmpeg/GStreamer adapter<br/>[camera.py]"]
  node_shared_frames["Shared frames<br/>camera frame bus<br/>[shared_frames.py]"]
  node_data_stream["Data stream<br/>event fan-out<br/>[__init__.py]"]
  node_analytics["Motion and AI<br/>analytics adapters<br/>[object_detector.py]"]
  node_nvr["NVR event logic<br/>recording coordinator<br/>[nvr.py]"]
  node_recorder["Recording pipeline<br/>fragment recorder<br/>[recorder.py]"]
  node_storage[("Storage and retention<br/>media persistence<br/>[tier_handler.py]")]
end

subgraph group_interface["Interfaces"]
  node_webserver["REST and WebSocket API<br/>authenticated HTTP API<br/>[commands.py]"]
  node_frontend["React frontend<br/>browser UI<br/>[App.tsx]"]
  node_integrations["External integrations<br/>MQTT, notifications, remote AI"]
end

node_docker -->|"packages"| node_supervisor
node_supervisor -->|"launches"| node_app
node_supervisor -->|"runs"| node_postgres
node_supervisor -->|"runs"| node_go2rtc
node_app -->|"loads"| node_configuration
node_app -->|"initializes"| node_component_loader
node_component_loader -->|"binds adapters to"| node_domain_registry
node_component_loader -->|"loads"| node_camera_ingest
node_component_loader -->|"loads"| node_analytics
node_camera_ingest -.->|"uses stream service"| node_go2rtc
node_camera_ingest -->|"publishes frames"| node_shared_frames
node_shared_frames -->|"fans out"| node_data_stream
node_data_stream -->|"delivers frames"| node_analytics
node_analytics -->|"detection results"| node_nvr
node_nvr -->|"triggers recording"| node_recorder
node_recorder -->|"persists media"| node_storage
node_storage -->|"stores metadata"| node_postgres
node_webserver -->|"serves tiered media"| node_storage
node_frontend -->|"REST and WebSocket"| node_webserver
node_nvr -->|"events and streams"| node_webserver
node_app -->|"publishes and calls"| node_integrations

click node_docker "https://github.com/roflcoopter/viseron/tree/dev/docker/Dockerfile"
click node_supervisor "https://github.com/roflcoopter/viseron/blob/dev/rootfs/etc/services.d/viseron/run"
click node_postgres "https://github.com/roflcoopter/viseron/blob/dev/rootfs/etc/services.d/postgres/run"
click node_go2rtc "https://github.com/roflcoopter/viseron/blob/dev/rootfs/etc/services.d/go2rtc/run"
click node_app "https://github.com/roflcoopter/viseron/blob/dev/viseron/__main__.py"
click node_configuration "https://github.com/roflcoopter/viseron/blob/dev/viseron/config.py"
click node_component_loader "https://github.com/roflcoopter/viseron/blob/dev/viseron/components/__init__.py"
click node_domain_registry "https://github.com/roflcoopter/viseron/blob/dev/viseron/domain_registry.py"
click node_camera_ingest "https://github.com/roflcoopter/viseron/blob/dev/viseron/components/ffmpeg/camera.py"
click node_shared_frames "https://github.com/roflcoopter/viseron/blob/dev/viseron/domains/camera/shared_frames.py"
click node_data_stream "https://github.com/roflcoopter/viseron/blob/dev/viseron/components/data_stream/__init__.py"
click node_analytics "https://github.com/roflcoopter/viseron/blob/dev/viseron/components/yolo/object_detector.py"
click node_nvr "https://github.com/roflcoopter/viseron/blob/dev/viseron/components/nvr/nvr.py"
click node_recorder "https://github.com/roflcoopter/viseron/blob/dev/viseron/domains/camera/recorder.py"
click node_storage "https://github.com/roflcoopter/viseron/blob/dev/viseron/components/storage/tier_handler.py"
click node_webserver "https://github.com/roflcoopter/viseron/blob/dev/viseron/components/webserver/websocket_api/commands.py"
click node_frontend "https://github.com/roflcoopter/viseron/blob/dev/frontend/src/App.tsx"
click node_integrations "https://github.com/roflcoopter/viseron/tree/dev/viseron/components/mqtt/homeassistant"

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_docker,node_supervisor,node_postgres,node_go2rtc toneBlue
class node_app,node_configuration,node_component_loader,node_domain_registry toneAmber
class node_camera_ingest,node_shared_frames,node_data_stream,node_analytics,node_nvr,node_recorder,node_storage toneMint
class node_webserver,node_frontend,node_integrations toneRose
```

## Components

### Container runtime

- [Docker image](https://github.com/roflcoopter/viseron/tree/dev/docker/Dockerfile): deployment · Primary delivery image with platform and GPU variants. · `docker/Dockerfile`
- [Service supervisor](https://github.com/roflcoopter/viseron/blob/dev/rootfs/etc/services.d/viseron/run): service launcher · Runs Viseron alongside supporting services. · `rootfs/etc/services.d/viseron/run`
- [PostgreSQL](https://github.com/roflcoopter/viseron/blob/dev/rootfs/etc/services.d/postgres/run): database service · `rootfs/etc/services.d/postgres/run`
- [go2rtc](https://github.com/roflcoopter/viseron/blob/dev/rootfs/etc/services.d/go2rtc/run): stream service · `rootfs/etc/services.d/go2rtc/run`

### Python core

- [Viseron application](https://github.com/roflcoopter/viseron/blob/dev/viseron/__main__.py): Python runtime · Starts orchestration and component lifecycle. · `viseron/__main__.py`
- [Configuration](https://github.com/roflcoopter/viseron/blob/dev/viseron/config.py): config loader · `viseron/config.py`
- [Component loader](https://github.com/roflcoopter/viseron/blob/dev/viseron/components/__init__.py): extension registry · Loads concrete integration adapters. · `viseron/components/__init__.py`
- [Domain registry](https://github.com/roflcoopter/viseron/blob/dev/viseron/domain_registry.py): semantic contracts · Shared camera, motion, detection, recognition, and NVR behavior. · `viseron/domain_registry.py`

### Media and analytics

- [Camera ingest](https://github.com/roflcoopter/viseron/blob/dev/viseron/components/ffmpeg/camera.py): FFmpeg/GStreamer adapter · Converts external streams into internal camera data. · `viseron/components/ffmpeg/camera.py`
- [Shared frames](https://github.com/roflcoopter/viseron/blob/dev/viseron/domains/camera/shared_frames.py): camera frame bus · `viseron/domains/camera/shared_frames.py`
- [Data stream](https://github.com/roflcoopter/viseron/blob/dev/viseron/components/data_stream/__init__.py): event fan-out · Distributes frame and analytics data to consumers. · `viseron/components/data_stream/__init__.py`
- [Motion and AI](https://github.com/roflcoopter/viseron/blob/dev/viseron/components/yolo/object_detector.py): analytics adapters · Motion detectors and object-detection providers process camera frames. · `viseron/components/yolo/object_detector.py`
- [NVR event logic](https://github.com/roflcoopter/viseron/blob/dev/viseron/components/nvr/nvr.py): recording coordinator · Turns detection and camera events into NVR behavior. · `viseron/components/nvr/nvr.py`
- [Recording pipeline](https://github.com/roflcoopter/viseron/blob/dev/viseron/domains/camera/recorder.py): fragment recorder · Creates camera recordings and media fragments. · `viseron/domains/camera/recorder.py`
- [Storage and retention](https://github.com/roflcoopter/viseron/blob/dev/viseron/components/storage/tier_handler.py): media persistence · Owns database data, queries, and tiered retention. · `viseron/components/storage/tier_handler.py`

### Interfaces

- [REST and WebSocket API](https://github.com/roflcoopter/viseron/blob/dev/viseron/components/webserver/websocket_api/commands.py): authenticated HTTP API · Serves APIs, media, and realtime commands. · `viseron/components/webserver/websocket_api/commands.py`
- [React frontend](https://github.com/roflcoopter/viseron/blob/dev/frontend/src/App.tsx): browser UI · Live camera, event, recording, and administration surfaces. · `frontend/src/App.tsx`
- [External integrations](https://github.com/roflcoopter/viseron/tree/dev/viseron/components/mqtt/homeassistant): MQTT, notifications, remote AI · `viseron/components/mqtt/homeassistant`

## Connections

- Docker image → Service supervisor: packages
- Service supervisor → Viseron application: launches
- Service supervisor → PostgreSQL: runs
- Service supervisor → go2rtc: runs
- Viseron application → Configuration: loads
- Viseron application → Component loader: initializes
- Component loader → Domain registry: binds adapters to
- Component loader → Camera ingest: loads
- Component loader → Motion and AI: loads
- Camera ingest → go2rtc: uses stream service
- Camera ingest → Shared frames: publishes frames
- Shared frames → Data stream: fans out
- Data stream → Motion and AI: delivers frames
- Motion and AI → NVR event logic: detection results
- NVR event logic → Recording pipeline: triggers recording
- Recording pipeline → Storage and retention: persists media
- Storage and retention → PostgreSQL: stores metadata
- REST and WebSocket API → Storage and retention: serves tiered media
- React frontend → REST and WebSocket API: REST and WebSocket
- NVR event logic → REST and WebSocket API: events and streams
- Viseron application → External integrations: publishes and calls
