# jairajreddy/crowd_detection_-aiml architecture

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

- Interactive diagram: https://gitdiagram.com/jairajreddy/crowd_detection_-aiml
- Repository: https://github.com/jairajreddy/crowd_detection_-aiml

## Overview

AI Crowd Analytics is a Flask surveillance application: users view a live webcam stream or upload a video, then see crowd statistics, a heatmap, and a downloadable text report. The upload route coordinates video processing and each analysis output; live detection is served separately through streaming and count routes. A separate PyTorch dataset/model training workflow is also present, but the sampled application code does not connect it to runtime inference. The graph follows explicit calls and README-described capabilities; unsampled UI wiring is omitted.

Main entry points: [`app.py`](https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/app.py) (Flask routes), [`heatmap_generator.py`](https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/heatmap_generator.py) (Heatmap generator), [`yolo_stream.py`](https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/yolo_stream.py) (Webcam stream), [`train.py`](https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/train.py) (Training workflow)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web application"]
  node_app["Flask routes<br/>[app.py]"]
  node_pages["Web pages"]
  node_uploads[("Uploaded videos")]
end

subgraph group_live["Live detection"]
  node_stream["Webcam stream<br/>[yolo_stream.py]"]
  node_detector{{"YOLO detector"}}
end

subgraph group_analysis["Video analysis"]
  node_processor["Video processor<br/>[video_processor.py]"]
  node_analytics["Summary builder<br/>[analytics.py]"]
  node_heatmap["Heatmap generator"]
  node_reports["Report generator"]
  node_heatmapfile["Heatmap image"]
  node_reportfile["Text report"]
end

subgraph group_training["Model training"]
  node_dataset["Crowd dataset<br/>[dataset.py]"]
  node_counter["Crowd counter<br/>[model.py]"]
  node_trainer["Training workflow<br/>[train.py]"]
end

node_user(("User"))

node_user -->|"uses"| node_app
node_app -->|"renders"| node_pages
node_app -->|"streams frames"| node_stream
node_app -->|"reads count"| node_stream
node_user -->|"uploads video"| node_app
node_app -->|"saves video"| node_uploads
node_app -->|"processes video"| node_processor
node_processor -->|"runs inference"| node_detector
node_app -->|"builds summary"| node_analytics
node_app -->|"generates heatmap"| node_heatmap
node_heatmap -->|"runs inference"| node_detector
node_heatmap -->|"writes image"| node_heatmapfile
node_app -->|"generates report"| node_reports
node_reports -->|"writes report"| node_reportfile
node_stream -->|"runs inference"| node_detector
node_trainer -->|"loads data"| node_dataset
node_trainer -->|"trains model"| node_counter

click node_app "https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/app.py"
click node_pages "https://github.com/jairajreddy/crowd_detection_-aiml/tree/main/templates"
click node_uploads "https://github.com/jairajreddy/crowd_detection_-aiml/tree/main/static"
click node_stream "https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/yolo_stream.py"
click node_processor "https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/video_processor.py"
click node_analytics "https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/analytics.py"
click node_heatmap "https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/heatmap_generator.py"
click node_reports "https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/report_generator.py"
click node_heatmapfile "https://github.com/jairajreddy/crowd_detection_-aiml/tree/main/static"
click node_reportfile "https://github.com/jairajreddy/crowd_detection_-aiml/tree/main/static"
click node_dataset "https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/dataset.py"
click node_counter "https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/model.py"
click node_trainer "https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/train.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_app,node_pages,node_uploads,node_user toneBlue
class node_stream,node_detector toneAmber
class node_processor,node_analytics,node_heatmap,node_reports,node_heatmapfile,node_reportfile toneMint
class node_dataset,node_counter,node_trainer toneRose
```

## Components

### Web application

- [Flask routes](https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/app.py): `app.py`
- [Web pages](https://github.com/jairajreddy/crowd_detection_-aiml/tree/main/templates): `templates`
- [Uploaded videos](https://github.com/jairajreddy/crowd_detection_-aiml/tree/main/static): `static`

### Live detection

- [Webcam stream](https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/yolo_stream.py): `yolo_stream.py`
- **YOLO detector**

### Video analysis

- [Video processor](https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/video_processor.py): `video_processor.py`
- [Summary builder](https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/analytics.py): `analytics.py`
- [Heatmap generator](https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/heatmap_generator.py): `heatmap_generator.py`
- [Report generator](https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/report_generator.py): `report_generator.py`
- [Heatmap image](https://github.com/jairajreddy/crowd_detection_-aiml/tree/main/static): `static`
- [Text report](https://github.com/jairajreddy/crowd_detection_-aiml/tree/main/static): `static`

### Model training

- [Crowd dataset](https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/dataset.py): `dataset.py`
- [Crowd counter](https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/model.py): `model.py`
- [Training workflow](https://github.com/jairajreddy/crowd_detection_-aiml/blob/main/train.py): `train.py`

### Other components

- **User**

## Connections

- User → Flask routes: uses (evidence: `README.md`)
- Flask routes → Web pages: renders (evidence: `app.py`)
- Flask routes → Webcam stream: streams frames (evidence: `app.py`)
- Flask routes → Webcam stream: reads count (evidence: `app.py`)
- User → Flask routes: uploads video (evidence: `app.py`)
- Flask routes → Uploaded videos: saves video (evidence: `app.py`)
- Flask routes → Video processor: processes video (evidence: `app.py`)
- Video processor → YOLO detector: runs inference (evidence: `video_processor.py`)
- Flask routes → Summary builder: builds summary (evidence: `app.py`)
- Flask routes → Heatmap generator: generates heatmap (evidence: `app.py`)
- Heatmap generator → YOLO detector: runs inference (evidence: `heatmap_generator.py`)
- Heatmap generator → Heatmap image: writes image (evidence: `heatmap_generator.py`)
- Flask routes → Report generator: generates report (evidence: `app.py`)
- Report generator → Text report: writes report (evidence: `report_generator.py`)
- Webcam stream → YOLO detector: runs inference (evidence: `yolo_stream.py`)
- Training workflow → Crowd dataset: loads data (evidence: `train.py`)
- Training workflow → Crowd counter: trains model (evidence: `train.py`)
