# scottlamb/moonfire-nvr architecture

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

- Interactive diagram: https://gitdiagram.com/scottlamb/moonfire-nvr
- Repository: https://github.com/scottlamb/moonfire-nvr

## Overview

Moonfire NVR records camera streams to disk, indexes recording metadata in SQLite, and serves a web UI for browsing, trimming, live viewing, and administration. The main runtime path is camera streams into the recorder, persisted samples and metadata, then web requests and UI results. The README documents the product capabilities; source excerpts and the SOURCE INDEX support several internal links. Some web-to-database and request-to-result details are unsampled, so those links are omitted rather than inferred.

Main entry points: [`ui/src/App.tsx`](https://github.com/scottlamb/moonfire-nvr/blob/master/ui/src/App.tsx) (UI Application), [`server/db/db.rs`](https://github.com/scottlamb/moonfire-nvr/blob/master/server/db/db.rs) (Recording Index), [`server/src/web/mod.rs`](https://github.com/scottlamb/moonfire-nvr/blob/master/server/src/web/mod.rs) (HTTP Web Server), [`ui/src/api.ts`](https://github.com/scottlamb/moonfire-nvr/blob/master/ui/src/api.ts) (API Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Recording Ingest"]
  node_recorder["Stream Recorder<br/>[streamer.rs]"]
  node_stream["Stream Handling<br/>[stream.rs]"]
end

subgraph group_storage["Recording Storage"]
  node_dbcore["Recording Index<br/>[db.rs]"]
  node_recordings["Recording Metadata<br/>[recording.rs]"]
  node_sampledir["Sample Directories<br/>[mod.rs]"]
  node_dirwriter["Sample Writer<br/>[writer.rs]"]
  node_authstore["Users And Sessions<br/>[auth.rs]"]
  node_upgrade["Schema Upgrades<br/>[mod.rs]"]
end

subgraph group_server["Server Runtime"]
  node_run["Run Command<br/>[mod.rs]"]
  node_webserver["HTTP Web Server<br/>[mod.rs]"]
  node_mp4["MP4 Construction<br/>[mp4.rs]"]
  node_body["Request Bodies<br/>[body.rs]"]
end

subgraph group_webui["Web Interface"]
  node_uiapp["UI Application<br/>[App.tsx]"]
  node_apiclient["API Client<br/>[api.ts]"]
  node_videolist["Recording Browser<br/>[index.tsx]"]
  node_liveview["Live View<br/>[index.tsx]"]
end

subgraph group_admin["Administration"]
  node_useradmin["User Management<br/>[index.tsx]"]
  node_login["Login UI<br/>[Login.tsx]"]
  node_config["Console Configuration<br/>[mod.rs]"]
end

node_camera(("IP Cameras"))
node_sqlite[("SQLite Database")]
node_disk[("Video Sample Files")]
node_browser(("Browser User"))

node_camera -->|"sends streams"| node_recorder
node_recorder -->|"handles streams"| node_stream
node_run -->|"starts streamers"| node_recorder
node_run -->|"starts server"| node_webserver
node_dbcore -->|"uses metadata"| node_recordings
node_dbcore -->|"manages directories"| node_sampledir
node_sampledir -->|"delegates writes"| node_dirwriter
node_dbcore -->|"uses authentication"| node_authstore
node_dbcore -->|"stores metadata"| node_sqlite
node_dirwriter -->|"writes samples"| node_disk
node_upgrade -->|"upgrades schema"| node_sqlite
node_browser -->|"uses interface"| node_uiapp
node_uiapp -->|"fetches data"| node_apiclient
node_uiapp -->|"routes to"| node_videolist
node_uiapp -->|"routes to"| node_liveview
node_uiapp -->|"routes to"| node_useradmin
node_uiapp -->|"renders"| node_login
node_videolist -->|"requests recordings"| node_apiclient
node_useradmin -->|"manages users"| node_apiclient
node_apiclient -->|"calls HTTP API"| node_webserver
node_webserver -->|"serves MP4"| node_mp4
node_webserver -->|"parses requests"| node_body
node_videolist -->|"requests trimmed video"| node_mp4
node_config -->|"supports console setup"| node_browser

click node_recorder "https://github.com/scottlamb/moonfire-nvr/blob/master/server/src/streamer.rs"
click node_stream "https://github.com/scottlamb/moonfire-nvr/blob/master/server/src/stream.rs"
click node_dbcore "https://github.com/scottlamb/moonfire-nvr/blob/master/server/db/db.rs"
click node_recordings "https://github.com/scottlamb/moonfire-nvr/blob/master/server/db/recording.rs"
click node_sampledir "https://github.com/scottlamb/moonfire-nvr/blob/master/server/db/dir/mod.rs"
click node_dirwriter "https://github.com/scottlamb/moonfire-nvr/blob/master/server/db/dir/writer.rs"
click node_authstore "https://github.com/scottlamb/moonfire-nvr/blob/master/server/db/auth.rs"
click node_run "https://github.com/scottlamb/moonfire-nvr/blob/master/server/src/cmds/run/mod.rs"
click node_webserver "https://github.com/scottlamb/moonfire-nvr/blob/master/server/src/web/mod.rs"
click node_mp4 "https://github.com/scottlamb/moonfire-nvr/blob/master/server/src/mp4.rs"
click node_body "https://github.com/scottlamb/moonfire-nvr/blob/master/server/src/body.rs"
click node_upgrade "https://github.com/scottlamb/moonfire-nvr/blob/master/server/db/upgrade/mod.rs"
click node_uiapp "https://github.com/scottlamb/moonfire-nvr/blob/master/ui/src/App.tsx"
click node_apiclient "https://github.com/scottlamb/moonfire-nvr/blob/master/ui/src/api.ts"
click node_videolist "https://github.com/scottlamb/moonfire-nvr/blob/master/ui/src/List/index.tsx"
click node_liveview "https://github.com/scottlamb/moonfire-nvr/blob/master/ui/src/Live/index.tsx"
click node_useradmin "https://github.com/scottlamb/moonfire-nvr/blob/master/ui/src/Users/index.tsx"
click node_login "https://github.com/scottlamb/moonfire-nvr/blob/master/ui/src/Login.tsx"
click node_config "https://github.com/scottlamb/moonfire-nvr/blob/master/server/src/cmds/config/mod.rs"

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_recorder,node_stream,node_browser toneBlue
class node_dbcore,node_recordings,node_sampledir,node_dirwriter,node_authstore,node_upgrade,node_sqlite,node_disk toneAmber
class node_run,node_webserver,node_mp4,node_body toneMint
class node_uiapp,node_apiclient,node_videolist,node_liveview toneRose
class node_useradmin,node_login,node_config,node_camera toneIndigo
```

## Components

### Recording Ingest

- [Stream Recorder](https://github.com/scottlamb/moonfire-nvr/blob/master/server/src/streamer.rs): `server/src/streamer.rs`
- [Stream Handling](https://github.com/scottlamb/moonfire-nvr/blob/master/server/src/stream.rs): `server/src/stream.rs`

### Recording Storage

- [Recording Index](https://github.com/scottlamb/moonfire-nvr/blob/master/server/db/db.rs): `server/db/db.rs`
- [Recording Metadata](https://github.com/scottlamb/moonfire-nvr/blob/master/server/db/recording.rs): `server/db/recording.rs`
- [Sample Directories](https://github.com/scottlamb/moonfire-nvr/blob/master/server/db/dir/mod.rs): `server/db/dir/mod.rs`
- [Sample Writer](https://github.com/scottlamb/moonfire-nvr/blob/master/server/db/dir/writer.rs): `server/db/dir/writer.rs`
- [Users And Sessions](https://github.com/scottlamb/moonfire-nvr/blob/master/server/db/auth.rs): `server/db/auth.rs`
- [Schema Upgrades](https://github.com/scottlamb/moonfire-nvr/blob/master/server/db/upgrade/mod.rs): `server/db/upgrade/mod.rs`

### Server Runtime

- [Run Command](https://github.com/scottlamb/moonfire-nvr/blob/master/server/src/cmds/run/mod.rs): `server/src/cmds/run/mod.rs`
- [HTTP Web Server](https://github.com/scottlamb/moonfire-nvr/blob/master/server/src/web/mod.rs): `server/src/web/mod.rs`
- [MP4 Construction](https://github.com/scottlamb/moonfire-nvr/blob/master/server/src/mp4.rs): `server/src/mp4.rs`
- [Request Bodies](https://github.com/scottlamb/moonfire-nvr/blob/master/server/src/body.rs): `server/src/body.rs`

### Web Interface

- [UI Application](https://github.com/scottlamb/moonfire-nvr/blob/master/ui/src/App.tsx): `ui/src/App.tsx`
- [API Client](https://github.com/scottlamb/moonfire-nvr/blob/master/ui/src/api.ts): `ui/src/api.ts`
- [Recording Browser](https://github.com/scottlamb/moonfire-nvr/blob/master/ui/src/List/index.tsx): `ui/src/List/index.tsx`
- [Live View](https://github.com/scottlamb/moonfire-nvr/blob/master/ui/src/Live/index.tsx): `ui/src/Live/index.tsx`

### Administration

- [User Management](https://github.com/scottlamb/moonfire-nvr/blob/master/ui/src/Users/index.tsx): `ui/src/Users/index.tsx`
- [Login UI](https://github.com/scottlamb/moonfire-nvr/blob/master/ui/src/Login.tsx): `ui/src/Login.tsx`
- [Console Configuration](https://github.com/scottlamb/moonfire-nvr/blob/master/server/src/cmds/config/mod.rs): `server/src/cmds/config/mod.rs`

### Other components

- **IP Cameras**
- **SQLite Database**
- **Video Sample Files**
- **Browser User**

## Connections

- IP Cameras → Stream Recorder: sends streams
- Stream Recorder → Stream Handling: handles streams (evidence: `server/src/streamer.rs`)
- Run Command → Stream Recorder: starts streamers (evidence: `server/src/cmds/run/mod.rs`)
- Run Command → HTTP Web Server: starts server (evidence: `server/src/cmds/run/mod.rs`)
- Recording Index → Recording Metadata: uses metadata (evidence: `server/db/db.rs`)
- Recording Index → Sample Directories: manages directories (evidence: `server/db/db.rs`)
- Sample Directories → Sample Writer: delegates writes (evidence: `server/db/dir/mod.rs`)
- Recording Index → Users And Sessions: uses authentication (evidence: `server/db/db.rs`)
- Recording Index → SQLite Database: stores metadata
- Sample Writer → Video Sample Files: writes samples
- Schema Upgrades → SQLite Database: upgrades schema
- Browser User → UI Application: uses interface
- UI Application → API Client: fetches data (evidence: `ui/src/App.tsx`)
- UI Application → Recording Browser: routes to (evidence: `ui/src/App.tsx`)
- UI Application → Live View: routes to (evidence: `ui/src/App.tsx`)
- UI Application → User Management: routes to (evidence: `ui/src/App.tsx`)
- UI Application → Login UI: renders (evidence: `ui/src/App.tsx`)
- Recording Browser → API Client: requests recordings (evidence: `ui/src/List/index.tsx`)
- User Management → API Client: manages users (evidence: `ui/src/Users/index.tsx`)
- API Client → HTTP Web Server: calls HTTP API
- HTTP Web Server → MP4 Construction: serves MP4 (evidence: `server/src/web/mod.rs`)
- HTTP Web Server → Request Bodies: parses requests (evidence: `server/src/web/mod.rs`)
- Recording Browser → MP4 Construction: requests trimmed video
- Console Configuration → Browser User: supports console setup
