# team-qua-n-tum/ner-shield architecture

> Architecture diagram of the GitHub repository team-qua-n-tum/ner-shield, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/team-qua-n-tum/ner-shield
- Repository: https://github.com/team-qua-n-tum/ner-shield

## Overview

#### Purpose and Entry Points
NER-SHIELD is a logistics-accessibility platform for India’s North Eastern Region. It combines road, incident, weather, vehicle, and predicted disruption risk into route recommendations, alerts, and a GIS operations dashboard. Backend HTTP startup is `backend/app/main.py`; API v1 composition is `backend/app/api/v1/api.py`. The browser client starts at `frontend/src/main.jsx` and renders the application from `frontend/src/App.jsx`.

#### API and Application Boundary
FastAPI endpoint modules expose domain-oriented read/write operations for dashboards, roads, routes, risks, incidents, vehicles, districts, and alerts. Request/response contracts are isolated in schema modules, while application services coordinate domain logic rather than placing it in handlers.
Paths: `backend/app/api/v1/endpoints/routes.py`, `backend/app/api/v1/endpoints/risk.py`, `backend/app/schemas/route.py`, `backend/app/services/routing_service.py`.

#### Data Store and Operational Domain
The backend store is the persistence boundary for logistics state and likely connects API/services to configured database infrastructure. The intended production geospatial database is PostgreSQL/PostGIS; repository data folders provide road, incident, district, vehicle, weather, and synthetic-data inputs. Runtime configuration is centralized separately.
Paths: `backend/app/db/store.py`, `backend/app/core/config.py`, `data/roads`, `data/incidents`.

#### Risk and Disruption Intelligence
Risk analysis models road-disruption likelihood and provides explanations for results. A separate disruption training pipeline generates synthetic training data and trains model artifacts; application-level AI service bridges predictive capability to API/domain workflows. This is the boundary between offline ML preparation and online decision support.
Paths: `backend/ai/risk/risk_engine.py`, `backend/ai/risk/model.py`, `backend/ai/risk/explainer.py`, `backend/ai/disruption/train.py`, `backend/app/services/ai_service.py`.

#### Routing, Cost, and ETA Pipeline
Routing constructs a graph, derives cost from factors such as blockage/risk, finds and optimizes candidate paths, then estimates ETA. It supports the core flow: road and disruption state → risk-aware route selection → ETA → logistics recommendations/alerts. Routing is encapsulated independently of FastAPI, enabling service and test use.
Paths: `backend/routing/graph.py`, `backend/routing/cost.py`, `backend/routing/engine.py`, `backend/routing/optimizer.py`, `backend/routing/eta.py`.

#### Frontend Dashboard and Mapping
The Vite React frontend presents operations data through dashboard panels and layered maps: roads, districts, incidents, risks, routes, and vehicles. API client modules form its backend boundary, although bundled JSON/mock data indicates the UI can operate against local demonstration data. Leaflet/OpenStreetMap are intended map infrastructure; an OSRM utility indicates external routing integration potential.
Paths: `frontend/src/components/dashboard/OperationsMap.jsx`, `frontend/src/components/map/NERMap.jsx`, `frontend/src/components/map/RiskLayer.jsx`, `frontend/src/lib/api/client.js`, `frontend/src/utils/osrm.js`.

#### Deployment and External Dependencies
Docker artifacts support containerized backend and compose-based local deployment. Material external systems are PostgreSQL/PostGIS for geospatial persistence, OpenStreetMap/Leaflet for map visualization, and potentially OSRM for route geometry or routing. Environment-specific values are supplied outside source through `.env`.
Paths: `backend/Dockerfile`, `backend/docker-compose.yml`, `docker-compose.yml`, `.env.example`.

Main entry points: [`backend/app/api/v1/endpoints/routes.py`](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/api/v1/endpoints/routes.py) (Route & risk endpoints), [`backend/ai/risk/risk_engine.py`](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/ai/risk/risk_engine.py) (Risk engine), [`backend/app/services/routing_service.py`](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/services/routing_service.py) (Routing service), [`backend/app/api/v1/api.py`](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/api/v1/api.py) (API v1 router)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_backend["Backend API"]
  node_api_startup["FastAPI startup<br/>application entry<br/>[main.py]"]
  node_api_v1["API v1 router<br/>API composition<br/>[api.py]"]
  node_domain_endpoints["Route &amp; risk endpoints<br/>HTTP handlers<br/>[routes.py]"]
  node_route_schemas["Route contracts<br/>request/response schemas<br/>[route.py]"]
  node_routing_service["Routing service<br/>application service<br/>[routing_service.py]"]
  node_ai_service["AI service<br/>application service<br/>[ai_service.py]"]
  node_store[("Logistics state store<br/>persistence boundary<br/>[store.py]")]
  node_config["Runtime configuration<br/>[config.py]"]
end

subgraph group_routing["Routing &amp; Intelligence"]
  node_risk_engine["Risk engine<br/>online risk analysis<br/>[risk_engine.py]"]
  node_risk_model["Risk model<br/>predictive model<br/>[model.py]"]
  node_risk_explainer["Risk explanations<br/>model explanation<br/>[explainer.py]"]
  node_training_pipeline["Disruption training<br/>offline ML pipeline<br/>[train.py]"]
  node_route_graph["Road graph<br/>routing graph<br/>[graph.py]"]
  node_route_cost["Risk-aware cost<br/>cost calculation<br/>[cost.py]"]
  node_route_engine["Route engine<br/>path finding<br/>[engine.py]"]
  node_route_optimizer["Route optimizer<br/>candidate optimization<br/>[optimizer.py]"]
  node_eta["ETA estimator<br/>arrival estimation<br/>[eta.py]"]
end

subgraph group_frontend["Operations Client"]
  node_web_app["React application<br/>browser entry<br/>[main.jsx]"]
  node_operations_map["Operations map<br/>GIS dashboard<br/>[OperationsMap.jsx]"]
  node_api_client["API client<br/>frontend API boundary<br/>[client.js]"]
end

subgraph group_external["Infrastructure"]
  node_postgis[("PostgreSQL/PostGIS<br/>geospatial database")]
  node_map_stack["OpenStreetMap / Leaflet<br/>map infrastructure"]
end

node_api_startup -->|"mounts"| node_api_v1
node_api_v1 -->|"routes requests"| node_domain_endpoints
node_domain_endpoints -->|"uses contracts"| node_route_schemas
node_domain_endpoints -->|"requests routes"| node_routing_service
node_domain_endpoints -->|"requests risk"| node_ai_service
node_routing_service -->|"reads road state"| node_store
node_routing_service -->|"selects routes"| node_route_engine
node_ai_service -->|"evaluates risk"| node_risk_engine
node_risk_engine -->|"uses"| node_risk_model
node_risk_engine -->|"explains"| node_risk_explainer
node_training_pipeline -.->|"trains artifacts"| node_risk_model
node_route_graph -->|"supplies network"| node_route_cost
node_route_cost -->|"weights paths"| node_route_engine
node_risk_engine -->|"provides disruption risk"| node_route_cost
node_route_engine -->|"produces candidates"| node_route_optimizer
node_route_optimizer -->|"selected route"| node_eta
node_web_app -->|"renders"| node_operations_map
node_web_app -->|"uses"| node_api_client
node_api_client -->|"HTTP requests"| node_api_v1
node_operations_map -->|"renders with"| node_map_stack
node_store -.->|"persists to"| node_postgis
node_config -.->|"configures"| node_store

click node_api_startup "https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/main.py"
click node_api_v1 "https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/api/v1/api.py"
click node_domain_endpoints "https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/api/v1/endpoints/routes.py"
click node_route_schemas "https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/schemas/route.py"
click node_routing_service "https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/services/routing_service.py"
click node_ai_service "https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/services/ai_service.py"
click node_store "https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/db/store.py"
click node_config "https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/core/config.py"
click node_risk_engine "https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/ai/risk/risk_engine.py"
click node_risk_model "https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/ai/risk/model.py"
click node_risk_explainer "https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/ai/risk/explainer.py"
click node_training_pipeline "https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/ai/disruption/train.py"
click node_route_graph "https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/routing/graph.py"
click node_route_cost "https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/routing/cost.py"
click node_route_engine "https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/routing/engine.py"
click node_route_optimizer "https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/routing/optimizer.py"
click node_eta "https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/routing/eta.py"
click node_web_app "https://github.com/team-qua-n-tum/ner-shield/blob/main/frontend/src/main.jsx"
click node_operations_map "https://github.com/team-qua-n-tum/ner-shield/blob/main/frontend/src/components/dashboard/OperationsMap.jsx"
click node_api_client "https://github.com/team-qua-n-tum/ner-shield/blob/main/frontend/src/lib/api/client.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_api_startup,node_api_v1,node_domain_endpoints,node_route_schemas,node_routing_service,node_ai_service,node_store,node_config toneBlue
class node_risk_engine,node_risk_model,node_risk_explainer,node_training_pipeline,node_route_graph,node_route_cost,node_route_engine,node_route_optimizer,node_eta toneAmber
class node_web_app,node_operations_map,node_api_client toneMint
class node_postgis,node_map_stack toneRose
```

## Components

### Backend API

- [FastAPI startup](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/main.py): application entry · `backend/app/main.py`
- [API v1 router](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/api/v1/api.py): API composition · `backend/app/api/v1/api.py`
- [Route & risk endpoints](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/api/v1/endpoints/routes.py): HTTP handlers · Representative domain endpoints also cover dashboards, incidents, vehicles, districts, and alerts. · `backend/app/api/v1/endpoints/routes.py`
- [Route contracts](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/schemas/route.py): request/response schemas · `backend/app/schemas/route.py`
- [Routing service](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/services/routing_service.py): application service · Coordinates route decisions outside HTTP handlers. · `backend/app/services/routing_service.py`
- [AI service](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/services/ai_service.py): application service · Bridges online prediction into domain workflows. · `backend/app/services/ai_service.py`
- [Logistics state store](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/db/store.py): persistence boundary · `backend/app/db/store.py`
- [Runtime configuration](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/app/core/config.py): configuration · `backend/app/core/config.py`

### Routing & Intelligence

- [Risk engine](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/ai/risk/risk_engine.py): online risk analysis · `backend/ai/risk/risk_engine.py`
- [Risk model](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/ai/risk/model.py): predictive model · `backend/ai/risk/model.py`
- [Risk explanations](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/ai/risk/explainer.py): model explanation · `backend/ai/risk/explainer.py`
- [Disruption training](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/ai/disruption/train.py): offline ML pipeline · Generates synthetic training data and model artifacts. · `backend/ai/disruption/train.py`
- [Road graph](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/routing/graph.py): routing graph · `backend/routing/graph.py`
- [Risk-aware cost](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/routing/cost.py): cost calculation · `backend/routing/cost.py`
- [Route engine](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/routing/engine.py): path finding · `backend/routing/engine.py`
- [Route optimizer](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/routing/optimizer.py): candidate optimization · `backend/routing/optimizer.py`
- [ETA estimator](https://github.com/team-qua-n-tum/ner-shield/blob/main/backend/routing/eta.py): arrival estimation · `backend/routing/eta.py`

### Operations Client

- [React application](https://github.com/team-qua-n-tum/ner-shield/blob/main/frontend/src/main.jsx): browser entry · `frontend/src/main.jsx`
- [Operations map](https://github.com/team-qua-n-tum/ner-shield/blob/main/frontend/src/components/dashboard/OperationsMap.jsx): GIS dashboard · Displays layered roads, districts, incidents, risks, routes, and vehicles. · `frontend/src/components/dashboard/OperationsMap.jsx`
- [API client](https://github.com/team-qua-n-tum/ner-shield/blob/main/frontend/src/lib/api/client.js): frontend API boundary · `frontend/src/lib/api/client.js`

### Infrastructure

- **PostgreSQL/PostGIS**: geospatial database
- **OpenStreetMap / Leaflet**: map infrastructure

## Connections

- FastAPI startup → API v1 router: mounts
- API v1 router → Route & risk endpoints: routes requests
- Route & risk endpoints → Route contracts: uses contracts
- Route & risk endpoints → Routing service: requests routes
- Route & risk endpoints → AI service: requests risk
- Routing service → Logistics state store: reads road state
- Routing service → Route engine: selects routes
- AI service → Risk engine: evaluates risk
- Risk engine → Risk model: uses
- Risk engine → Risk explanations: explains
- Disruption training → Risk model: trains artifacts
- Road graph → Risk-aware cost: supplies network
- Risk-aware cost → Route engine: weights paths
- Risk engine → Risk-aware cost: provides disruption risk
- Route engine → Route optimizer: produces candidates
- Route optimizer → ETA estimator: selected route
- React application → Operations map: renders
- React application → API client: uses
- API client → API v1 router: HTTP requests
- Operations map → OpenStreetMap / Leaflet: renders with
- Logistics state store → PostgreSQL/PostGIS: persists to
- Runtime configuration → Logistics state store: configures
