# shubhamg2004/crimedetectionsystem architecture

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

- Interactive diagram: https://gitdiagram.com/shubhamg2004/crimedetectionsystem
- Repository: https://github.com/shubhamg2004/crimedetectionsystem

## Overview

Crime Detection System supports camera-based AI detection through incident reporting and station alerts, alongside role-based operations, analytics, mapping, and case management. The main workflow is an operator or camera submitting an image; the backend validates camera access, calls the AI server, stores incident evidence and results, then emits live updates and may notify a nearby police station. The README describes predictive analytics and multi-channel notifications, but sampled code only confirms incident-driven alert delivery and does not expose the analytics implementation details.

Main entry points: [`backend/src/app.js`](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/app.js) (API application), [`backend/src/config/firebase.js`](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/config/firebase.js) (Firebase services), [`backend/src/routes/detect.routes.js`](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/routes/detect.routes.js) (Detection intake), [`backend/src/controllers/incident.controller.js`](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/controllers/incident.controller.js) (Incident creation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web application"]
  node_web_dashboards["Role dashboards"]
  node_web_field["Camera setup"]
  node_web_analytics["Analytics view<br/>[page.js]"]
  node_web_incidents["Incident views<br/>[page.js]"]
  node_web_detection["Image detection<br/>[page.js]"]
end

subgraph group_api["Backend API"]
  node_api_app["API application<br/>[app.js]"]
  node_camera_routes["Camera management<br/>[camera.routes.js]"]
  node_admin_routes["Role administration<br/>[admin.routes.js]"]
  node_detect_routes["Detection intake<br/>[detect.routes.js]"]
  node_incident_routes["Incident endpoints<br/>[incident.routes.js]"]
  node_analytics_routes["Analytics endpoints"]
  node_message_routes["Support messaging<br/>[messages.routes.js]"]
end

subgraph group_detection["AI detection"]
  node_ai_server["AI service<br/>[detector.py]"]
  node_image_detector["Image analysis<br/>[image_detector.py]"]
  node_pose_detector["Pose analysis<br/>[pose_detector.py]"]
  node_reasoning["Detection reasoning<br/>[reasoning_layer.py]"]
end

subgraph group_operations["Incident operations"]
  node_incident_controller["Incident creation"]
  node_station_controller["Station lookup"]
  node_alert_service["Alert dispatch<br/>[alert.service.js]"]
  node_alert_controller["Alert management"]
end

subgraph group_platform["Data and integrations"]
  node_firebase[("Firebase services<br/>[firebase.js]")]
  node_cloudinary["Evidence storage<br/>[cloudinary.js]"]
  node_realtime["Live event server<br/>[server.js]"]
  node_functions["Incident escalation<br/>[index.js]"]
end

node_operators(("Operators"))
node_fieldops(("Field operators"))
node_admin(("Administrators"))
node_camera_device(("Camera device"))
node_twilio["Twilio messaging"]
node_email["Email delivery"]

node_operators -->|"use"| node_web_dashboards
node_fieldops -->|"manage cameras"| node_web_field
node_admin -->|"administer"| node_web_dashboards
node_operators -->|"submit image"| node_web_detection
node_web_dashboards -->|"request data"| node_api_app
node_web_field -->|"manage cameras"| node_api_app
node_web_detection -->|"submit detection"| node_api_app
node_web_incidents -->|"request incidents"| node_api_app
node_web_analytics -->|"request analytics"| node_api_app
node_api_app -->|"dispatch"| node_camera_routes
node_api_app -->|"dispatch"| node_admin_routes
node_api_app -->|"dispatch"| node_detect_routes
node_api_app -->|"dispatch"| node_incident_routes
node_api_app -->|"dispatch"| node_analytics_routes
node_api_app -->|"dispatch"| node_message_routes
node_camera_routes -->|"read and write"| node_firebase
node_admin_routes -->|"manage identities"| node_firebase
node_message_routes -->|"read and write messages"| node_firebase
node_analytics_routes -->|"query data"| node_firebase
node_detect_routes -->|"validate camera; store incident"| node_firebase
node_camera_device -->|"send image"| node_detect_routes
node_detect_routes -->|"forward image"| node_ai_server
node_ai_server -->|"analyze image"| node_image_detector
node_ai_server -->|"analyze pose"| node_pose_detector
node_ai_server -->|"interpret detections"| node_reasoning
node_detect_routes -->|"upload evidence"| node_cloudinary
node_detect_routes -->|"find nearest station"| node_station_controller
node_station_controller -->|"read stations"| node_firebase
node_detect_routes -->|"trigger station alert"| node_alert_service
node_alert_service -->|"save alert state"| node_firebase
node_alert_service -.->|"send WhatsApp"| node_twilio
node_alert_service -.->|"send email"| node_email
node_detect_routes -->|"emit incident event"| node_realtime
node_incident_routes -->|"invoke"| node_incident_controller
node_incident_controller -->|"save incident"| node_firebase
node_incident_controller -->|"upload evidence"| node_cloudinary
node_incident_controller -->|"trigger station alert"| node_alert_service
node_incident_controller -->|"find nearest station"| node_station_controller
node_alert_controller -->|"read and update alerts"| node_firebase
node_functions -->|"escalate incident"| node_firebase

click node_web_dashboards "https://github.com/shubhamg2004/crimedetectionsystem/tree/main/frontend/src/app/dashboard"
click node_web_field "https://github.com/shubhamg2004/crimedetectionsystem/tree/main/frontend/src/app/field-operator"
click node_web_analytics "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/frontend/src/app/analytics/page.js"
click node_web_incidents "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/frontend/src/app/dashboard/operator/incidents/page.js"
click node_web_detection "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/frontend/src/app/detect-image/page.js"
click node_api_app "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/app.js"
click node_camera_routes "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/routes/camera.routes.js"
click node_admin_routes "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/routes/admin.routes.js"
click node_detect_routes "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/routes/detect.routes.js"
click node_incident_routes "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/routes/incident.routes.js"
click node_analytics_routes "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/routes/analytics.routes.js"
click node_message_routes "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/routes/messages.routes.js"
click node_ai_server "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/ai-server/detector.py"
click node_image_detector "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/ai-server/image_detector.py"
click node_pose_detector "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/ai-server/pose_detector.py"
click node_reasoning "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/ai-server/reasoning_layer.py"
click node_incident_controller "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/controllers/incident.controller.js"
click node_station_controller "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/controllers/policeStation.controller.js"
click node_alert_service "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/services/alert.service.js"
click node_alert_controller "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/controllers/alert.controller.js"
click node_firebase "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/config/firebase.js"
click node_cloudinary "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/config/cloudinary.js"
click node_realtime "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/server.js"
click node_functions "https://github.com/shubhamg2004/crimedetectionsystem/blob/main/functions/index.js"

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_web_dashboards,node_web_field,node_web_analytics,node_web_incidents,node_web_detection toneBlue
class node_api_app,node_camera_routes,node_admin_routes,node_detect_routes,node_incident_routes,node_analytics_routes,node_message_routes toneAmber
class node_ai_server,node_image_detector,node_pose_detector,node_reasoning toneMint
class node_incident_controller,node_station_controller,node_alert_service,node_alert_controller toneRose
class node_firebase,node_cloudinary,node_realtime,node_functions,node_operators,node_fieldops,node_admin,node_camera_device,node_twilio,node_email toneIndigo
```

## Components

### Web application

- [Role dashboards](https://github.com/shubhamg2004/crimedetectionsystem/tree/main/frontend/src/app/dashboard): `frontend/src/app/dashboard`
- [Camera setup](https://github.com/shubhamg2004/crimedetectionsystem/tree/main/frontend/src/app/field-operator): `frontend/src/app/field-operator`
- [Analytics view](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/frontend/src/app/analytics/page.js): `frontend/src/app/analytics/page.js`
- [Incident views](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/frontend/src/app/dashboard/operator/incidents/page.js): `frontend/src/app/dashboard/operator/incidents/page.js`
- [Image detection](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/frontend/src/app/detect-image/page.js): `frontend/src/app/detect-image/page.js`

### Backend API

- [API application](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/app.js): `backend/src/app.js`
- [Camera management](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/routes/camera.routes.js): `backend/src/routes/camera.routes.js`
- [Role administration](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/routes/admin.routes.js): `backend/src/routes/admin.routes.js`
- [Detection intake](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/routes/detect.routes.js): `backend/src/routes/detect.routes.js`
- [Incident endpoints](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/routes/incident.routes.js): `backend/src/routes/incident.routes.js`
- [Analytics endpoints](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/routes/analytics.routes.js): `backend/src/routes/analytics.routes.js`
- [Support messaging](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/routes/messages.routes.js): `backend/src/routes/messages.routes.js`

### AI detection

- [AI service](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/ai-server/detector.py): `ai-server/detector.py`
- [Image analysis](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/ai-server/image_detector.py): `ai-server/image_detector.py`
- [Pose analysis](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/ai-server/pose_detector.py): `ai-server/pose_detector.py`
- [Detection reasoning](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/ai-server/reasoning_layer.py): `ai-server/reasoning_layer.py`

### Incident operations

- [Incident creation](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/controllers/incident.controller.js): `backend/src/controllers/incident.controller.js`
- [Station lookup](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/controllers/policeStation.controller.js): `backend/src/controllers/policeStation.controller.js`
- [Alert dispatch](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/services/alert.service.js): `backend/src/services/alert.service.js`
- [Alert management](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/controllers/alert.controller.js): `backend/src/controllers/alert.controller.js`

### Data and integrations

- [Firebase services](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/config/firebase.js): `backend/src/config/firebase.js`
- [Evidence storage](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/config/cloudinary.js): `backend/src/config/cloudinary.js`
- [Live event server](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/backend/src/server.js): `backend/src/server.js`
- [Incident escalation](https://github.com/shubhamg2004/crimedetectionsystem/blob/main/functions/index.js): `functions/index.js`

### Other components

- **Operators**
- **Field operators**
- **Administrators**
- **Camera device**
- **Twilio messaging**
- **Email delivery**

## Connections

- Operators → Role dashboards: use
- Field operators → Camera setup: manage cameras
- Administrators → Role dashboards: administer
- Operators → Image detection: submit image
- Role dashboards → API application: request data
- Camera setup → API application: manage cameras
- Image detection → API application: submit detection
- Incident views → API application: request incidents
- Analytics view → API application: request analytics
- API application → Camera management: dispatch
- API application → Role administration: dispatch
- API application → Detection intake: dispatch
- API application → Incident endpoints: dispatch
- API application → Analytics endpoints: dispatch
- API application → Support messaging: dispatch
- Camera management → Firebase services: read and write
- Role administration → Firebase services: manage identities
- Support messaging → Firebase services: read and write messages
- Analytics endpoints → Firebase services: query data
- Detection intake → Firebase services: validate camera; store incident
- Camera device → Detection intake: send image
- Detection intake → AI service: forward image
- AI service → Image analysis: analyze image
- AI service → Pose analysis: analyze pose
- AI service → Detection reasoning: interpret detections
- Detection intake → Evidence storage: upload evidence
- Detection intake → Station lookup: find nearest station
- Station lookup → Firebase services: read stations
- Detection intake → Alert dispatch: trigger station alert
- Alert dispatch → Firebase services: save alert state
- Alert dispatch → Twilio messaging: send WhatsApp
- Alert dispatch → Email delivery: send email
- Detection intake → Live event server: emit incident event
- Incident endpoints → Incident creation: invoke
- Incident creation → Firebase services: save incident
- Incident creation → Evidence storage: upload evidence
- Incident creation → Alert dispatch: trigger station alert
- Incident creation → Station lookup: find nearest station
- Alert management → Firebase services: read and update alerts
- Incident escalation → Firebase services: escalate incident
