# liso-27/nivaranai architecture

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

- Interactive diagram: https://gitdiagram.com/liso-27/nivaranai
- Repository: https://github.com/liso-27/nivaranai

## Overview

NivaranAI is a ward-level, multi-hazard warning and citizen-government coordination platform. Its principal cycle fuses weather feeds and corroborating citizen reports into auditable, confidence-scored ward risks; a scheduled runner persists changes and dispatches deterministic alerts. Citizens can view hazards, report conditions, find safe places, and receive notifications, while officials triage reports and manage camps and administrators oversee the platform. The React client reaches Flask services through its API layer, with Appwrite-backed state and Firebase/Twilio notification integrations. Backend connections are based chiefly on README architecture; unsampled modules are represented by documented responsibilities, not inspected internals.

Main entry points: [`ReGenX/src/App.tsx`](https://github.com/liso-27/nivaranai/blob/main/ReGenX/src/App.tsx) (Role dashboards), [`api.py`](https://github.com/liso-27/nivaranai/blob/main/api.py) (Flask API), [`risk_engine.py`](https://github.com/liso-27/nivaranai/blob/main/risk_engine.py) (Ward risk scoring), [`ReGenX/src/context/DisasterDataContext.tsx`](https://github.com/liso-27/nivaranai/blob/main/ReGenX/src/context/DisasterDataContext.tsx) (Disaster data state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["User experience"]
  node_app["Role dashboards<br/>[App.tsx]"]
  node_citizen_ui["Citizen tools"]
  node_official_ui["Official tools"]
  node_admin_ui["Admin dashboard<br/>[AdminDashboard.tsx]"]
  node_map_ui["Disaster map<br/>[DisasterMap.tsx]"]
  node_client_state["Disaster data state"]
  node_auth["Authentication state<br/>[AuthContext.tsx]"]
  node_notifications_ui["Notification state"]
  node_api_client["REST client<br/>[api.ts]"]
end

subgraph group_backend["API and coordination"]
  node_flask_api["Flask API<br/>[api.py]"]
  node_auth_service["Role access and audit<br/>[auth_service.py]"]
  node_crowd["Crowd reports<br/>[crowd_updates.py]"]
end

subgraph group_risk["Risk intelligence"]
  node_risk_engine["Ward risk scoring<br/>[risk_engine.py]"]
  node_runner["Scheduled risk cycle"]
  node_map_zones["Hazard map zones<br/>[map_zones.py]"]
  node_weather["Weather data providers"]
end

subgraph group_operations["Response operations"]
  node_safe_places["Safe-place services"]
  node_news["News service<br/>[news_service.py]"]
  node_notification_service["Alert dispatch"]
  node_sms["SMS controls<br/>[sms_service.py]"]
end

subgraph group_platform["External platform"]
  node_appwrite[("Appwrite")]
  node_push["Firebase messaging"]
  node_twilio["Twilio SMS"]
  node_gemini["Gemini explanations"]
end

node_citizens(("Citizens"))
node_officials(("Government officials"))
node_admins(("Administrators"))

node_citizens -->|"use"| node_app
node_officials -->|"use"| node_app
node_admins -->|"use"| node_app
node_app -->|"renders"| node_citizen_ui
node_app -->|"renders"| node_official_ui
node_app -.->|"renders"| node_admin_ui
node_app -->|"renders"| node_map_ui
node_app -->|"provides"| node_client_state
node_app -->|"uses"| node_auth
node_citizen_ui -->|"reads and updates"| node_client_state
node_official_ui -->|"reads and updates"| node_client_state
node_map_ui -->|"reads layers"| node_client_state
node_client_state -->|"requests data"| node_api_client
node_auth -->|"authenticates through"| node_api_client
node_api_client -->|"REST requests"| node_flask_api
node_flask_api -->|"delegates auth"| node_auth_service
node_flask_api -->|"routes reports"| node_crowd
node_flask_api -->|"routes locations"| node_safe_places
node_flask_api -->|"routes map zones"| node_map_zones
node_flask_api -->|"routes news"| node_news
node_crowd -->|"supplies corroboration"| node_risk_engine
node_risk_engine -->|"fetches signals"| node_weather
node_runner -->|"runs scoring"| node_risk_engine
node_runner -->|"dispatches changes"| node_notification_service
node_risk_engine -->|"writes risk rows"| node_appwrite
node_runner -->|"persists changes"| node_appwrite
node_map_zones -->|"transforms risk"| node_risk_engine
node_map_zones -->|"reads risk zones"| node_appwrite
node_safe_places -->|"stores locations"| node_appwrite
node_notification_service -->|"sends SMS through"| node_sms
node_notification_service -->|"sends push"| node_push
node_sms -->|"sends messages"| node_twilio
node_notifications_ui -->|"syncs tokens"| node_api_client
node_notifications_ui -->|"registers token"| node_push
node_risk_engine -.->|"explains scores"| node_gemini

click node_app "https://github.com/liso-27/nivaranai/blob/main/ReGenX/src/App.tsx"
click node_citizen_ui "https://github.com/liso-27/nivaranai/tree/main/ReGenX/src/components/citizen"
click node_official_ui "https://github.com/liso-27/nivaranai/tree/main/ReGenX/src/components/government"
click node_admin_ui "https://github.com/liso-27/nivaranai/blob/main/ReGenX/src/components/admin/AdminDashboard.tsx"
click node_map_ui "https://github.com/liso-27/nivaranai/blob/main/ReGenX/src/components/map/DisasterMap.tsx"
click node_client_state "https://github.com/liso-27/nivaranai/blob/main/ReGenX/src/context/DisasterDataContext.tsx"
click node_auth "https://github.com/liso-27/nivaranai/blob/main/ReGenX/src/context/AuthContext.tsx"
click node_notifications_ui "https://github.com/liso-27/nivaranai/blob/main/ReGenX/src/context/NotificationContext.tsx"
click node_api_client "https://github.com/liso-27/nivaranai/blob/main/ReGenX/src/services/api.ts"
click node_flask_api "https://github.com/liso-27/nivaranai/blob/main/api.py"
click node_auth_service "https://github.com/liso-27/nivaranai/blob/main/auth_service.py"
click node_crowd "https://github.com/liso-27/nivaranai/blob/main/crowd_updates.py"
click node_risk_engine "https://github.com/liso-27/nivaranai/blob/main/risk_engine.py"
click node_runner "https://github.com/liso-27/nivaranai/blob/main/scheduled_runner.py"
click node_map_zones "https://github.com/liso-27/nivaranai/blob/main/map_zones.py"
click node_safe_places "https://github.com/liso-27/nivaranai/blob/main/emergency_locations.py"
click node_news "https://github.com/liso-27/nivaranai/blob/main/news_service.py"
click node_notification_service "https://github.com/liso-27/nivaranai/blob/main/notification_service.py"
click node_sms "https://github.com/liso-27/nivaranai/blob/main/sms_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_citizen_ui,node_official_ui,node_admin_ui,node_map_ui,node_client_state,node_auth,node_notifications_ui,node_api_client toneBlue
class node_flask_api,node_auth_service,node_crowd toneAmber
class node_risk_engine,node_runner,node_map_zones,node_weather toneMint
class node_safe_places,node_news,node_notification_service,node_sms toneRose
class node_appwrite,node_push,node_twilio,node_gemini,node_citizens,node_officials,node_admins toneIndigo
```

## Components

### User experience

- [Role dashboards](https://github.com/liso-27/nivaranai/blob/main/ReGenX/src/App.tsx): `ReGenX/src/App.tsx`
- [Citizen tools](https://github.com/liso-27/nivaranai/tree/main/ReGenX/src/components/citizen): `ReGenX/src/components/citizen`
- [Official tools](https://github.com/liso-27/nivaranai/tree/main/ReGenX/src/components/government): `ReGenX/src/components/government`
- [Admin dashboard](https://github.com/liso-27/nivaranai/blob/main/ReGenX/src/components/admin/AdminDashboard.tsx): `ReGenX/src/components/admin/AdminDashboard.tsx`
- [Disaster map](https://github.com/liso-27/nivaranai/blob/main/ReGenX/src/components/map/DisasterMap.tsx): `ReGenX/src/components/map/DisasterMap.tsx`
- [Disaster data state](https://github.com/liso-27/nivaranai/blob/main/ReGenX/src/context/DisasterDataContext.tsx): `ReGenX/src/context/DisasterDataContext.tsx`
- [Authentication state](https://github.com/liso-27/nivaranai/blob/main/ReGenX/src/context/AuthContext.tsx): `ReGenX/src/context/AuthContext.tsx`
- [Notification state](https://github.com/liso-27/nivaranai/blob/main/ReGenX/src/context/NotificationContext.tsx): `ReGenX/src/context/NotificationContext.tsx`
- [REST client](https://github.com/liso-27/nivaranai/blob/main/ReGenX/src/services/api.ts): `ReGenX/src/services/api.ts`

### API and coordination

- [Flask API](https://github.com/liso-27/nivaranai/blob/main/api.py): `api.py`
- [Role access and audit](https://github.com/liso-27/nivaranai/blob/main/auth_service.py): `auth_service.py`
- [Crowd reports](https://github.com/liso-27/nivaranai/blob/main/crowd_updates.py): `crowd_updates.py`

### Risk intelligence

- [Ward risk scoring](https://github.com/liso-27/nivaranai/blob/main/risk_engine.py): `risk_engine.py`
- [Scheduled risk cycle](https://github.com/liso-27/nivaranai/blob/main/scheduled_runner.py): `scheduled_runner.py`
- [Hazard map zones](https://github.com/liso-27/nivaranai/blob/main/map_zones.py): `map_zones.py`
- **Weather data providers**

### Response operations

- [Safe-place services](https://github.com/liso-27/nivaranai/blob/main/emergency_locations.py): `emergency_locations.py`
- [News service](https://github.com/liso-27/nivaranai/blob/main/news_service.py): `news_service.py`
- [Alert dispatch](https://github.com/liso-27/nivaranai/blob/main/notification_service.py): `notification_service.py`
- [SMS controls](https://github.com/liso-27/nivaranai/blob/main/sms_service.py): `sms_service.py`

### External platform

- **Appwrite**
- **Firebase messaging**
- **Twilio SMS**
- **Gemini explanations**

### Other components

- **Citizens**
- **Government officials**
- **Administrators**

## Connections

- Citizens → Role dashboards: use (evidence: `ReGenX/src/App.tsx`)
- Government officials → Role dashboards: use (evidence: `ReGenX/src/App.tsx`)
- Administrators → Role dashboards: use (evidence: `ReGenX/src/App.tsx`)
- Role dashboards → Citizen tools: renders (evidence: `ReGenX/src/App.tsx`)
- Role dashboards → Official tools: renders (evidence: `ReGenX/src/App.tsx`)
- Role dashboards → Admin dashboard: renders (evidence: `README.md`)
- Role dashboards → Disaster map: renders (evidence: `ReGenX/src/App.tsx`)
- Role dashboards → Disaster data state: provides (evidence: `ReGenX/src/App.tsx`)
- Role dashboards → Authentication state: uses (evidence: `ReGenX/src/App.tsx`)
- Citizen tools → Disaster data state: reads and updates (evidence: `ReGenX/src/components/citizen/CitizenDashboard.tsx`)
- Official tools → Disaster data state: reads and updates (evidence: `ReGenX/src/components/government/CampManagerView.tsx`)
- Disaster map → Disaster data state: reads layers (evidence: `ReGenX/src/components/map/DisasterMap.tsx`)
- Disaster data state → REST client: requests data (evidence: `ReGenX/src/context/DisasterDataContext.tsx`)
- Authentication state → REST client: authenticates through (evidence: `ReGenX/src/context/AuthContext.tsx`)
- REST client → Flask API: REST requests (evidence: `README.md`)
- Flask API → Role access and audit: delegates auth (evidence: `README.md`)
- Flask API → Crowd reports: routes reports (evidence: `README.md`)
- Flask API → Safe-place services: routes locations (evidence: `README.md`)
- Flask API → Hazard map zones: routes map zones (evidence: `README.md`)
- Flask API → News service: routes news (evidence: `README.md`)
- Crowd reports → Ward risk scoring: supplies corroboration (evidence: `crowd_updates.py`)
- Ward risk scoring → Weather data providers: fetches signals (evidence: `README.md`)
- Scheduled risk cycle → Ward risk scoring: runs scoring (evidence: `README.md`)
- Scheduled risk cycle → Alert dispatch: dispatches changes (evidence: `README.md`)
- Ward risk scoring → Appwrite: writes risk rows (evidence: `risk_engine.py`)
- Scheduled risk cycle → Appwrite: persists changes (evidence: `README.md`)
- Hazard map zones → Ward risk scoring: transforms risk (evidence: `map_zones.py`)
- Hazard map zones → Appwrite: reads risk zones (evidence: `map_zones.py`)
- Safe-place services → Appwrite: stores locations (evidence: `emergency_locations.py`)
- Alert dispatch → SMS controls: sends SMS through (evidence: `README.md`)
- Alert dispatch → Firebase messaging: sends push (evidence: `README.md`)
- SMS controls → Twilio SMS: sends messages (evidence: `README.md`)
- Notification state → REST client: syncs tokens (evidence: `ReGenX/src/context/NotificationContext.tsx`)
- Notification state → Firebase messaging: registers token (evidence: `ReGenX/src/context/NotificationContext.tsx`)
- Ward risk scoring → Gemini explanations: explains scores (evidence: `README.md`)
