# mohammedasrarabdullah/roadsafe architecture

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

- Interactive diagram: https://gitdiagram.com/mohammedasrarabdullah/roadsafe
- Repository: https://github.com/mohammedasrarabdullah/roadsafe

## Overview

RoadSafe AI serves browser-based accident analytics, district comparison, risk rankings, and officer investigations through an Express API backed by MySQL. Its optional historical scoring job reads MySQL accidents and calls the deployed Vercel prediction API; the README explicitly rules out local inference. The graph preserves the documented feature areas, but several browser-to-API and unsampled analytics connections cannot be verified from the excerpts, so those links are omitted or marked unverified.

Main entry points: [`public/js/api.js`](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/public/js/api.js) (Browser API client), [`backend/utils/sql.js`](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/utils/sql.js) (Query and selection layer), [`backend/controllers`](https://github.com/mohammedasrarabdullah/roadsafe/tree/main/backend/controllers) (API controllers), [`backend/app.js`](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/app.js) (Express application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Browser experience"]
  node_webui["Web pages"]
  node_api_client["Browser API client<br/>[api.js]"]
  node_eda_ui["Dashboard and comparison<br/>[eda.js]"]
  node_hotspot_ui["Hotspot explorer<br/>[hotspots.js]"]
  node_ranking_ui["Risk ranking<br/>[ranking.js]"]
  node_investigation_ui["Officer investigations<br/>[investigation.js]"]
  node_report_ui["Report export<br/>[report_pdf.js]"]
end

subgraph group_api["API and investigations"]
  node_server["Express application<br/>[app.js]"]
  node_routes["API route modules"]
  node_role["Demo role context"]
  node_controllers["API controllers"]
  node_investigation["Investigation workflow"]
  node_recommendations["Evidence suggestions"]
  node_reports["Report assembly<br/>[report.service.js]"]
end

subgraph group_analytics["Risk analytics"]
  node_analytics_service["Analytics service"]
  node_dashboard["Dashboard and comparison data"]
  node_hotspots["Hotspot analysis"]
  node_intervention["Intervention analysis"]
  node_ranking["Location risk ranking<br/>[ranking.service.js]"]
  node_insights["Insight calculations<br/>[insights.js]"]
  node_sql["Query and selection layer<br/>[sql.js]"]
end

subgraph group_scoring["Historical scoring"]
  node_score_job["Scoring and import job<br/>[score.py]"]
  node_db_loader["Accident row loader<br/>[db_loader.py]"]
  node_prediction["Prediction client<br/>[vercel_client.py]"]
end

node_user(("Road safety user"))
node_mysql[("MySQL database")]
node_vercel["Deployed Vercel model API"]

node_user -.->|"uses"| node_webui
node_webui -->|"served by"| node_server
node_server -->|"mounts"| node_routes
node_server -->|"attaches user"| node_role
node_routes -->|"dispatches"| node_controllers
node_routes -->|"guards requests"| node_role
node_controllers -->|"manages cases"| node_investigation
node_controllers -->|"requests suggestions"| node_recommendations
node_controllers -->|"builds submissions"| node_reports
node_investigation -->|"validates locations"| node_ranking
node_recommendations -->|"checks edit access"| node_investigation
node_dashboard -->|"calculates summaries"| node_insights
node_ranking -->|"formats timing"| node_insights
node_dashboard -->|"queries data"| node_sql
node_ranking -->|"queries data"| node_sql
node_investigation -->|"reads and writes"| node_sql
node_recommendations -->|"queries and stores"| node_sql
node_sql -->|"executes queries"| node_mysql
node_score_job -->|"loads rows"| node_db_loader
node_score_job -->|"requests scores"| node_prediction
node_prediction -->|"calls batch API"| node_vercel
node_score_job -.->|"rebuilds risk summaries"| node_mysql
node_api_client -.->|"sends API requests"| node_server
node_eda_ui -.->|"requests analytics"| node_api_client
node_hotspot_ui -.->|"requests hotspots"| node_api_client
node_ranking_ui -.->|"requests rankings"| node_api_client
node_investigation_ui -.->|"manages investigations"| node_api_client
node_report_ui -.->|"requests reports"| node_api_client

click node_webui "https://github.com/mohammedasrarabdullah/roadsafe/tree/main/public"
click node_api_client "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/public/js/api.js"
click node_eda_ui "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/public/js/dashboard/eda.js"
click node_hotspot_ui "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/public/js/hotspots/hotspots.js"
click node_ranking_ui "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/public/js/ranking/ranking.js"
click node_investigation_ui "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/public/js/investigation/investigation.js"
click node_report_ui "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/public/js/reports/report_pdf.js"
click node_server "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/app.js"
click node_routes "https://github.com/mohammedasrarabdullah/roadsafe/tree/main/backend/routes"
click node_role "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/middleware/activeRole.middleware.js"
click node_controllers "https://github.com/mohammedasrarabdullah/roadsafe/tree/main/backend/controllers"
click node_investigation "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/services/investigation.service.js"
click node_recommendations "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/services/recommendation.service.js"
click node_reports "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/services/report.service.js"
click node_analytics_service "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/services/analytics.service.js"
click node_dashboard "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/services/dashboard.service.js"
click node_hotspots "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/services/hotspots.service.js"
click node_intervention "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/services/intervention.service.js"
click node_ranking "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/services/ranking.service.js"
click node_insights "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/utils/insights.js"
click node_sql "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/utils/sql.js"
click node_score_job "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/ml-service/score.py"
click node_db_loader "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/ml-service/db_loader.py"
click node_prediction "https://github.com/mohammedasrarabdullah/roadsafe/blob/main/ml-service/vercel_client.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_webui,node_api_client,node_eda_ui,node_hotspot_ui,node_ranking_ui,node_investigation_ui,node_report_ui,node_user toneBlue
class node_server,node_routes,node_role,node_controllers,node_investigation,node_recommendations,node_reports,node_mysql toneAmber
class node_analytics_service,node_dashboard,node_hotspots,node_intervention,node_ranking,node_insights,node_sql,node_vercel toneMint
class node_score_job,node_db_loader,node_prediction toneRose
```

## Components

### Browser experience

- [Web pages](https://github.com/mohammedasrarabdullah/roadsafe/tree/main/public): `public`
- [Browser API client](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/public/js/api.js): `public/js/api.js`
- [Dashboard and comparison](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/public/js/dashboard/eda.js): `public/js/dashboard/eda.js`
- [Hotspot explorer](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/public/js/hotspots/hotspots.js): `public/js/hotspots/hotspots.js`
- [Risk ranking](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/public/js/ranking/ranking.js): `public/js/ranking/ranking.js`
- [Officer investigations](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/public/js/investigation/investigation.js): `public/js/investigation/investigation.js`
- [Report export](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/public/js/reports/report_pdf.js): `public/js/reports/report_pdf.js`

### API and investigations

- [Express application](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/app.js): `backend/app.js`
- [API route modules](https://github.com/mohammedasrarabdullah/roadsafe/tree/main/backend/routes): `backend/routes`
- [Demo role context](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/middleware/activeRole.middleware.js): `backend/middleware/activeRole.middleware.js`
- [API controllers](https://github.com/mohammedasrarabdullah/roadsafe/tree/main/backend/controllers): `backend/controllers`
- [Investigation workflow](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/services/investigation.service.js): `backend/services/investigation.service.js`
- [Evidence suggestions](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/services/recommendation.service.js): `backend/services/recommendation.service.js`
- [Report assembly](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/services/report.service.js): `backend/services/report.service.js`

### Risk analytics

- [Analytics service](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/services/analytics.service.js): `backend/services/analytics.service.js`
- [Dashboard and comparison data](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/services/dashboard.service.js): `backend/services/dashboard.service.js`
- [Hotspot analysis](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/services/hotspots.service.js): `backend/services/hotspots.service.js`
- [Intervention analysis](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/services/intervention.service.js): `backend/services/intervention.service.js`
- [Location risk ranking](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/services/ranking.service.js): `backend/services/ranking.service.js`
- [Insight calculations](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/utils/insights.js): `backend/utils/insights.js`
- [Query and selection layer](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/backend/utils/sql.js): `backend/utils/sql.js`

### Historical scoring

- [Scoring and import job](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/ml-service/score.py): `ml-service/score.py`
- [Accident row loader](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/ml-service/db_loader.py): `ml-service/db_loader.py`
- [Prediction client](https://github.com/mohammedasrarabdullah/roadsafe/blob/main/ml-service/vercel_client.py): `ml-service/vercel_client.py`

### Other components

- **Road safety user**
- **MySQL database**
- **Deployed Vercel model API**

## Connections

- Road safety user → Web pages: uses
- Web pages → Express application: served by (evidence: `backend/app.js`)
- Express application → API route modules: mounts (evidence: `backend/app.js`)
- Express application → Demo role context: attaches user (evidence: `backend/app.js`)
- API route modules → API controllers: dispatches (evidence: `backend/routes/investigations.routes.js`)
- API route modules → Demo role context: guards requests (evidence: `backend/routes/investigations.routes.js`)
- API controllers → Investigation workflow: manages cases (evidence: `backend/controllers/investigations.controller.js`)
- API controllers → Evidence suggestions: requests suggestions (evidence: `backend/controllers/investigations.controller.js`)
- API controllers → Report assembly: builds submissions (evidence: `backend/controllers/investigations.controller.js`)
- Investigation workflow → Location risk ranking: validates locations (evidence: `backend/services/investigation.service.js`)
- Evidence suggestions → Investigation workflow: checks edit access (evidence: `backend/services/recommendation.service.js`)
- Dashboard and comparison data → Insight calculations: calculates summaries (evidence: `backend/services/dashboard.service.js`)
- Location risk ranking → Insight calculations: formats timing (evidence: `backend/services/ranking.service.js`)
- Dashboard and comparison data → Query and selection layer: queries data (evidence: `backend/services/dashboard.service.js`)
- Location risk ranking → Query and selection layer: queries data (evidence: `backend/services/ranking.service.js`)
- Investigation workflow → Query and selection layer: reads and writes (evidence: `backend/services/investigation.service.js`)
- Evidence suggestions → Query and selection layer: queries and stores (evidence: `backend/services/recommendation.service.js`)
- Query and selection layer → MySQL database: executes queries (evidence: `backend/utils/sql.js`)
- Scoring and import job → Accident row loader: loads rows (evidence: `ml-service/score.py`)
- Scoring and import job → Prediction client: requests scores (evidence: `ml-service/score.py`)
- Prediction client → Deployed Vercel model API: calls batch API (evidence: `README.md`)
- Scoring and import job → MySQL database: rebuilds risk summaries (evidence: `README.md`)
- Browser API client → Express application: sends API requests
- Dashboard and comparison → Browser API client: requests analytics
- Hotspot explorer → Browser API client: requests hotspots
- Risk ranking → Browser API client: requests rankings
- Officer investigations → Browser API client: manages investigations
- Report export → Browser API client: requests reports
