How bug1857/agriroute-ai works
AgriRoute AI is a prototype for harvest planning, with separate synthetic-demo, live-assisted, and synthetic-Mandi workspaces. The principal workflow is coordinator sign-in and lot planning, human review and approval, then delivery of an approved snapshot to the assigned farmer. The graph also preserves buyer-offer review, what-if analysis, and the optional Gemini agent. Source excerpts establish several API-to-library calls; README statements support the documented user workflows and provider boundaries. Some UI-to-API wiring is not shown, so it is omitted.
Main entry points: coordinator/route.ts Coordinator workflow API · coordinator.ts Auth and approvals · mandi.ts Mandi analysis · live/route.ts Live evidence API
Components 28
Coordinator and farmer
- Coordinator workspace
components/CoordinatorWorkspace.tsx - Farmer decision
components/FarmerDecision.tsx - Coordinator workflow API
app/api/coordinator/route.ts - Auth and approvals
lib/coordinator.ts - Farmer snapshot
lib/farmer-record.ts
Planning and analysis
- Lot planner
lib/planner.ts - Demo world data
lib/world.ts - Demo explorer
components/Explorer.tsx - What-if analysis
components/WhatIfAnalysis.tsx - What-if API
app/api/whatif/route.ts - Sensitivity analysis
lib/whatif.ts
Live assisted
- Live workspace
components/LiveWorkspace.tsx - Live evidence API
app/api/live/route.ts - Live assessment
lib/live.ts - Weather and routing
lib/live-providers.ts
Synthetic Mandi
- Mandi workspace
components/MandiWorkspace.tsx - Mandi analysis
lib/mandi.ts - Synthetic prices
lib/mandi-data.ts - Buyer offer review
components/BuyerOfferReview.tsx - Offer review API
app/api/offers/route.ts - Offer parsing
lib/offers.ts
Persistence and agent
- Agent API
app/api/agent/route.ts - Planning agent
lib/agent.ts - Gemini adapter
lib/gemini-server.ts - Replay records
lib/agent-store.ts - PostgreSQL
lib/database.ts
Other components
- Coordinator
- Farmer
Connections 28
- Coordinator → Coordinator workspace: plans lots
README.md - Coordinator workspace → Coordinator workflow API: submits workflow
- Coordinator workflow API → Auth and approvals: authenticates and routes
app/api/coordinator/route.ts - Coordinator workflow API → PostgreSQL: plans in transaction
app/api/coordinator/route.ts - Coordinator workflow API → Mandi analysis: plans lot
app/api/coordinator/route.ts - Coordinator workflow API → Synthetic prices: reads prices
app/api/coordinator/route.ts - Auth and approvals → PostgreSQL: reads and writes
lib/coordinator.ts - Auth and approvals → Offer parsing: validates offers
lib/coordinator.ts - Auth and approvals → Mandi analysis: validates plans
lib/coordinator.ts - Auth and approvals → Farmer snapshot: formats snapshot
- Farmer → Farmer decision: views decision
README.md - Demo explorer → Lot planner: plans scenarios
components/Explorer.tsx - Demo explorer → Demo world data: uses world data
components/Explorer.tsx - What-if API → Sensitivity analysis: analyzes scenario
app/api/whatif/route.ts - What-if API → Demo world data: reads world
app/api/whatif/route.ts - What-if analysis → What-if API: requests analysis
- Live workspace → Live evidence API: requests evidence
- Live evidence API → Live assessment: recalculates workflow
app/api/live/route.ts - Live evidence API → Weather and routing: fetches evidence
app/api/live/route.ts - Mandi workspace → Mandi analysis: uses analysis
components/MandiWorkspace.tsx - Mandi workspace → Synthetic prices: uses dataset
components/MandiWorkspace.tsx - Buyer offer review → Offer review API: submits review
components/BuyerOfferReview.tsx - Offer review API → Offer parsing: parses offer
- Agent API → Gemini adapter: invokes agent
app/api/agent/route.ts - Gemini adapter → Planning agent: runs function calls
lib/gemini-server.ts - Gemini adapter → Replay records: records traces
lib/gemini-server.ts - Mandi analysis → Lot planner: uses calculations
lib/mandi.ts - Live assessment → Lot planner: uses risk and storage
lib/live.ts