# aaryan2304/cctv-video-anomaly-detection architecture

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

- Interactive diagram: https://gitdiagram.com/aaryan2304/cctv-video-anomaly-detection
- Repository: https://github.com/aaryan2304/cctv-video-anomaly-detection

## Overview

This repository is a video-anomaly detection product with a FastAPI service and Streamlit dashboard, plus a separate model training/evaluation workflow. Its runtime path preprocesses uploaded video frames, scores them with a reconstruction model, and exposes anomaly scores and flags. The graph also preserves documented threshold controls, monitoring, and ONNX export. Some route and dashboard wiring was not excerpted, so only documented or source-index-supported relationships are shown.

Main entry points: [`app.py`](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/app.py) (REST API), [`main.py`](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/main.py) (Training workflow), [`models/detector.py`](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/models/detector.py) (Anomaly detector), [`data/preprocessing.py`](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/data/preprocessing.py) (Video preprocessing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_product["Video analysis"]
  node_dashboard["Interactive dashboard<br/>[dashboard.py]"]
  node_api["REST API<br/>[app.py]"]
  node_preprocess["Video preprocessing<br/>[preprocessing.py]"]
  node_scores["Scores and flags<br/>[app.py]"]
  node_presets["Threshold controls<br/>[app.py]"]
end

subgraph group_ml["Detection models"]
  node_autoencoder["Convolutional autoencoder<br/>[autoencoder.py]"]
  node_detector["Anomaly detector<br/>[detector.py]"]
end

subgraph group_training["Training and evaluation"]
  node_train["Training workflow<br/>[main.py]"]
  node_dataset["Video datasets<br/>[dataset.py]"]
  node_synthetic["Synthetic data<br/>[synthetic_data.py]"]
  node_metrics["Performance metrics<br/>[metrics.py]"]
  node_visualizer["Evaluation visualizer<br/>[visualizer.py]"]
end

subgraph group_operations["Operations and export"]
  node_config["Training configuration<br/>[config.py]"]
  node_settings["Service settings<br/>[settings.py]"]
  node_monitoring["Service monitoring<br/>[app.py]"]
  node_onnx["ONNX export<br/>[export_model.py]"]
end

node_user(("Video user"))

node_user -->|"uploads video"| node_dashboard
node_dashboard -.->|"requests analysis"| node_api
node_api -->|"preprocesses frames"| node_preprocess
node_api -->|"runs detection"| node_detector
node_detector -->|"uses model"| node_autoencoder
node_api -->|"returns scores"| node_scores
node_api -->|"offers controls"| node_presets
node_train -->|"loads data"| node_dataset
node_train -->|"preprocesses frames"| node_preprocess
node_train -->|"trains model"| node_detector
node_train -->|"evaluates scores"| node_metrics
node_dataset -->|"uses preprocessor"| node_preprocess
node_train -->|"loads configuration"| node_config
node_api -->|"loads settings"| node_settings
node_api -->|"exposes metrics"| node_monitoring
node_onnx -->|"exports model"| node_autoencoder

click node_dashboard "https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/dashboard.py"
click node_api "https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/app.py"
click node_preprocess "https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/data/preprocessing.py"
click node_scores "https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/app.py"
click node_presets "https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/app.py"
click node_autoencoder "https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/models/autoencoder.py"
click node_detector "https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/models/detector.py"
click node_train "https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/main.py"
click node_dataset "https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/data/dataset.py"
click node_synthetic "https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/data/synthetic_data.py"
click node_metrics "https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/evaluation/metrics.py"
click node_visualizer "https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/evaluation/visualizer.py"
click node_config "https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/config.py"
click node_settings "https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/settings.py"
click node_monitoring "https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/app.py"
click node_onnx "https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/export_model.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_dashboard,node_api,node_preprocess,node_scores,node_presets,node_user toneBlue
class node_autoencoder,node_detector toneAmber
class node_train,node_dataset,node_synthetic,node_metrics,node_visualizer toneMint
class node_config,node_settings,node_monitoring,node_onnx toneRose
```

## Components

### Video analysis

- [Interactive dashboard](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/dashboard.py): `dashboard.py`
- [REST API](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/app.py): `app.py`
- [Video preprocessing](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/data/preprocessing.py): `data/preprocessing.py`
- [Scores and flags](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/app.py): `app.py`
- [Threshold controls](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/app.py): `app.py`

### Detection models

- [Convolutional autoencoder](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/models/autoencoder.py): `models/autoencoder.py`
- [Anomaly detector](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/models/detector.py): `models/detector.py`

### Training and evaluation

- [Training workflow](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/main.py): `main.py`
- [Video datasets](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/data/dataset.py): `data/dataset.py`
- [Synthetic data](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/data/synthetic_data.py): `data/synthetic_data.py`
- [Performance metrics](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/evaluation/metrics.py): `evaluation/metrics.py`
- [Evaluation visualizer](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/evaluation/visualizer.py): `evaluation/visualizer.py`

### Operations and export

- [Training configuration](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/config.py): `config.py`
- [Service settings](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/settings.py): `settings.py`
- [Service monitoring](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/app.py): `app.py`
- [ONNX export](https://github.com/aaryan2304/cctv-video-anomaly-detection/blob/main/export_model.py): `export_model.py`

### Other components

- **Video user**

## Connections

- Video user → Interactive dashboard: uploads video (evidence: `README.md`)
- Interactive dashboard → REST API: requests analysis
- REST API → Video preprocessing: preprocesses frames (evidence: `app.py`)
- REST API → Anomaly detector: runs detection (evidence: `app.py`)
- Anomaly detector → Convolutional autoencoder: uses model (evidence: `models/detector.py`)
- REST API → Scores and flags: returns scores (evidence: `README.md`)
- REST API → Threshold controls: offers controls (evidence: `README.md`)
- Training workflow → Video datasets: loads data (evidence: `main.py`)
- Training workflow → Video preprocessing: preprocesses frames (evidence: `main.py`)
- Training workflow → Anomaly detector: trains model (evidence: `main.py`)
- Training workflow → Performance metrics: evaluates scores (evidence: `main.py`)
- Video datasets → Video preprocessing: uses preprocessor (evidence: `data/dataset.py`)
- Training workflow → Training configuration: loads configuration (evidence: `main.py`)
- REST API → Service settings: loads settings (evidence: `app.py`)
- REST API → Service monitoring: exposes metrics (evidence: `README.md`)
- ONNX export → Convolutional autoencoder: exports model (evidence: `export_model.py`)
