# sharanmankala/crashintelligence architecture

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

- Interactive diagram: https://gitdiagram.com/sharanmankala/crashintelligence
- Repository: https://github.com/sharanmankala/crashintelligence

## Overview

CrashIntelligence is a React dashboard and FastAPI service for California crash-risk analysis. Users explore ranked hotspots, county forecasts, spatial predictions, trends and explainability; the AI surfaces provide forecast review/correction and evidence-grounded crash queries. The backend reads precomputed artifacts, shapes analysis results, and serves API responses. The graph preserves README-described dashboard capabilities even where routing or implementation details were not sampled; those links are omitted when the excerpts do not establish them.

Main entry points: [`frontend/src/services/api.ts`](https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/services/api.ts) (API client), [`backend/app/main.py`](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/main.py) (FastAPI app), [`backend/app/services/repository.py`](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/services/repository.py) (Artifact repository), [`backend/app/utils/frame.py`](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/utils/frame.py) (Frame utilities)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Dashboard"]
  node_app["App routes<br/>[App.tsx]"]
  node_hotspot_page["Hotspot analysis"]
  node_forecast_page["Forecast analytics"]
  node_spatial_page["Spatial risk maps"]
  node_overview_page["Overview and trends<br/>[OverviewPage.tsx]"]
  node_explain_page["Explainability"]
  node_method_page["Methodology"]
  node_forecast_ai_page["Forecast assistant"]
  node_query_page["Crash query assistant"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_api["API routing"]
  node_backend["FastAPI app<br/>[main.py]"]
  node_hotspot_router["Hotspot routes<br/>[hotspots.py]"]
  node_forecast_router["Forecast routes<br/>[forecasts.py]"]
  node_trend_router["Trend routes<br/>[trends.py]"]
  node_shap_router["SHAP routes<br/>[shap.py]"]
  node_method_router["Methodology routes<br/>[methodology.py]"]
  node_ai_router["AI routes<br/>[ai.py]"]
end

subgraph group_analytics["Crash analytics"]
  node_hotspot_service["Hotspot analysis<br/>[hotspot_service.py]"]
  node_forecast_service["Forecast analysis"]
  node_trend_service["Crash trends<br/>[trend_service.py]"]
  node_shap_service["Feature interpretation<br/>[shap_service.py]"]
  node_benchmark_service["Model benchmark"]
  node_repository[("Artifact repository<br/>[repository.py]")]
  node_frame["Frame utilities<br/>[frame.py]"]
end

subgraph group_assist["AI assistance"]
  node_ai_service["AI orchestration<br/>[ai_service.py]"]
  node_context_service["Assistant context"]
end

node_user(("Dashboard user"))
node_openai["OpenAI API"]
node_weather["OpenWeather"]

node_user -->|"opens dashboard"| node_app
node_app -->|"routes to"| node_hotspot_page
node_app -->|"routes to"| node_forecast_page
node_app -->|"routes to"| node_spatial_page
node_hotspot_page -->|"requests data"| node_api_client
node_forecast_page -->|"requests data"| node_api_client
node_spatial_page -->|"requests data"| node_api_client
node_overview_page -->|"requests data"| node_api_client
node_explain_page -->|"requests data"| node_api_client
node_method_page -->|"requests data"| node_api_client
node_forecast_ai_page -->|"requests correction"| node_api_client
node_query_page -->|"sends query"| node_api_client
node_api_client -->|"calls endpoints"| node_hotspot_router
node_api_client -->|"calls endpoints"| node_forecast_router
node_api_client -->|"calls endpoints"| node_trend_router
node_api_client -->|"calls endpoints"| node_shap_router
node_api_client -->|"calls endpoints"| node_method_router
node_api_client -->|"calls endpoints"| node_ai_router
node_backend -->|"registers routes"| node_hotspot_router
node_backend -->|"registers routes"| node_forecast_router
node_backend -->|"registers routes"| node_trend_router
node_backend -->|"registers routes"| node_shap_router
node_backend -->|"registers routes"| node_method_router
node_backend -->|"registers routes"| node_ai_router
node_hotspot_router -->|"calls service"| node_hotspot_service
node_forecast_router -->|"calls service"| node_forecast_service
node_trend_router -->|"calls service"| node_trend_service
node_shap_router -->|"calls service"| node_shap_service
node_ai_router -->|"calls service"| node_ai_service
node_hotspot_service -->|"reads artifacts"| node_repository
node_forecast_service -->|"reads forecast data"| node_repository
node_trend_service -->|"reads crash data"| node_repository
node_shap_service -->|"reads artifacts"| node_repository
node_benchmark_service -->|"reads benchmarks"| node_repository
node_hotspot_service -->|"cleans records"| node_frame
node_forecast_service -->|"cleans records"| node_frame
node_trend_service -->|"cleans records"| node_frame
node_shap_service -->|"cleans records"| node_frame
node_benchmark_service -->|"cleans records"| node_frame
node_ai_service -->|"resolves baseline"| node_forecast_service
node_ai_service -->|"assembles context"| node_context_service
node_context_service -->|"reads history"| node_repository
node_ai_service -->|"requests reasoning"| node_openai
node_context_service -.->|"optionally enriches"| node_weather

click node_app "https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/App.tsx"
click node_hotspot_page "https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/pages/HotspotAnalysisPage.tsx"
click node_forecast_page "https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/pages/ForecastingAnalyticsPage.tsx"
click node_spatial_page "https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/pages/SpatialRiskMapsPage.tsx"
click node_overview_page "https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/pages/OverviewPage.tsx"
click node_explain_page "https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/pages/ExplainabilityPage.tsx"
click node_method_page "https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/pages/ResearchMethodologyPage.tsx"
click node_forecast_ai_page "https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/pages/AIForecastAssistantPage.tsx"
click node_query_page "https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/pages/AIQueryAssistantPage.tsx"
click node_api_client "https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/services/api.ts"
click node_backend "https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/main.py"
click node_hotspot_router "https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/routers/hotspots.py"
click node_forecast_router "https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/routers/forecasts.py"
click node_trend_router "https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/routers/trends.py"
click node_shap_router "https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/routers/shap.py"
click node_method_router "https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/routers/methodology.py"
click node_ai_router "https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/routers/ai.py"
click node_hotspot_service "https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/services/hotspot_service.py"
click node_forecast_service "https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/services/forecast_service.py"
click node_trend_service "https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/services/trend_service.py"
click node_shap_service "https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/services/shap_service.py"
click node_benchmark_service "https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/services/benchmark_service.py"
click node_repository "https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/services/repository.py"
click node_frame "https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/utils/frame.py"
click node_ai_service "https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/services/ai_service.py"
click node_context_service "https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/services/assistant_context_service.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_hotspot_page,node_forecast_page,node_spatial_page,node_overview_page,node_explain_page,node_method_page,node_forecast_ai_page,node_query_page,node_api_client,node_user toneBlue
class node_backend,node_hotspot_router,node_forecast_router,node_trend_router,node_shap_router,node_method_router,node_ai_router toneAmber
class node_hotspot_service,node_forecast_service,node_trend_service,node_shap_service,node_benchmark_service,node_repository,node_frame,node_openai toneMint
class node_ai_service,node_context_service toneRose
class node_weather toneIndigo
```

## Components

### Dashboard

- [App routes](https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Hotspot analysis](https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/pages/HotspotAnalysisPage.tsx): `frontend/src/pages/HotspotAnalysisPage.tsx`
- [Forecast analytics](https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/pages/ForecastingAnalyticsPage.tsx): `frontend/src/pages/ForecastingAnalyticsPage.tsx`
- [Spatial risk maps](https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/pages/SpatialRiskMapsPage.tsx): `frontend/src/pages/SpatialRiskMapsPage.tsx`
- [Overview and trends](https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/pages/OverviewPage.tsx): `frontend/src/pages/OverviewPage.tsx`
- [Explainability](https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/pages/ExplainabilityPage.tsx): `frontend/src/pages/ExplainabilityPage.tsx`
- [Methodology](https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/pages/ResearchMethodologyPage.tsx): `frontend/src/pages/ResearchMethodologyPage.tsx`
- [Forecast assistant](https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/pages/AIForecastAssistantPage.tsx): `frontend/src/pages/AIForecastAssistantPage.tsx`
- [Crash query assistant](https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/pages/AIQueryAssistantPage.tsx): `frontend/src/pages/AIQueryAssistantPage.tsx`
- [API client](https://github.com/sharanmankala/crashintelligence/blob/main/frontend/src/services/api.ts): `frontend/src/services/api.ts`

### API routing

- [FastAPI app](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/main.py): `backend/app/main.py`
- [Hotspot routes](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/routers/hotspots.py): `backend/app/routers/hotspots.py`
- [Forecast routes](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/routers/forecasts.py): `backend/app/routers/forecasts.py`
- [Trend routes](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/routers/trends.py): `backend/app/routers/trends.py`
- [SHAP routes](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/routers/shap.py): `backend/app/routers/shap.py`
- [Methodology routes](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/routers/methodology.py): `backend/app/routers/methodology.py`
- [AI routes](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/routers/ai.py): `backend/app/routers/ai.py`

### Crash analytics

- [Hotspot analysis](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/services/hotspot_service.py): `backend/app/services/hotspot_service.py`
- [Forecast analysis](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/services/forecast_service.py): `backend/app/services/forecast_service.py`
- [Crash trends](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/services/trend_service.py): `backend/app/services/trend_service.py`
- [Feature interpretation](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/services/shap_service.py): `backend/app/services/shap_service.py`
- [Model benchmark](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/services/benchmark_service.py): `backend/app/services/benchmark_service.py`
- [Artifact repository](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/services/repository.py): `backend/app/services/repository.py`
- [Frame utilities](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/utils/frame.py): `backend/app/utils/frame.py`

### AI assistance

- [AI orchestration](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/services/ai_service.py): `backend/app/services/ai_service.py`
- [Assistant context](https://github.com/sharanmankala/crashintelligence/blob/main/backend/app/services/assistant_context_service.py): `backend/app/services/assistant_context_service.py`

### Other components

- **Dashboard user**
- **OpenAI API**
- **OpenWeather**

## Connections

- Dashboard user → App routes: opens dashboard (evidence: `frontend/src/App.tsx`)
- App routes → Hotspot analysis: routes to (evidence: `frontend/src/App.tsx`)
- App routes → Forecast analytics: routes to (evidence: `frontend/src/App.tsx`)
- App routes → Spatial risk maps: routes to (evidence: `frontend/src/App.tsx`)
- Hotspot analysis → API client: requests data (evidence: `frontend/src/pages/HotspotAnalysisPage.tsx`)
- Forecast analytics → API client: requests data (evidence: `frontend/src/pages/ForecastingAnalyticsPage.tsx`)
- Spatial risk maps → API client: requests data (evidence: `frontend/src/pages/SpatialRiskMapsPage.tsx`)
- Overview and trends → API client: requests data (evidence: `frontend/src/pages/OverviewPage.tsx`)
- Explainability → API client: requests data (evidence: `frontend/src/pages/ExplainabilityPage.tsx`)
- Methodology → API client: requests data (evidence: `frontend/src/pages/ResearchMethodologyPage.tsx`)
- Forecast assistant → API client: requests correction (evidence: `frontend/src/pages/AIForecastAssistantPage.tsx`)
- Crash query assistant → API client: sends query (evidence: `frontend/src/pages/AIQueryAssistantPage.tsx`)
- API client → Hotspot routes: calls endpoints (evidence: `frontend/src/services/api.ts`)
- API client → Forecast routes: calls endpoints (evidence: `frontend/src/services/api.ts`)
- API client → Trend routes: calls endpoints (evidence: `frontend/src/services/api.ts`)
- API client → SHAP routes: calls endpoints (evidence: `frontend/src/services/api.ts`)
- API client → Methodology routes: calls endpoints (evidence: `frontend/src/services/api.ts`)
- API client → AI routes: calls endpoints (evidence: `frontend/src/services/api.ts`)
- FastAPI app → Hotspot routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI app → Forecast routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI app → Trend routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI app → SHAP routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI app → Methodology routes: registers routes (evidence: `backend/app/main.py`)
- FastAPI app → AI routes: registers routes (evidence: `backend/app/main.py`)
- Hotspot routes → Hotspot analysis: calls service (evidence: `backend/app/routers/hotspots.py`)
- Forecast routes → Forecast analysis: calls service (evidence: `backend/app/routers/forecasts.py`)
- Trend routes → Crash trends: calls service (evidence: `backend/app/routers/trends.py`)
- SHAP routes → Feature interpretation: calls service (evidence: `backend/app/routers/shap.py`)
- AI routes → AI orchestration: calls service (evidence: `backend/app/routers/ai.py`)
- Hotspot analysis → Artifact repository: reads artifacts (evidence: `backend/app/services/hotspot_service.py`)
- Forecast analysis → Artifact repository: reads forecast data (evidence: `backend/app/services/forecast_service.py`)
- Crash trends → Artifact repository: reads crash data (evidence: `backend/app/services/trend_service.py`)
- Feature interpretation → Artifact repository: reads artifacts (evidence: `backend/app/services/shap_service.py`)
- Model benchmark → Artifact repository: reads benchmarks (evidence: `backend/app/services/benchmark_service.py`)
- Hotspot analysis → Frame utilities: cleans records (evidence: `backend/app/services/hotspot_service.py`)
- Forecast analysis → Frame utilities: cleans records (evidence: `backend/app/services/forecast_service.py`)
- Crash trends → Frame utilities: cleans records (evidence: `backend/app/services/trend_service.py`)
- Feature interpretation → Frame utilities: cleans records (evidence: `backend/app/services/shap_service.py`)
- Model benchmark → Frame utilities: cleans records (evidence: `backend/app/services/benchmark_service.py`)
- AI orchestration → Forecast analysis: resolves baseline (evidence: `backend/app/services/ai_service.py`)
- AI orchestration → Assistant context: assembles context (evidence: `backend/app/services/ai_service.py`)
- Assistant context → Artifact repository: reads history (evidence: `backend/app/services/assistant_context_service.py`)
- AI orchestration → OpenAI API: requests reasoning (evidence: `backend/app/services/ai_service.py`)
- Assistant context → OpenWeather: optionally enriches (evidence: `backend/app/services/assistant_context_service.py`)
