# opensensor/lightnvr architecture

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

- Interactive diagram: https://gitdiagram.com/opensensor/lightnvr
- Repository: https://github.com/opensensor/lightnvr

## Overview

LightNVR is a self-hosted network video recorder. Operators configure cameras and policies through the web UI and REST API; camera streams are ingested, analyzed, recorded, retained, and made available for live viewing or investigation. The map also includes documented integrations and operational features. The excerpts chiefly expose storage and web-query internals; other relationships are included only where the README documents the capability, so some subsystem links remain intentionally absent.

Main entry points: [`web/js/components/preact/LiveView.tsx`](https://github.com/opensensor/lightnvr/blob/main/web/js/components/preact/LiveView.tsx) (Web interface), [`src/video/stream_manager.c`](https://github.com/opensensor/lightnvr/blob/main/src/video/stream_manager.c) (Live streaming), [`src/storage/storage_manager.c`](https://github.com/opensensor/lightnvr/blob/main/src/storage/storage_manager.c) (Storage management), [`src/web/api_handlers_storage_targets.c`](https://github.com/opensensor/lightnvr/blob/main/src/web/api_handlers_storage_targets.c) (Storage controls)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Operator experience"]
  node_webui["Web interface<br/>[LiveView.tsx]"]
  node_webapi["REST API"]
end

subgraph group_video["Video workflows"]
  node_streaming["Live streaming<br/>[stream_manager.c]"]
  node_detection["Detection"]
  node_recording["Recording<br/>[recording.c]"]
  node_playback["Playback and investigation"]
end

subgraph group_platform["Data and storage"]
  node_storage["Storage management<br/>[storage_manager.c]"]
  node_storageapi["Storage controls"]
  node_database[("SQLite database<br/>[db_core.c]")]
end

subgraph group_integrations["Security and operations"]
  node_auth["Authentication"]
  node_onvif["ONVIF discovery and events<br/>[onvif_discovery.c]"]
  node_mqtt["MQTT events<br/>[mqtt_client.c]"]
  node_health["System health and metrics<br/>[system_health.c]"]
  node_archive["External archive<br/>[storage_s3.c]"]
end

node_operator(("Operator"))
node_camera(("IP camera"))
node_mqttservice(("MQTT broker"))

node_operator -->|"operates"| node_webui
node_webui -->|"requests"| node_webapi
node_camera -->|"sends video"| node_streaming
node_streaming -->|"records streams"| node_recording
node_streaming -->|"analyzes video"| node_detection
node_webui -->|"reviews footage"| node_playback
node_webapi -->|"configures storage"| node_storageapi
node_storageapi -->|"reads and writes"| node_database
node_storageapi -->|"probes targets"| node_storage
node_storage -->|"reads recording data"| node_database
node_operator -->|"discovers cameras"| node_onvif
node_operator -->|"authenticates"| node_auth
node_mqtt -->|"publishes events"| node_mqttservice
node_operator -->|"views health"| node_health
node_storage -.->|"archives recordings"| node_archive

click node_webui "https://github.com/opensensor/lightnvr/blob/main/web/js/components/preact/LiveView.tsx"
click node_webapi "https://github.com/opensensor/lightnvr/blob/main/src/web/api_handlers_streaming.c"
click node_streaming "https://github.com/opensensor/lightnvr/blob/main/src/video/stream_manager.c"
click node_detection "https://github.com/opensensor/lightnvr/blob/main/src/video/detection_integration.c"
click node_recording "https://github.com/opensensor/lightnvr/blob/main/src/video/recording.c"
click node_playback "https://github.com/opensensor/lightnvr/blob/main/src/web/api_handlers_recordings_playback.c"
click node_storage "https://github.com/opensensor/lightnvr/blob/main/src/storage/storage_manager.c"
click node_storageapi "https://github.com/opensensor/lightnvr/blob/main/src/web/api_handlers_storage_targets.c"
click node_database "https://github.com/opensensor/lightnvr/blob/main/src/database/db_core.c"
click node_auth "https://github.com/opensensor/lightnvr/blob/main/src/web/api_handlers_auth_backend_agnostic.c"
click node_onvif "https://github.com/opensensor/lightnvr/blob/main/src/video/onvif_discovery.c"
click node_mqtt "https://github.com/opensensor/lightnvr/blob/main/src/core/mqtt_client.c"
click node_health "https://github.com/opensensor/lightnvr/blob/main/src/telemetry/system_health.c"
click node_archive "https://github.com/opensensor/lightnvr/blob/main/src/storage/storage_s3.c"

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_webui,node_webapi toneBlue
class node_streaming,node_detection,node_recording,node_playback toneAmber
class node_storage,node_storageapi,node_database toneMint
class node_auth,node_onvif,node_mqtt,node_health,node_archive toneRose
class node_operator,node_camera,node_mqttservice toneIndigo
```

## Components

### Operator experience

- [Web interface](https://github.com/opensensor/lightnvr/blob/main/web/js/components/preact/LiveView.tsx): `web/js/components/preact/LiveView.tsx`
- [REST API](https://github.com/opensensor/lightnvr/blob/main/src/web/api_handlers_streaming.c): `src/web/api_handlers_streaming.c`

### Video workflows

- [Live streaming](https://github.com/opensensor/lightnvr/blob/main/src/video/stream_manager.c): `src/video/stream_manager.c`
- [Detection](https://github.com/opensensor/lightnvr/blob/main/src/video/detection_integration.c): `src/video/detection_integration.c`
- [Recording](https://github.com/opensensor/lightnvr/blob/main/src/video/recording.c): `src/video/recording.c`
- [Playback and investigation](https://github.com/opensensor/lightnvr/blob/main/src/web/api_handlers_recordings_playback.c): `src/web/api_handlers_recordings_playback.c`

### Data and storage

- [Storage management](https://github.com/opensensor/lightnvr/blob/main/src/storage/storage_manager.c): `src/storage/storage_manager.c`
- [Storage controls](https://github.com/opensensor/lightnvr/blob/main/src/web/api_handlers_storage_targets.c): `src/web/api_handlers_storage_targets.c`
- [SQLite database](https://github.com/opensensor/lightnvr/blob/main/src/database/db_core.c): `src/database/db_core.c`

### Security and operations

- [Authentication](https://github.com/opensensor/lightnvr/blob/main/src/web/api_handlers_auth_backend_agnostic.c): `src/web/api_handlers_auth_backend_agnostic.c`
- [ONVIF discovery and events](https://github.com/opensensor/lightnvr/blob/main/src/video/onvif_discovery.c): `src/video/onvif_discovery.c`
- [MQTT events](https://github.com/opensensor/lightnvr/blob/main/src/core/mqtt_client.c): `src/core/mqtt_client.c`
- [System health and metrics](https://github.com/opensensor/lightnvr/blob/main/src/telemetry/system_health.c): `src/telemetry/system_health.c`
- [External archive](https://github.com/opensensor/lightnvr/blob/main/src/storage/storage_s3.c): `src/storage/storage_s3.c`

### Other components

- **Operator**
- **IP camera**
- **MQTT broker**

## Connections

- Operator → Web interface: operates (evidence: `README.md`)
- Web interface → REST API: requests (evidence: `README.md`)
- IP camera → Live streaming: sends video (evidence: `README.md`)
- Live streaming → Recording: records streams (evidence: `README.md`)
- Live streaming → Detection: analyzes video (evidence: `README.md`)
- Web interface → Playback and investigation: reviews footage (evidence: `README.md`)
- REST API → Storage controls: configures storage (evidence: `src/web/api_handlers_storage_targets.c`)
- Storage controls → SQLite database: reads and writes (evidence: `src/web/api_handlers_storage_targets.c`)
- Storage controls → Storage management: probes targets (evidence: `src/web/api_handlers_storage_targets.c`)
- Storage management → SQLite database: reads recording data (evidence: `src/storage/storage_manager.c`)
- Operator → ONVIF discovery and events: discovers cameras (evidence: `README.md`)
- Operator → Authentication: authenticates (evidence: `README.md`)
- MQTT events → MQTT broker: publishes events (evidence: `README.md`)
- Operator → System health and metrics: views health (evidence: `README.md`)
- Storage management → External archive: archives recordings (evidence: `README.md`)
