# motion-project/motion architecture

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

- Interactive diagram: https://gitdiagram.com/motion-project/motion
- Repository: https://github.com/motion-project/motion

## Overview

Motion monitors camera video for image changes. Camera input is acquired from local devices or network streams, processed per camera for motion detection, and can produce snapshots, recordings, and web-accessible views; configuration, scheduling, logging, and database support round out the runtime. The excerpts directly show camera setup for network/libcamera sources, motion-difference processing, and snapshot handling. Other links are limited to references in the source index or are marked unverified because the relevant implementation was not shown.

Main entry points: [`src/camera.cpp`](https://github.com/motion-project/motion/blob/master/src/camera.cpp) (Camera handler), [`src/webu_ans.cpp`](https://github.com/motion-project/motion/blob/master/src/webu_ans.cpp) (Request handling), [`src/motion.cpp`](https://github.com/motion-project/motion/blob/master/src/motion.cpp) (Application runtime), [`src/webu.cpp`](https://github.com/motion-project/motion/blob/master/src/webu.cpp) (Web server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Runtime and configuration"]
  node_application["Application runtime<br/>[motion.cpp]"]
  node_configuration["Configuration<br/>[conf.cpp]"]
  node_schedule["Scheduling<br/>[schedule.cpp]"]
  node_logging["Logging<br/>[logger.hpp]"]
end

subgraph group_capture["Capture and detection"]
  node_camera["Camera handler<br/>[camera.cpp]"]
  node_v4l2["V4L2 capture<br/>[video_v4l2.cpp]"]
  node_network_camera["Network capture<br/>[netcam.cpp]"]
  node_libcamera["libcamera capture<br/>[libcam.cpp]"]
  node_motion_detection["Motion detection<br/>[alg.cpp]"]
  node_secondary_detection["Secondary detection<br/>[alg_sec.cpp]"]
  node_image_drawing["Image drawing<br/>[draw.cpp]"]
end

subgraph group_media["Media outputs"]
  node_movie["Movie recording<br/>[movie.cpp]"]
  node_pictures["Snapshots and images<br/>[picture.cpp]"]
  node_video_conversion["Video conversion<br/>[video_convert.cpp]"]
  node_jpeg_utilities["JPEG utilities<br/>[jpegutils.cpp]"]
  node_rotation["Image rotation<br/>[rotate.cpp]"]
  node_loopback["Video loopback<br/>[video_loopback.cpp]"]
  node_sound["Sound processing<br/>[sound.cpp]"]
end

subgraph group_web["Web and persistence"]
  node_web_server["Web server<br/>[webu.cpp]"]
  node_web_answers["Request handling<br/>[webu_ans.cpp]"]
  node_web_streams["Video streams<br/>[webu_stream.cpp]"]
  node_all_camera_view["All-camera view<br/>[webu_allcam.cpp]"]
  node_database[("Database<br/>[dbse.cpp]")]
  node_web_controls["Web controls<br/>[webu_post.cpp]"]
  node_web_json["JSON responses<br/>[webu_json.cpp]"]
  node_web_mpegts["MPEG-TS output<br/>[webu_mpegts.cpp]"]
  node_web_files["File responses<br/>[webu_file.cpp]"]
  node_web_text["Text responses<br/>[webu_text.cpp]"]
  node_web_get_image["Image requests<br/>[webu_getimg.cpp]"]
end

node_operator(("Operator"))
node_camera_input(("Camera input"))

node_operator -.->|"configures"| node_configuration
node_camera_input -.->|"supplies video"| node_camera
node_camera -->|"starts capture"| node_network_camera
node_camera -->|"creates capture"| node_libcamera
node_camera -->|"computes differences"| node_motion_detection
node_camera -->|"processes snapshots"| node_pictures
node_application -.->|"coordinates"| node_camera
node_application -.->|"uses settings"| node_configuration
node_camera -.->|"selects capture"| node_v4l2
node_camera -.->|"invokes detection"| node_secondary_detection
node_camera -.->|"renders images"| node_image_drawing
node_camera -.->|"records events"| node_movie
node_camera -.->|"rotates images"| node_rotation
node_camera -.->|"outputs video"| node_loopback
node_application -.->|"uses schedule"| node_schedule
node_application -.->|"starts sound"| node_sound
node_application -.->|"starts database"| node_database
node_application -.->|"starts web"| node_web_server
node_operator -.->|"requests views"| node_web_server
node_web_server -->|"dispatches requests"| node_web_answers
node_web_answers -->|"routes controls"| node_web_controls
node_web_answers -->|"routes JSON"| node_web_json
node_web_answers -->|"routes streams"| node_web_streams
node_web_answers -->|"routes files"| node_web_files
node_web_answers -->|"routes text"| node_web_text
node_web_answers -->|"routes MPEG-TS"| node_web_mpegts
node_web_server -->|"dispatches view"| node_all_camera_view
node_web_server -.->|"dispatches images"| node_web_get_image
node_web_streams -.->|"uses utilities"| node_jpeg_utilities
node_web_mpegts -.->|"uses images"| node_pictures
node_pictures -.->|"records metadata"| node_database
node_movie -.->|"records metadata"| node_database

click node_application "https://github.com/motion-project/motion/blob/master/src/motion.cpp"
click node_configuration "https://github.com/motion-project/motion/blob/master/src/conf.cpp"
click node_schedule "https://github.com/motion-project/motion/blob/master/src/schedule.cpp"
click node_logging "https://github.com/motion-project/motion/blob/master/src/logger.hpp"
click node_camera "https://github.com/motion-project/motion/blob/master/src/camera.cpp"
click node_v4l2 "https://github.com/motion-project/motion/blob/master/src/video_v4l2.cpp"
click node_network_camera "https://github.com/motion-project/motion/blob/master/src/netcam.cpp"
click node_libcamera "https://github.com/motion-project/motion/blob/master/src/libcam.cpp"
click node_motion_detection "https://github.com/motion-project/motion/blob/master/src/alg.cpp"
click node_secondary_detection "https://github.com/motion-project/motion/blob/master/src/alg_sec.cpp"
click node_image_drawing "https://github.com/motion-project/motion/blob/master/src/draw.cpp"
click node_movie "https://github.com/motion-project/motion/blob/master/src/movie.cpp"
click node_pictures "https://github.com/motion-project/motion/blob/master/src/picture.cpp"
click node_video_conversion "https://github.com/motion-project/motion/blob/master/src/video_convert.cpp"
click node_web_server "https://github.com/motion-project/motion/blob/master/src/webu.cpp"
click node_web_answers "https://github.com/motion-project/motion/blob/master/src/webu_ans.cpp"
click node_web_streams "https://github.com/motion-project/motion/blob/master/src/webu_stream.cpp"
click node_all_camera_view "https://github.com/motion-project/motion/blob/master/src/webu_allcam.cpp"
click node_database "https://github.com/motion-project/motion/blob/master/src/dbse.cpp"
click node_web_controls "https://github.com/motion-project/motion/blob/master/src/webu_post.cpp"
click node_web_json "https://github.com/motion-project/motion/blob/master/src/webu_json.cpp"
click node_web_mpegts "https://github.com/motion-project/motion/blob/master/src/webu_mpegts.cpp"
click node_web_files "https://github.com/motion-project/motion/blob/master/src/webu_file.cpp"
click node_web_text "https://github.com/motion-project/motion/blob/master/src/webu_text.cpp"
click node_web_get_image "https://github.com/motion-project/motion/blob/master/src/webu_getimg.cpp"
click node_jpeg_utilities "https://github.com/motion-project/motion/blob/master/src/jpegutils.cpp"
click node_rotation "https://github.com/motion-project/motion/blob/master/src/rotate.cpp"
click node_loopback "https://github.com/motion-project/motion/blob/master/src/video_loopback.cpp"
click node_sound "https://github.com/motion-project/motion/blob/master/src/sound.cpp"

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_application,node_configuration,node_schedule,node_logging toneBlue
class node_camera,node_v4l2,node_network_camera,node_libcamera,node_motion_detection,node_secondary_detection,node_image_drawing toneAmber
class node_movie,node_pictures,node_video_conversion,node_jpeg_utilities,node_rotation,node_loopback,node_sound toneMint
class node_web_server,node_web_answers,node_web_streams,node_all_camera_view,node_database,node_web_controls,node_web_json,node_web_mpegts,node_web_files,node_web_text,node_web_get_image toneRose
class node_operator,node_camera_input toneIndigo
```

## Components

### Runtime and configuration

- [Application runtime](https://github.com/motion-project/motion/blob/master/src/motion.cpp): `src/motion.cpp`
- [Configuration](https://github.com/motion-project/motion/blob/master/src/conf.cpp): `src/conf.cpp`
- [Scheduling](https://github.com/motion-project/motion/blob/master/src/schedule.cpp): `src/schedule.cpp`
- [Logging](https://github.com/motion-project/motion/blob/master/src/logger.hpp): `src/logger.hpp`

### Capture and detection

- [Camera handler](https://github.com/motion-project/motion/blob/master/src/camera.cpp): `src/camera.cpp`
- [V4L2 capture](https://github.com/motion-project/motion/blob/master/src/video_v4l2.cpp): `src/video_v4l2.cpp`
- [Network capture](https://github.com/motion-project/motion/blob/master/src/netcam.cpp): `src/netcam.cpp`
- [libcamera capture](https://github.com/motion-project/motion/blob/master/src/libcam.cpp): `src/libcam.cpp`
- [Motion detection](https://github.com/motion-project/motion/blob/master/src/alg.cpp): `src/alg.cpp`
- [Secondary detection](https://github.com/motion-project/motion/blob/master/src/alg_sec.cpp): `src/alg_sec.cpp`
- [Image drawing](https://github.com/motion-project/motion/blob/master/src/draw.cpp): `src/draw.cpp`

### Media outputs

- [Movie recording](https://github.com/motion-project/motion/blob/master/src/movie.cpp): `src/movie.cpp`
- [Snapshots and images](https://github.com/motion-project/motion/blob/master/src/picture.cpp): `src/picture.cpp`
- [Video conversion](https://github.com/motion-project/motion/blob/master/src/video_convert.cpp): `src/video_convert.cpp`
- [JPEG utilities](https://github.com/motion-project/motion/blob/master/src/jpegutils.cpp): `src/jpegutils.cpp`
- [Image rotation](https://github.com/motion-project/motion/blob/master/src/rotate.cpp): `src/rotate.cpp`
- [Video loopback](https://github.com/motion-project/motion/blob/master/src/video_loopback.cpp): `src/video_loopback.cpp`
- [Sound processing](https://github.com/motion-project/motion/blob/master/src/sound.cpp): `src/sound.cpp`

### Web and persistence

- [Web server](https://github.com/motion-project/motion/blob/master/src/webu.cpp): `src/webu.cpp`
- [Request handling](https://github.com/motion-project/motion/blob/master/src/webu_ans.cpp): `src/webu_ans.cpp`
- [Video streams](https://github.com/motion-project/motion/blob/master/src/webu_stream.cpp): `src/webu_stream.cpp`
- [All-camera view](https://github.com/motion-project/motion/blob/master/src/webu_allcam.cpp): `src/webu_allcam.cpp`
- [Database](https://github.com/motion-project/motion/blob/master/src/dbse.cpp): `src/dbse.cpp`
- [Web controls](https://github.com/motion-project/motion/blob/master/src/webu_post.cpp): `src/webu_post.cpp`
- [JSON responses](https://github.com/motion-project/motion/blob/master/src/webu_json.cpp): `src/webu_json.cpp`
- [MPEG-TS output](https://github.com/motion-project/motion/blob/master/src/webu_mpegts.cpp): `src/webu_mpegts.cpp`
- [File responses](https://github.com/motion-project/motion/blob/master/src/webu_file.cpp): `src/webu_file.cpp`
- [Text responses](https://github.com/motion-project/motion/blob/master/src/webu_text.cpp): `src/webu_text.cpp`
- [Image requests](https://github.com/motion-project/motion/blob/master/src/webu_getimg.cpp): `src/webu_getimg.cpp`

### Other components

- **Operator**
- **Camera input**

## Connections

- Operator → Configuration: configures
- Camera input → Camera handler: supplies video
- Camera handler → Network capture: starts capture (evidence: `src/camera.cpp`)
- Camera handler → libcamera capture: creates capture (evidence: `src/camera.cpp`)
- Camera handler → Motion detection: computes differences (evidence: `src/camera.cpp`)
- Camera handler → Snapshots and images: processes snapshots (evidence: `src/camera.cpp`)
- Application runtime → Camera handler: coordinates
- Application runtime → Configuration: uses settings
- Camera handler → V4L2 capture: selects capture
- Camera handler → Secondary detection: invokes detection
- Camera handler → Image drawing: renders images
- Camera handler → Movie recording: records events
- Camera handler → Image rotation: rotates images
- Camera handler → Video loopback: outputs video
- Application runtime → Scheduling: uses schedule
- Application runtime → Sound processing: starts sound
- Application runtime → Database: starts database
- Application runtime → Web server: starts web
- Operator → Web server: requests views
- Web server → Request handling: dispatches requests (evidence: `src/webu.cpp`)
- Request handling → Web controls: routes controls (evidence: `src/webu_ans.cpp`)
- Request handling → JSON responses: routes JSON (evidence: `src/webu_ans.cpp`)
- Request handling → Video streams: routes streams (evidence: `src/webu_ans.cpp`)
- Request handling → File responses: routes files (evidence: `src/webu_ans.cpp`)
- Request handling → Text responses: routes text (evidence: `src/webu_ans.cpp`)
- Request handling → MPEG-TS output: routes MPEG-TS (evidence: `src/webu_ans.cpp`)
- Web server → All-camera view: dispatches view (evidence: `src/webu.cpp`)
- Web server → Image requests: dispatches images
- Video streams → JPEG utilities: uses utilities
- MPEG-TS output → Snapshots and images: uses images
- Snapshots and images → Database: records metadata
- Movie recording → Database: records metadata
