# sai8143/accident-detection-accisense architecture

> Architecture diagram of the GitHub repository sai8143/accident-detection-accisense, 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/sai8143/accident-detection-accisense
- Repository: https://github.com/sai8143/accident-detection-accisense

## Overview

This repository implements a mobile-assisted road-accident detection service. A user captures a photo; the app attaches device location and submits it to the API, which scores the image, applies temporal filtering, and returns a potential/no-accident result. Separate API routes accept video frames or start live camera/RTSP monitoring; confirmed detections can be stored and trigger emergency logging. The graph also shows the persistence and detection layers. Unsampled service modules are included where substantial, but their behavior and connections are not inferred.

Main entry points: [`backend/app/main.py`](https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/main.py) (FastAPI routes), [`mobile-app/src/services/api.js`](https://github.com/sai8143/accident-detection-accisense/blob/main/mobile-app/src/services/api.js) (Alert API client), [`backend/app/services/rtsp_stream.py`](https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/rtsp_stream.py) (Stream processing), [`mobile-app/src/screens/CameraScreen.js`](https://github.com/sai8143/accident-detection-accisense/blob/main/mobile-app/src/screens/CameraScreen.js) (Camera capture)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Mobile App"]
  node_camera_screen["Camera capture<br/>[CameraScreen.js]"]
  node_mobile_api["Alert API client<br/>[api.js]"]
  node_mobile_config["API endpoint config<br/>[config.js]"]
  node_app_entry["App entry<br/>[App.js]"]
end

subgraph group_api["API Orchestration"]
  node_main_api["FastAPI routes<br/>[main.py]"]
  node_schemas["API schemas<br/>[schemas.py]"]
end

subgraph group_detection["Detection Services"]
  node_photo_detector["Photo scoring<br/>[photo_detector.py]"]
  node_temporal_filter["Temporal voting<br/>[temporal_filter.py]"]
  node_decision_engine["Accident decision<br/>[decision_engine.py]"]
  node_video_detector["Video detection<br/>[video_detector.py]"]
  node_rtsp_stream["Stream processing<br/>[rtsp_stream.py]"]
  node_ai_detector["AI detector<br/>[ai_detector.py]"]
  node_crash_classifier["Crash classifier"]
  node_location_service["Location service<br/>[location.py]"]
end

subgraph group_state["Persistence and Alerts"]
  node_database_config[("Database setup<br/>[database.py]")]
  node_accident_model[("Accident records<br/>[models.py]")]
  node_notifier["Emergency notifier<br/>[notifier.py]"]
end

node_user(("Mobile user"))

node_user -->|"captures photo"| node_camera_screen
node_app_entry -->|"renders"| node_camera_screen
node_camera_screen -->|"submits photo"| node_mobile_api
node_mobile_api -->|"reads endpoint"| node_mobile_config
node_mobile_api -->|"posts alert"| node_main_api
node_main_api -->|"scores image"| node_photo_detector
node_main_api -->|"filters score"| node_temporal_filter
node_main_api -->|"decides video result"| node_decision_engine
node_main_api -->|"detects frame"| node_video_detector
node_main_api -->|"starts monitoring"| node_rtsp_stream
node_rtsp_stream -->|"checks frames"| node_video_detector
node_rtsp_stream -->|"alerts on detection"| node_notifier
node_main_api -->|"logs or alerts"| node_notifier
node_main_api -->|"creates record"| node_accident_model
node_main_api -->|"opens session"| node_database_config
node_accident_model -->|"uses base"| node_database_config
node_main_api -->|"uses response schemas"| node_schemas

click node_camera_screen "https://github.com/sai8143/accident-detection-accisense/blob/main/mobile-app/src/screens/CameraScreen.js"
click node_mobile_api "https://github.com/sai8143/accident-detection-accisense/blob/main/mobile-app/src/services/api.js"
click node_mobile_config "https://github.com/sai8143/accident-detection-accisense/blob/main/mobile-app/src/config.js"
click node_app_entry "https://github.com/sai8143/accident-detection-accisense/blob/main/mobile-app/App.js"
click node_main_api "https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/main.py"
click node_schemas "https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/schemas.py"
click node_photo_detector "https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/photo_detector.py"
click node_temporal_filter "https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/temporal_filter.py"
click node_decision_engine "https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/decision_engine.py"
click node_video_detector "https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/video_detector.py"
click node_rtsp_stream "https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/rtsp_stream.py"
click node_ai_detector "https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/ai_detector.py"
click node_crash_classifier "https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/crash_classifier.py"
click node_location_service "https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/location.py"
click node_database_config "https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/database.py"
click node_accident_model "https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/models.py"
click node_notifier "https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/notifier.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_camera_screen,node_mobile_api,node_mobile_config,node_app_entry,node_user toneBlue
class node_main_api,node_schemas toneAmber
class node_photo_detector,node_temporal_filter,node_decision_engine,node_video_detector,node_rtsp_stream,node_ai_detector,node_crash_classifier,node_location_service toneMint
class node_database_config,node_accident_model,node_notifier toneRose
```

## Components

### Mobile App

- [Camera capture](https://github.com/sai8143/accident-detection-accisense/blob/main/mobile-app/src/screens/CameraScreen.js): `mobile-app/src/screens/CameraScreen.js`
- [Alert API client](https://github.com/sai8143/accident-detection-accisense/blob/main/mobile-app/src/services/api.js): `mobile-app/src/services/api.js`
- [API endpoint config](https://github.com/sai8143/accident-detection-accisense/blob/main/mobile-app/src/config.js): `mobile-app/src/config.js`
- [App entry](https://github.com/sai8143/accident-detection-accisense/blob/main/mobile-app/App.js): `mobile-app/App.js`

### API Orchestration

- [FastAPI routes](https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/main.py): `backend/app/main.py`
- [API schemas](https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/schemas.py): `backend/app/schemas.py`

### Detection Services

- [Photo scoring](https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/photo_detector.py): `backend/app/services/photo_detector.py`
- [Temporal voting](https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/temporal_filter.py): `backend/app/services/temporal_filter.py`
- [Accident decision](https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/decision_engine.py): `backend/app/services/decision_engine.py`
- [Video detection](https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/video_detector.py): `backend/app/services/video_detector.py`
- [Stream processing](https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/rtsp_stream.py): `backend/app/services/rtsp_stream.py`
- [AI detector](https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/ai_detector.py): `backend/app/services/ai_detector.py`
- [Crash classifier](https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/crash_classifier.py): `backend/app/services/crash_classifier.py`
- [Location service](https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/location.py): `backend/app/services/location.py`

### Persistence and Alerts

- [Database setup](https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/database.py): `backend/app/database.py`
- [Accident records](https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/models.py): `backend/app/models.py`
- [Emergency notifier](https://github.com/sai8143/accident-detection-accisense/blob/main/backend/app/services/notifier.py): `backend/app/services/notifier.py`

### Other components

- **Mobile user**

## Connections

- Mobile user → Camera capture: captures photo (evidence: `mobile-app/src/screens/CameraScreen.js`)
- App entry → Camera capture: renders (evidence: `mobile-app/App.js`)
- Camera capture → Alert API client: submits photo (evidence: `mobile-app/src/screens/CameraScreen.js`)
- Alert API client → API endpoint config: reads endpoint (evidence: `mobile-app/src/services/api.js`)
- Alert API client → FastAPI routes: posts alert (evidence: `mobile-app/src/services/api.js`)
- FastAPI routes → Photo scoring: scores image (evidence: `backend/app/main.py`)
- FastAPI routes → Temporal voting: filters score (evidence: `backend/app/main.py`)
- FastAPI routes → Accident decision: decides video result (evidence: `backend/app/main.py`)
- FastAPI routes → Video detection: detects frame (evidence: `backend/app/main.py`)
- FastAPI routes → Stream processing: starts monitoring (evidence: `backend/app/main.py`)
- Stream processing → Video detection: checks frames (evidence: `backend/app/services/rtsp_stream.py`)
- Stream processing → Emergency notifier: alerts on detection (evidence: `backend/app/services/rtsp_stream.py`)
- FastAPI routes → Emergency notifier: logs or alerts (evidence: `backend/app/main.py`)
- FastAPI routes → Accident records: creates record (evidence: `backend/app/main.py`)
- FastAPI routes → Database setup: opens session (evidence: `backend/app/main.py`)
- Accident records → Database setup: uses base (evidence: `backend/app/models.py`)
- FastAPI routes → API schemas: uses response schemas (evidence: `backend/app/main.py`)
