# ashish-netam011/famsecure architecture

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

- Interactive diagram: https://gitdiagram.com/ashish-netam011/famsecure
- Repository: https://github.com/ashish-netam011/famsecure

## Overview

FarmRescue is an agricultural emergency early-warning and response platform. Farmers report a problem or supply field observations; the system assembles evidence, assesses risk with deterministic rules, validates a stored action plan, and presents response guidance. Field workers can verify conditions, while reassessment and outcome reporting preserve an incident history. Weather, AI explanations, and MongoDB persistence are supporting capabilities. The README documents the overall flow; sampled sources confirm key API, store, evidence, and persistence links, but several page and integration connections are documented rather than source-verified.

Main entry points: [`src/domain/store/index.ts`](https://github.com/ashish-netam011/famsecure/blob/master/src/domain/store/index.ts) (Incident and farm store), [`src/app/api/fields/[id]/incidents/route.ts`](https://github.com/ashish-netam011/famsecure/blob/master/src/app/api/fields/%5Bid%5D/incidents/route.ts) (Field incident route), [`src/app/incidents/[id]/page.tsx`](https://github.com/ashish-netam011/famsecure/blob/master/src/app/incidents/%5Bid%5D/page.tsx) (Incident response), [`src/domain/weather/fieldBundle.ts`](https://github.com/ashish-netam011/famsecure/blob/master/src/domain/weather/fieldBundle.ts) (Weather bundle)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Farmer and worker experience"]
  node_dashboard["Farm dashboard<br/>[page.tsx]"]
  node_reporting["Incident wizard<br/>[page.tsx]"]
  node_response["Incident response<br/>[page.tsx]"]
  node_workerqueue["Inspection queue<br/>[page.tsx]"]
  node_history["Audit history<br/>[page.tsx]"]
  node_simulator["Simulation drawer"]
end

subgraph group_api["API and field evidence"]
  node_incidentapi["Incident routes<br/>[route.ts]"]
  node_fieldincidentapi["Field incident route<br/>[route.ts]"]
  node_fieldcontext["Evidence context<br/>[context.ts]"]
  node_weather["Weather bundle<br/>[fieldBundle.ts]"]
  node_soil["Soil adapter<br/>[adapter.ts]"]
end

subgraph group_assessment["Assessment and response"]
  node_risk["Risk rules<br/>[rules.ts]"]
  node_safety["Safety gate<br/>[safetyGate.ts]"]
  node_plans["Stored action plans<br/>[recommendations.ts]"]
  node_ai["AI explanation adapter<br/>[adapter.ts]"]
end

subgraph group_operations["History and persistence"]
  node_store[("Incident and farm store<br/>[index.ts]")]
  node_persistence[("Mongo persistence<br/>[mongo.ts]")]
end

node_farmer(("Farmer"))
node_worker(("Field worker"))
node_weatherprovider["Open-Meteo"]
node_gemini["Gemini"]
node_mongodb[("MongoDB")]

node_farmer -->|"views"| node_dashboard
node_farmer -->|"reports incident"| node_reporting
node_reporting -->|"submits report"| node_incidentapi
node_incidentapi -->|"creates incident"| node_store
node_store -->|"evaluates risk"| node_risk
node_store -->|"validates actions"| node_safety
node_safety -->|"validates plan"| node_plans
node_store -->|"persists mutations"| node_persistence
node_persistence -->|"writes and hydrates"| node_mongodb
node_store -.->|"serves assessment"| node_response
node_response -->|"requests explanation"| node_ai
node_ai -.->|"optionally explains"| node_gemini
node_farmer -->|"reports from field"| node_fieldincidentapi
node_fieldincidentapi -->|"reads and creates"| node_store
node_fieldincidentapi -->|"fetches conditions"| node_weather
node_fieldincidentapi -->|"fetches regional soil"| node_soil
node_fieldincidentapi -->|"builds evidence"| node_fieldcontext
node_fieldcontext -.->|"supplies evidence"| node_risk
node_weather -.->|"fetches weather"| node_weatherprovider
node_worker -->|"reviews queue"| node_workerqueue
node_workerqueue -.->|"verifies incident"| node_store
node_response -.->|"adds evidence and outcomes"| node_store
node_response -->|"records assessment timeline"| node_history
node_simulator -.->|"requests reassessment"| node_store
node_dashboard -.->|"shows conditions"| node_weather

click node_dashboard "https://github.com/ashish-netam011/famsecure/blob/master/src/app/page.tsx"
click node_reporting "https://github.com/ashish-netam011/famsecure/blob/master/src/app/incidents/new/page.tsx"
click node_response "https://github.com/ashish-netam011/famsecure/blob/master/src/app/incidents/%5Bid%5D/page.tsx"
click node_workerqueue "https://github.com/ashish-netam011/famsecure/blob/master/src/app/field-worker/page.tsx"
click node_history "https://github.com/ashish-netam011/famsecure/blob/master/src/app/history/page.tsx"
click node_simulator "https://github.com/ashish-netam011/famsecure/blob/master/src/components/SimulationDrawer.tsx"
click node_incidentapi "https://github.com/ashish-netam011/famsecure/blob/master/src/app/api/incidents/route.ts"
click node_fieldincidentapi "https://github.com/ashish-netam011/famsecure/blob/master/src/app/api/fields/%5Bid%5D/incidents/route.ts"
click node_fieldcontext "https://github.com/ashish-netam011/famsecure/blob/master/src/domain/field/context.ts"
click node_weather "https://github.com/ashish-netam011/famsecure/blob/master/src/domain/weather/fieldBundle.ts"
click node_soil "https://github.com/ashish-netam011/famsecure/blob/master/src/domain/soil/adapter.ts"
click node_risk "https://github.com/ashish-netam011/famsecure/blob/master/src/domain/risk/rules.ts"
click node_safety "https://github.com/ashish-netam011/famsecure/blob/master/src/domain/safety/safetyGate.ts"
click node_plans "https://github.com/ashish-netam011/famsecure/blob/master/src/domain/actions/recommendations.ts"
click node_ai "https://github.com/ashish-netam011/famsecure/blob/master/src/domain/ai/adapter.ts"
click node_store "https://github.com/ashish-netam011/famsecure/blob/master/src/domain/store/index.ts"
click node_persistence "https://github.com/ashish-netam011/famsecure/blob/master/src/lib/persistence/mongo.ts"

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_dashboard,node_reporting,node_response,node_workerqueue,node_history,node_simulator toneBlue
class node_incidentapi,node_fieldincidentapi,node_fieldcontext,node_weather,node_soil,node_mongodb toneAmber
class node_risk,node_safety,node_plans,node_ai toneMint
class node_store,node_persistence,node_worker toneRose
class node_farmer,node_weatherprovider,node_gemini toneIndigo
```

## Components

### Farmer and worker experience

- [Farm dashboard](https://github.com/ashish-netam011/famsecure/blob/master/src/app/page.tsx): `src/app/page.tsx`
- [Incident wizard](https://github.com/ashish-netam011/famsecure/blob/master/src/app/incidents/new/page.tsx): `src/app/incidents/new/page.tsx`
- [Incident response](https://github.com/ashish-netam011/famsecure/blob/master/src/app/incidents/%5Bid%5D/page.tsx): `src/app/incidents/[id]/page.tsx`
- [Inspection queue](https://github.com/ashish-netam011/famsecure/blob/master/src/app/field-worker/page.tsx): `src/app/field-worker/page.tsx`
- [Audit history](https://github.com/ashish-netam011/famsecure/blob/master/src/app/history/page.tsx): `src/app/history/page.tsx`
- [Simulation drawer](https://github.com/ashish-netam011/famsecure/blob/master/src/components/SimulationDrawer.tsx): `src/components/SimulationDrawer.tsx`

### API and field evidence

- [Incident routes](https://github.com/ashish-netam011/famsecure/blob/master/src/app/api/incidents/route.ts): `src/app/api/incidents/route.ts`
- [Field incident route](https://github.com/ashish-netam011/famsecure/blob/master/src/app/api/fields/%5Bid%5D/incidents/route.ts): `src/app/api/fields/[id]/incidents/route.ts`
- [Evidence context](https://github.com/ashish-netam011/famsecure/blob/master/src/domain/field/context.ts): `src/domain/field/context.ts`
- [Weather bundle](https://github.com/ashish-netam011/famsecure/blob/master/src/domain/weather/fieldBundle.ts): `src/domain/weather/fieldBundle.ts`
- [Soil adapter](https://github.com/ashish-netam011/famsecure/blob/master/src/domain/soil/adapter.ts): `src/domain/soil/adapter.ts`

### Assessment and response

- [Risk rules](https://github.com/ashish-netam011/famsecure/blob/master/src/domain/risk/rules.ts): `src/domain/risk/rules.ts`
- [Safety gate](https://github.com/ashish-netam011/famsecure/blob/master/src/domain/safety/safetyGate.ts): `src/domain/safety/safetyGate.ts`
- [Stored action plans](https://github.com/ashish-netam011/famsecure/blob/master/src/domain/actions/recommendations.ts): `src/domain/actions/recommendations.ts`
- [AI explanation adapter](https://github.com/ashish-netam011/famsecure/blob/master/src/domain/ai/adapter.ts): `src/domain/ai/adapter.ts`

### History and persistence

- [Incident and farm store](https://github.com/ashish-netam011/famsecure/blob/master/src/domain/store/index.ts): `src/domain/store/index.ts`
- [Mongo persistence](https://github.com/ashish-netam011/famsecure/blob/master/src/lib/persistence/mongo.ts): `src/lib/persistence/mongo.ts`

### Other components

- **Farmer**
- **Field worker**
- **Open-Meteo**
- **Gemini**
- **MongoDB**

## Connections

- Farmer → Farm dashboard: views (evidence: `README.md`)
- Farmer → Incident wizard: reports incident (evidence: `README.md`)
- Incident wizard → Incident routes: submits report (evidence: `README.md`)
- Incident routes → Incident and farm store: creates incident (evidence: `src/app/api/incidents/route.ts`)
- Incident and farm store → Risk rules: evaluates risk (evidence: `src/domain/store/index.ts`)
- Incident and farm store → Safety gate: validates actions (evidence: `src/domain/store/index.ts`)
- Safety gate → Stored action plans: validates plan (evidence: `README.md`)
- Incident and farm store → Mongo persistence: persists mutations (evidence: `src/domain/store/index.ts`)
- Mongo persistence → MongoDB: writes and hydrates (evidence: `README.md`)
- Incident and farm store → Incident response: serves assessment
- Incident response → AI explanation adapter: requests explanation (evidence: `README.md`)
- AI explanation adapter → Gemini: optionally explains (evidence: `README.md`)
- Farmer → Field incident route: reports from field (evidence: `README.md`)
- Field incident route → Incident and farm store: reads and creates (evidence: `src/app/api/fields/[id]/incidents/route.ts`)
- Field incident route → Weather bundle: fetches conditions (evidence: `src/app/api/fields/[id]/incidents/route.ts`)
- Field incident route → Soil adapter: fetches regional soil (evidence: `src/app/api/fields/[id]/incidents/route.ts`)
- Field incident route → Evidence context: builds evidence (evidence: `src/app/api/fields/[id]/incidents/route.ts`)
- Evidence context → Risk rules: supplies evidence
- Weather bundle → Open-Meteo: fetches weather (evidence: `README.md`)
- Field worker → Inspection queue: reviews queue (evidence: `README.md`)
- Inspection queue → Incident and farm store: verifies incident
- Incident response → Incident and farm store: adds evidence and outcomes
- Incident response → Audit history: records assessment timeline (evidence: `README.md`)
- Simulation drawer → Incident and farm store: requests reassessment
- Farm dashboard → Weather bundle: shows conditions (evidence: `README.md`)
