# farahnaqwi/agrifarm architecture

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

- Interactive diagram: https://gitdiagram.com/farahnaqwi/agrifarm
- Repository: https://github.com/farahnaqwi/agrifarm

## Overview

AgriFarm is an offline-first PWA that turns a farmer’s consented account, plot, and photos into a tagged evidence report she can review and choose to share. Its main path runs from capture through on-device speech extraction and farmer confirmation, then report generation and sealing; a lender can retrieve the shared report, check its hash, review evidence, and request a site visit. The README documents satellite/weather checks and cooperative attestation as report capabilities. Some of those data-production paths are outside the supplied tree, so their implementation links are not inferred.

Main entry points: [`app/src/capture/Flow.tsx`](https://github.com/farahnaqwi/agrifarm/blob/main/app/src/capture/Flow.tsx) (Capture flow), [`backend/engine/index.ts`](https://github.com/farahnaqwi/agrifarm/blob/main/backend/engine/index.ts) (Report engine), [`app/src/data/reports.ts`](https://github.com/farahnaqwi/agrifarm/blob/main/app/src/data/reports.ts) (Report sharing), [`app/src/lender/Verify.tsx`](https://github.com/farahnaqwi/agrifarm/blob/main/app/src/lender/Verify.tsx) (Lender verification)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Farmer capture"]
  node_flow["Capture flow<br/>[Flow.tsx]"]
  node_speech["Speech extraction<br/>[extract.ts]"]
  node_asr["On-device ASR<br/>[asr.ts]"]
  node_plot["Plot capture<br/>[Plot.tsx]"]
  node_photos["Photo capture<br/>[Photos.tsx]"]
  node_capturedata["Capture record<br/>[capture.ts]"]
end

subgraph group_evidence["Evidence and report"]
  node_evidencecards["Evidence cards<br/>[cards.ts]"]
  node_engine["Report engine<br/>[index.ts]"]
  node_canonical["Canonicalization<br/>[canonical.ts]"]
  node_narrative["Report narration<br/>[speech.ts]"]
  node_review["Farmer review<br/>[Review.tsx]"]
end

subgraph group_sharing["Sharing and storage"]
  node_seal["Phone sealing<br/>[engine.ts]"]
  node_reports["Report sharing<br/>[reports.ts]"]
  node_offline[("Offline store<br/>[store.ts]")]
end

subgraph group_lender["Lender review"]
  node_lenderverify["Lender verification<br/>[Verify.tsx]"]
  node_charts["Evidence charts<br/>[charts.tsx]"]
end

subgraph group_contracts["Shared contracts"]
  node_contracts["Report contracts<br/>[report.ts]"]
end

node_farmer(("Farmer"))
node_supabase[("Supabase")]
node_officer(("Loan officer"))
node_satweather[("Satellite and weather records")]
node_cooperative["Cooperative attestation"]

node_farmer -->|"provides input"| node_flow
node_flow -->|"routes speech"| node_speech
node_speech -->|"transcribes audio"| node_asr
node_flow -->|"routes plot capture"| node_plot
node_flow -->|"routes photo capture"| node_photos
node_flow -->|"assembles capture"| node_capturedata
node_flow -->|"loads cards"| node_evidencecards
node_flow -->|"builds report"| node_engine
node_engine -->|"canonicalizes"| node_canonical
node_engine -->|"composes narration"| node_narrative
node_engine -.->|"checks evidence"| node_satweather
node_engine -.->|"uses attestations"| node_cooperative
node_flow -->|"routes report review"| node_review
node_flow -->|"seals approved report"| node_seal
node_seal -->|"uploads report"| node_reports
node_reports -->|"queues offline"| node_offline
node_reports -.->|"sends and fetches"| node_supabase
node_officer -->|"opens QR report"| node_lenderverify
node_lenderverify -->|"fetches report"| node_reports
node_lenderverify -->|"renders evidence"| node_charts
node_officer -->|"requests site visit"| node_lenderverify
node_capturedata -->|"uses report types"| node_contracts
node_engine -->|"uses report types"| node_contracts

click node_flow "https://github.com/farahnaqwi/agrifarm/blob/main/app/src/capture/Flow.tsx"
click node_speech "https://github.com/farahnaqwi/agrifarm/blob/main/app/src/ai/extract.ts"
click node_asr "https://github.com/farahnaqwi/agrifarm/blob/main/app/src/ai/asr.ts"
click node_plot "https://github.com/farahnaqwi/agrifarm/blob/main/app/src/capture/Plot.tsx"
click node_photos "https://github.com/farahnaqwi/agrifarm/blob/main/app/src/capture/Photos.tsx"
click node_capturedata "https://github.com/farahnaqwi/agrifarm/blob/main/app/src/capture/capture.ts"
click node_evidencecards "https://github.com/farahnaqwi/agrifarm/blob/main/app/src/data/cards.ts"
click node_engine "https://github.com/farahnaqwi/agrifarm/blob/main/backend/engine/index.ts"
click node_canonical "https://github.com/farahnaqwi/agrifarm/blob/main/backend/engine/canonical.ts"
click node_narrative "https://github.com/farahnaqwi/agrifarm/blob/main/backend/engine/speech.ts"
click node_review "https://github.com/farahnaqwi/agrifarm/blob/main/app/src/capture/Review.tsx"
click node_seal "https://github.com/farahnaqwi/agrifarm/blob/main/app/src/engine.ts"
click node_reports "https://github.com/farahnaqwi/agrifarm/blob/main/app/src/data/reports.ts"
click node_offline "https://github.com/farahnaqwi/agrifarm/blob/main/app/src/offline/store.ts"
click node_lenderverify "https://github.com/farahnaqwi/agrifarm/blob/main/app/src/lender/Verify.tsx"
click node_charts "https://github.com/farahnaqwi/agrifarm/blob/main/app/src/lender/charts.tsx"
click node_contracts "https://github.com/farahnaqwi/agrifarm/blob/main/app/src/types/report.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_flow,node_speech,node_asr,node_plot,node_photos,node_capturedata toneBlue
class node_evidencecards,node_engine,node_canonical,node_narrative,node_review,node_supabase,node_satweather toneAmber
class node_seal,node_reports,node_offline toneMint
class node_lenderverify,node_charts toneRose
class node_contracts,node_farmer,node_officer,node_cooperative toneIndigo
```

## Components

### Farmer capture

- [Capture flow](https://github.com/farahnaqwi/agrifarm/blob/main/app/src/capture/Flow.tsx): `app/src/capture/Flow.tsx`
- [Speech extraction](https://github.com/farahnaqwi/agrifarm/blob/main/app/src/ai/extract.ts): `app/src/ai/extract.ts`
- [On-device ASR](https://github.com/farahnaqwi/agrifarm/blob/main/app/src/ai/asr.ts): `app/src/ai/asr.ts`
- [Plot capture](https://github.com/farahnaqwi/agrifarm/blob/main/app/src/capture/Plot.tsx): `app/src/capture/Plot.tsx`
- [Photo capture](https://github.com/farahnaqwi/agrifarm/blob/main/app/src/capture/Photos.tsx): `app/src/capture/Photos.tsx`
- [Capture record](https://github.com/farahnaqwi/agrifarm/blob/main/app/src/capture/capture.ts): `app/src/capture/capture.ts`

### Evidence and report

- [Evidence cards](https://github.com/farahnaqwi/agrifarm/blob/main/app/src/data/cards.ts): `app/src/data/cards.ts`
- [Report engine](https://github.com/farahnaqwi/agrifarm/blob/main/backend/engine/index.ts): `backend/engine/index.ts`
- [Canonicalization](https://github.com/farahnaqwi/agrifarm/blob/main/backend/engine/canonical.ts): `backend/engine/canonical.ts`
- [Report narration](https://github.com/farahnaqwi/agrifarm/blob/main/backend/engine/speech.ts): `backend/engine/speech.ts`
- [Farmer review](https://github.com/farahnaqwi/agrifarm/blob/main/app/src/capture/Review.tsx): `app/src/capture/Review.tsx`

### Sharing and storage

- [Phone sealing](https://github.com/farahnaqwi/agrifarm/blob/main/app/src/engine.ts): `app/src/engine.ts`
- [Report sharing](https://github.com/farahnaqwi/agrifarm/blob/main/app/src/data/reports.ts): `app/src/data/reports.ts`
- [Offline store](https://github.com/farahnaqwi/agrifarm/blob/main/app/src/offline/store.ts): `app/src/offline/store.ts`

### Lender review

- [Lender verification](https://github.com/farahnaqwi/agrifarm/blob/main/app/src/lender/Verify.tsx): `app/src/lender/Verify.tsx`
- [Evidence charts](https://github.com/farahnaqwi/agrifarm/blob/main/app/src/lender/charts.tsx): `app/src/lender/charts.tsx`

### Shared contracts

- [Report contracts](https://github.com/farahnaqwi/agrifarm/blob/main/app/src/types/report.ts): `app/src/types/report.ts`

### Other components

- **Farmer**
- **Supabase**
- **Loan officer**
- **Satellite and weather records**
- **Cooperative attestation**

## Connections

- Farmer → Capture flow: provides input (evidence: `README.md`)
- Capture flow → Speech extraction: routes speech (evidence: `app/src/capture/Flow.tsx`)
- Speech extraction → On-device ASR: transcribes audio (evidence: `app/src/ai/extract.ts`)
- Capture flow → Plot capture: routes plot capture (evidence: `app/src/capture/Flow.tsx`)
- Capture flow → Photo capture: routes photo capture (evidence: `app/src/capture/Flow.tsx`)
- Capture flow → Capture record: assembles capture (evidence: `app/src/capture/Flow.tsx`)
- Capture flow → Evidence cards: loads cards (evidence: `app/src/capture/Flow.tsx`)
- Capture flow → Report engine: builds report
- Report engine → Canonicalization: canonicalizes (evidence: `backend/engine/index.ts`)
- Report engine → Report narration: composes narration (evidence: `backend/engine/index.ts`)
- Report engine → Satellite and weather records: checks evidence (evidence: `README.md`)
- Report engine → Cooperative attestation: uses attestations (evidence: `README.md`)
- Capture flow → Farmer review: routes report review (evidence: `app/src/capture/Flow.tsx`)
- Capture flow → Phone sealing: seals approved report (evidence: `app/src/capture/Flow.tsx`)
- Phone sealing → Report sharing: uploads report (evidence: `app/src/capture/Share.tsx`)
- Report sharing → Offline store: queues offline (evidence: `app/src/data/reports.ts`)
- Report sharing → Supabase: sends and fetches (evidence: `app/src/data/reports.ts`)
- Loan officer → Lender verification: opens QR report (evidence: `README.md`)
- Lender verification → Report sharing: fetches report (evidence: `app/src/lender/Verify.tsx`)
- Lender verification → Evidence charts: renders evidence (evidence: `app/src/lender/Verify.tsx`)
- Loan officer → Lender verification: requests site visit (evidence: `app/src/lender/Verify.tsx`)
- Capture record → Report contracts: uses report types
- Report engine → Report contracts: uses report types (evidence: `backend/engine/index.ts`)
