# miladnasiri/vlm-based-car-accident-detection-implementation-guide architecture

> Architecture diagram of the GitHub repository miladnasiri/vlm-based-car-accident-detection-implementation-guide, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide
- Repository: https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide

## Overview

This repository implements VLM-based highway accident detection for local video processing and an optional REST API. The main workflow samples video frames, analyzes them with a vision-language model, filters and annotates detections, and writes a JSON report alongside the annotated video. The API accepts uploads, tracks background jobs, and exposes status, downloads, statistics, and GPU information. The map is based on the README and excerpts of the two core files; unsampled implementation details and undocumented connections are omitted.

Main entry points: [`api-server.py`](https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/api-server.py) (API Endpoints), [`accident-detection-main.py`](https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/accident-detection-main.py) (Video Sampling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_processing["Video Detection"]
  node_cli["CLI Entry"]
  node_video["Video Sampling"]
  node_vlm["VLM Analysis"]
  node_parse["Detection Parsing"]
  node_filter["Confidence Filtering"]
end

subgraph group_outputs["Detection Results"]
  node_annotation["Frame Annotation"]
  node_report["Report Generation"]
  node_annotated_video["Annotated Video"]
end

subgraph group_api["REST API"]
  node_api_routes["API Endpoints<br/>[api-server.py]"]
  node_uploads[("Uploaded Videos<br/>[api-server.py]")]
  node_downloads_stats["Downloads and Stats<br/>[api-server.py]"]
  node_gpu_status["GPU Status<br/>[api-server.py]"]
end

subgraph group_operations["Job Operations"]
  node_jobs[("Job Tracking<br/>[api-server.py]")]
  node_background["Background Processing<br/>[api-server.py]"]
end

node_operator(("Video Operator"))
node_api_client(("API Client"))

node_operator -->|"runs"| node_cli
node_cli -->|"processes video"| node_video
node_video -->|"samples frames"| node_vlm
node_vlm -->|"returns response"| node_parse
node_parse -->|"produces detections"| node_filter
node_video -->|"annotates frames"| node_annotation
node_annotation -->|"writes frames"| node_annotated_video
node_video -->|"generates report"| node_report
node_api_client -->|"submits video"| node_api_routes
node_api_routes -->|"saves upload"| node_uploads
node_api_routes -->|"creates job"| node_jobs
node_api_routes -->|"schedules task"| node_background
node_background -->|"processes video"| node_video
node_background -->|"reads report"| node_report
node_api_routes -->|"serves results"| node_downloads_stats
node_api_routes -->|"reports GPU status"| node_gpu_status

click node_cli "https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/accident-detection-main.py"
click node_video "https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/accident-detection-main.py"
click node_vlm "https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/accident-detection-main.py"
click node_parse "https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/accident-detection-main.py"
click node_filter "https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/accident-detection-main.py"
click node_annotation "https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/accident-detection-main.py"
click node_report "https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/accident-detection-main.py"
click node_annotated_video "https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/accident-detection-main.py"
click node_api_routes "https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/api-server.py"
click node_uploads "https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/api-server.py"
click node_jobs "https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/api-server.py"
click node_background "https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/api-server.py"
click node_downloads_stats "https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/api-server.py"
click node_gpu_status "https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/api-server.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_cli,node_video,node_vlm,node_parse,node_filter,node_api_client toneBlue
class node_annotation,node_report,node_annotated_video toneAmber
class node_api_routes,node_uploads,node_downloads_stats,node_gpu_status toneMint
class node_jobs,node_background toneRose
class node_operator toneIndigo
```

## Components

### Video Detection

- [CLI Entry](https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/accident-detection-main.py): `accident-detection-main.py`
- [Video Sampling](https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/accident-detection-main.py): `accident-detection-main.py`
- [VLM Analysis](https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/accident-detection-main.py): `accident-detection-main.py`
- [Detection Parsing](https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/accident-detection-main.py): `accident-detection-main.py`
- [Confidence Filtering](https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/accident-detection-main.py): `accident-detection-main.py`

### Detection Results

- [Frame Annotation](https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/accident-detection-main.py): `accident-detection-main.py`
- [Report Generation](https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/accident-detection-main.py): `accident-detection-main.py`
- [Annotated Video](https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/accident-detection-main.py): `accident-detection-main.py`

### REST API

- [API Endpoints](https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/api-server.py): `api-server.py`
- [Uploaded Videos](https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/api-server.py): `api-server.py`
- [Downloads and Stats](https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/api-server.py): `api-server.py`
- [GPU Status](https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/api-server.py): `api-server.py`

### Job Operations

- [Job Tracking](https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/api-server.py): `api-server.py`
- [Background Processing](https://github.com/miladnasiri/vlm-based-car-accident-detection-implementation-guide/blob/main/api-server.py): `api-server.py`

### Other components

- **Video Operator**
- **API Client**

## Connections

- Video Operator → CLI Entry: runs (evidence: `README.md`)
- CLI Entry → Video Sampling: processes video (evidence: `accident-detection-main.py`)
- Video Sampling → VLM Analysis: samples frames (evidence: `README.md`)
- VLM Analysis → Detection Parsing: returns response (evidence: `accident-detection-main.py`)
- Detection Parsing → Confidence Filtering: produces detections (evidence: `accident-detection-main.py`)
- Video Sampling → Frame Annotation: annotates frames (evidence: `accident-detection-main.py`)
- Frame Annotation → Annotated Video: writes frames (evidence: `accident-detection-main.py`)
- Video Sampling → Report Generation: generates report (evidence: `accident-detection-main.py`)
- API Client → API Endpoints: submits video (evidence: `README.md`)
- API Endpoints → Uploaded Videos: saves upload (evidence: `api-server.py`)
- API Endpoints → Job Tracking: creates job (evidence: `api-server.py`)
- API Endpoints → Background Processing: schedules task (evidence: `api-server.py`)
- Background Processing → Video Sampling: processes video (evidence: `api-server.py`)
- Background Processing → Report Generation: reads report (evidence: `api-server.py`)
- API Endpoints → Downloads and Stats: serves results (evidence: `api-server.py`)
- API Endpoints → GPU Status: reports GPU status (evidence: `api-server.py`)
