# shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system architecture

> Architecture diagram of the GitHub repository shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-10). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system
- Repository: https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system

## Overview

FasalRakshak collects geotagged crop-loss claims, stores evidence, correlates images and weather, and presents confidence signals for official review. The primary path is farmer submission (including offline capture and later sync) through the reports API, followed by asynchronous AI assessment and review in the dashboard. The README also documents exports, certificates, and proactive weather monitoring. Edges reflect the supplied excerpts, SOURCE INDEX references, or README; unsampled integrations are not asserted as confirmed calls.

Main entry points: [`backend/app/main.py`](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/main.py) (FastAPI Runtime), [`backend/app/workers/ai_pipeline.py`](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/workers/ai_pipeline.py) (AI Assessment Pipeline), [`backend/app/api/reports.py`](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/api/reports.py) (Claims API), [`frontend/src/lib/api.ts`](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/frontend/src/lib/api.ts) (Frontend API Client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Farmer and Inspector Experience"]
  node_farmer_ui["Farmer PWA<br/>[page.tsx]"]
  node_claim_ui["Claims View<br/>[page.tsx]"]
  node_dashboard["Review Dashboard<br/>[page.tsx]"]
  node_offline_submit["Offline Claim Submit"]
  node_offline_store[("Offline Claim Store<br/>[db.ts]")]
  node_sync["Claim Sync Engine<br/>[syncEngine.ts]"]
  node_api_client["Frontend API Client<br/>[api.ts]"]
end

subgraph group_api["API and Identity"]
  node_app["FastAPI Runtime<br/>[main.py]"]
  node_auth_api["Authentication API<br/>[auth.py]"]
  node_auth_service["Identity Service<br/>[auth_service.py]"]
  node_auth_deps["Auth and Role Guards<br/>[deps.py]"]
end

subgraph group_evidence["Claims and Evidence"]
  node_reports_api["Claims API<br/>[reports.py]"]
  node_storage_service["Evidence Storage<br/>[storage_service.py]"]
  node_object_store[("MinIO Object Store")]
  node_exports["Claim Exports and Certificates"]
end

subgraph group_assessment["Assessment and Weather"]
  node_pipeline["AI Assessment Pipeline<br/>[ai_pipeline.py]"]
  node_cv["Vision and Duplicate Audit<br/>[cv_service.py]"]
  node_weather["Claim Weather Correlation<br/>[weather_service.py]"]
  node_scoring["Confidence Scoring<br/>[scoring_service.py]"]
  node_monitor["Proactive Weather Monitor"]
end

subgraph group_operations["Runtime and Persistence"]
  node_redis["Redis Streams"]
  node_consumer["Stream Consumer<br/>[consumer.py]"]
  node_db[("PostgreSQL and PostGIS<br/>[session.py]")]
end

node_farmer(("Farmer"))
node_official(("Inspector"))

node_farmer -->|"captures loss"| node_farmer_ui
node_farmer_ui -.->|"queues offline"| node_offline_submit
node_offline_submit -->|"stores claim"| node_offline_store
node_sync -->|"reads and updates"| node_offline_store
node_sync -.->|"uploads claim"| node_api_client
node_farmer_ui -.->|"uses API"| node_api_client
node_api_client -.->|"sends requests"| node_app
node_official -->|"reviews cases"| node_dashboard
node_dashboard -.->|"requests review data"| node_api_client
node_app -->|"routes requests"| node_auth_api
node_app -->|"routes requests"| node_reports_api
node_auth_api -->|"uses identity service"| node_auth_service
node_auth_api -->|"checks roles"| node_auth_deps
node_auth_service -->|"reads and writes users"| node_db
node_reports_api -->|"guards claim routes"| node_auth_deps
node_reports_api -->|"persists claim data"| node_db
node_reports_api -->|"requests evidence URLs"| node_storage_service
node_storage_service -->|"creates upload URLs"| node_object_store
node_app -->|"starts worker"| node_consumer
node_consumer -->|"consumes events"| node_redis
node_consumer -->|"runs assessment"| node_pipeline
node_pipeline -->|"fetches images"| node_object_store
node_pipeline -->|"analyzes and checks duplicates"| node_cv
node_pipeline -->|"fetches correlation"| node_weather
node_pipeline -->|"computes confidence"| node_scoring
node_pipeline -->|"persists assessment"| node_db
node_app -.->|"starts monitor worker"| node_monitor
node_reports_api -->|"uses claim exports"| node_exports
node_app -->|"initializes database"| node_db

click node_farmer_ui "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/frontend/src/app/farmer/page.tsx"
click node_claim_ui "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/frontend/src/app/farmer/claims/page.tsx"
click node_dashboard "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/frontend/src/app/dashboard/page.tsx"
click node_offline_submit "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/frontend/src/lib/offline/useOfflineClaimSubmit.ts"
click node_offline_store "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/frontend/src/lib/offline/db.ts"
click node_sync "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/frontend/src/lib/offline/syncEngine.ts"
click node_api_client "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/frontend/src/lib/api.ts"
click node_app "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/main.py"
click node_auth_api "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/api/auth.py"
click node_auth_service "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/services/auth_service.py"
click node_auth_deps "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/api/deps.py"
click node_reports_api "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/api/reports.py"
click node_storage_service "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/services/storage_service.py"
click node_consumer "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/workers/consumer.py"
click node_pipeline "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/workers/ai_pipeline.py"
click node_cv "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/services/cv_service.py"
click node_weather "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/services/weather_service.py"
click node_scoring "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/services/scoring_service.py"
click node_monitor "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/services/weather_monitor_service.py"
click node_db "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/db/session.py"
click node_exports "https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/services/pmfby_export_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_farmer_ui,node_claim_ui,node_dashboard,node_offline_submit,node_offline_store,node_sync,node_api_client toneBlue
class node_app,node_auth_api,node_auth_service,node_auth_deps toneAmber
class node_reports_api,node_storage_service,node_object_store,node_exports toneMint
class node_pipeline,node_cv,node_weather,node_scoring,node_monitor toneRose
class node_redis,node_consumer,node_db,node_farmer,node_official toneIndigo
```

## Components

### Farmer and Inspector Experience

- [Farmer PWA](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/frontend/src/app/farmer/page.tsx): `frontend/src/app/farmer/page.tsx`
- [Claims View](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/frontend/src/app/farmer/claims/page.tsx): `frontend/src/app/farmer/claims/page.tsx`
- [Review Dashboard](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/frontend/src/app/dashboard/page.tsx): `frontend/src/app/dashboard/page.tsx`
- [Offline Claim Submit](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/frontend/src/lib/offline/useOfflineClaimSubmit.ts): `frontend/src/lib/offline/useOfflineClaimSubmit.ts`
- [Offline Claim Store](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/frontend/src/lib/offline/db.ts): `frontend/src/lib/offline/db.ts`
- [Claim Sync Engine](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/frontend/src/lib/offline/syncEngine.ts): `frontend/src/lib/offline/syncEngine.ts`
- [Frontend API Client](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/frontend/src/lib/api.ts): `frontend/src/lib/api.ts`

### API and Identity

- [FastAPI Runtime](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/main.py): `backend/app/main.py`
- [Authentication API](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/api/auth.py): `backend/app/api/auth.py`
- [Identity Service](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/services/auth_service.py): `backend/app/services/auth_service.py`
- [Auth and Role Guards](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/api/deps.py): `backend/app/api/deps.py`

### Claims and Evidence

- [Claims API](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/api/reports.py): `backend/app/api/reports.py`
- [Evidence Storage](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/services/storage_service.py): `backend/app/services/storage_service.py`
- **MinIO Object Store**
- [Claim Exports and Certificates](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/services/pmfby_export_service.py): `backend/app/services/pmfby_export_service.py`

### Assessment and Weather

- [AI Assessment Pipeline](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/workers/ai_pipeline.py): `backend/app/workers/ai_pipeline.py`
- [Vision and Duplicate Audit](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/services/cv_service.py): `backend/app/services/cv_service.py`
- [Claim Weather Correlation](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/services/weather_service.py): `backend/app/services/weather_service.py`
- [Confidence Scoring](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/services/scoring_service.py): `backend/app/services/scoring_service.py`
- [Proactive Weather Monitor](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/services/weather_monitor_service.py): `backend/app/services/weather_monitor_service.py`

### Runtime and Persistence

- **Redis Streams**
- [Stream Consumer](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/workers/consumer.py): `backend/app/workers/consumer.py`
- [PostgreSQL and PostGIS](https://github.com/shreyanshfs/fasalrakshak-ai-powered-crop-loss-evidence-verification-system/blob/main/backend/app/db/session.py): `backend/app/db/session.py`

### Other components

- **Farmer**
- **Inspector**

## Connections

- Farmer → Farmer PWA: captures loss (evidence: `README.md`)
- Farmer PWA → Offline Claim Submit: queues offline
- Offline Claim Submit → Offline Claim Store: stores claim (evidence: `frontend/src/lib/offline/useOfflineClaimSubmit.ts`)
- Claim Sync Engine → Offline Claim Store: reads and updates (evidence: `frontend/src/lib/offline/syncEngine.ts`)
- Claim Sync Engine → Frontend API Client: uploads claim
- Farmer PWA → Frontend API Client: uses API
- Frontend API Client → FastAPI Runtime: sends requests
- Inspector → Review Dashboard: reviews cases (evidence: `README.md`)
- Review Dashboard → Frontend API Client: requests review data
- FastAPI Runtime → Authentication API: routes requests (evidence: `backend/app/main.py`)
- FastAPI Runtime → Claims API: routes requests (evidence: `backend/app/main.py`)
- Authentication API → Identity Service: uses identity service (evidence: `backend/app/api/auth.py`)
- Authentication API → Auth and Role Guards: checks roles (evidence: `backend/app/api/auth.py`)
- Identity Service → PostgreSQL and PostGIS: reads and writes users (evidence: `backend/app/services/auth_service.py`)
- Claims API → Auth and Role Guards: guards claim routes (evidence: `backend/app/api/reports.py`)
- Claims API → PostgreSQL and PostGIS: persists claim data (evidence: `backend/app/api/reports.py`)
- Claims API → Evidence Storage: requests evidence URLs (evidence: `backend/app/api/reports.py`)
- Evidence Storage → MinIO Object Store: creates upload URLs (evidence: `backend/app/services/storage_service.py`)
- FastAPI Runtime → Stream Consumer: starts worker (evidence: `backend/app/main.py`)
- Stream Consumer → Redis Streams: consumes events (evidence: `backend/app/workers/consumer.py`)
- Stream Consumer → AI Assessment Pipeline: runs assessment (evidence: `backend/app/workers/consumer.py`)
- AI Assessment Pipeline → MinIO Object Store: fetches images (evidence: `backend/app/workers/ai_pipeline.py`)
- AI Assessment Pipeline → Vision and Duplicate Audit: analyzes and checks duplicates (evidence: `backend/app/workers/ai_pipeline.py`)
- AI Assessment Pipeline → Claim Weather Correlation: fetches correlation (evidence: `backend/app/workers/ai_pipeline.py`)
- AI Assessment Pipeline → Confidence Scoring: computes confidence (evidence: `backend/app/workers/ai_pipeline.py`)
- AI Assessment Pipeline → PostgreSQL and PostGIS: persists assessment (evidence: `backend/app/workers/ai_pipeline.py`)
- FastAPI Runtime → Proactive Weather Monitor: starts monitor worker
- Claims API → Claim Exports and Certificates: uses claim exports (evidence: `backend/app/api/reports.py`)
- FastAPI Runtime → PostgreSQL and PostGIS: initializes database (evidence: `backend/app/main.py`)
