# bokutosss/motion architecture

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

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

## Overview

This is a phone-connected motion-detection service with a browser dashboard. A user connects a phone or webcam, the runtime processes frames for motion and optional object/pose recognition, then presents a live feed and records events as snapshots; optional Telegram alerts can notify the user. The sampled source shows these responsibilities split between the Flask app and a camera-first runtime used by the WSGI entry point. The README is empty, so capability coverage and relationships rely on the supplied excerpts; unsampled routes and internals are not expanded.

Main entry points: [`camera_runtime.py`](https://github.com/bokutosss/motion/blob/main/camera_runtime.py) (Camera runtime), [`app.py`](https://github.com/bokutosss/motion/blob/main/app.py) (Web dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Camera capture"]
  node_runtime["Camera runtime<br/>[camera_runtime.py]"]
  node_frame_input["Frame input<br/>[app.py]"]
end

subgraph group_analysis["Detection and events"]
  node_motion["Motion detection<br/>[camera_runtime.py]"]
  node_object_pose["Object and pose detection<br/>[app.py]"]
end

subgraph group_web["Dashboard and API"]
  node_dashboard["Web dashboard<br/>[app.py]"]
  node_api["Camera and control API<br/>[app.py]"]
  node_auth["Basic authentication<br/>[app.py]"]
  node_mjpeg["MJPEG stream<br/>[app.py]"]
end

subgraph group_delivery["Alerts and media"]
  node_event["Event recording<br/>[app.py]"]
  node_snapshots[("Snapshot files<br/>[app.py]")]
end

node_user(("Phone user"))
node_phone_camera(("Phone camera"))
node_local_camera(("Local camera"))
node_telegram(("Telegram"))

node_user -->|"opens"| node_dashboard
node_dashboard -->|"controls camera"| node_api
node_dashboard -->|"captures frames"| node_phone_camera
node_phone_camera -->|"uploads frames"| node_frame_input
node_frame_input -->|"updates phone frames"| node_runtime
node_local_camera -->|"provides video"| node_runtime
node_runtime -->|"processes frames"| node_motion
node_runtime -->|"runs inference"| node_object_pose
node_runtime -->|"records motion"| node_event
node_runtime -->|"publishes JPEG frames"| node_mjpeg
node_mjpeg -->|"streams video"| node_dashboard
node_event -->|"writes snapshots"| node_snapshots
node_dashboard -->|"requests snapshot"| node_snapshots
node_event -->|"sends photo alert"| node_telegram
node_user -->|"authenticates"| node_auth
node_api -->|"checks credentials"| node_auth

click node_dashboard "https://github.com/bokutosss/motion/blob/main/app.py"
click node_api "https://github.com/bokutosss/motion/blob/main/app.py"
click node_auth "https://github.com/bokutosss/motion/blob/main/app.py"
click node_mjpeg "https://github.com/bokutosss/motion/blob/main/app.py"
click node_runtime "https://github.com/bokutosss/motion/blob/main/camera_runtime.py"
click node_frame_input "https://github.com/bokutosss/motion/blob/main/app.py"
click node_motion "https://github.com/bokutosss/motion/blob/main/camera_runtime.py"
click node_object_pose "https://github.com/bokutosss/motion/blob/main/app.py"
click node_event "https://github.com/bokutosss/motion/blob/main/app.py"
click node_snapshots "https://github.com/bokutosss/motion/blob/main/app.py"

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_runtime,node_frame_input,node_user toneBlue
class node_motion,node_object_pose toneAmber
class node_dashboard,node_api,node_auth,node_mjpeg toneMint
class node_event,node_snapshots toneRose
class node_phone_camera,node_local_camera,node_telegram toneIndigo
```

## Components

### Camera capture

- [Camera runtime](https://github.com/bokutosss/motion/blob/main/camera_runtime.py): `camera_runtime.py`
- [Frame input](https://github.com/bokutosss/motion/blob/main/app.py): `app.py`

### Detection and events

- [Motion detection](https://github.com/bokutosss/motion/blob/main/camera_runtime.py): `camera_runtime.py`
- [Object and pose detection](https://github.com/bokutosss/motion/blob/main/app.py): `app.py`

### Dashboard and API

- [Web dashboard](https://github.com/bokutosss/motion/blob/main/app.py): `app.py`
- [Camera and control API](https://github.com/bokutosss/motion/blob/main/app.py): `app.py`
- [Basic authentication](https://github.com/bokutosss/motion/blob/main/app.py): `app.py`
- [MJPEG stream](https://github.com/bokutosss/motion/blob/main/app.py): `app.py`

### Alerts and media

- [Event recording](https://github.com/bokutosss/motion/blob/main/app.py): `app.py`
- [Snapshot files](https://github.com/bokutosss/motion/blob/main/app.py): `app.py`

### Other components

- **Phone user**
- **Phone camera**
- **Local camera**
- **Telegram**

## Connections

- Phone user → Web dashboard: opens (evidence: `app.py`)
- Web dashboard → Camera and control API: controls camera (evidence: `app.py`)
- Web dashboard → Phone camera: captures frames (evidence: `app.py`)
- Phone camera → Frame input: uploads frames (evidence: `app.py`)
- Frame input → Camera runtime: updates phone frames (evidence: `camera_runtime.py`)
- Local camera → Camera runtime: provides video (evidence: `camera_runtime.py`)
- Camera runtime → Motion detection: processes frames (evidence: `camera_runtime.py`)
- Camera runtime → Object and pose detection: runs inference (evidence: `camera_runtime.py`)
- Camera runtime → Event recording: records motion (evidence: `camera_runtime.py`)
- Camera runtime → MJPEG stream: publishes JPEG frames (evidence: `camera_runtime.py`)
- MJPEG stream → Web dashboard: streams video (evidence: `app.py`)
- Event recording → Snapshot files: writes snapshots (evidence: `app.py`)
- Web dashboard → Snapshot files: requests snapshot (evidence: `app.py`)
- Event recording → Telegram: sends photo alert (evidence: `app.py`)
- Phone user → Basic authentication: authenticates (evidence: `app.py`)
- Camera and control API → Basic authentication: checks credentials (evidence: `app.py`)
