# creativearun/agriflow architecture

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

- Interactive diagram: https://gitdiagram.com/creativearun/agriflow
- Repository: https://github.com/creativearun/agriflow

## Overview

AgriFlow is a farm-to-market platform whose principal journey runs from farmer produce listing and quality/market analysis through buyer matching and aggregation to shipment planning and tracking. The tree contains a React client, a FastAPI intelligence service, and an Express logistics service; the README also describes a Spring core backend, but no corresponding source is present here. The graph preserves major documented stages and capabilities; unsampled service internals and cross-service wiring are omitted unless documented or visible in the excerpts.

Main entry points: [`agriflow-farm-intelligence-api/app/main.py`](https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/main.py) (Intelligence API), [`agriflow-farm-intelligence-api/app/services/agriculture_service.py`](https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/services/agriculture_service.py) (Combined Analysis), [`frontend/src/lib/api/services.js`](https://github.com/creativearun/agriflow/blob/main/frontend/src/lib/api/services.js) (API Client), [`agriflow-farm-intelligence-api/app/services/quality_service.py`](https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/services/quality_service.py) (Quality Assessment)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Farmer and Buyer Client"]
  node_app["FarmFlow Interface<br/>[farmlink-app.jsx]"]
  node_map["Shipment Map<br/>[MapLeaflet.jsx]"]
  node_voice["Voice Input"]
  node_speech["Text to Speech"]
  node_assistant["AI Assistant"]
  node_api_client["API Client<br/>[services.js]"]
end

subgraph group_intelligence["Farm Intelligence"]
  node_ai_api["Intelligence API<br/>[main.py]"]
  node_quality["Quality Assessment<br/>[quality_service.py]"]
  node_vision_model["Vision Model<br/>[quality_model.py]"]
  node_price["Price Forecasting<br/>[price_service.py]"]
  node_price_model["Price Model<br/>[price_model.py]"]
  node_demand["Demand Forecasting<br/>[demand_service.py]"]
  node_matching["Buyer Matching"]
  node_aggregation["Supply Aggregation"]
  node_ag_analysis["Combined Analysis"]
  node_language["Multilingual Advice"]
end

subgraph group_logistics["Shipment Logistics"]
  node_log_app["Logistics API<br/>[app.js]"]
  node_shipments["Shipment Management"]
  node_tracking["GPS Tracking"]
  node_routes["Route Planning"]
  node_recalc_controller["Route Recalculation"]
  node_recalc_service["Recalculation Service"]
  node_tracking_service["Location State"]
  node_socket["Live Events<br/>[socket.js]"]
end

subgraph group_outside["External Services"]
  node_osrm["OSRM Routing"]
  node_hosted_model["Hosted Vision Model"]
  node_core_backend["Core Backend"]
end

node_farmer(("Farmer / Buyer"))

node_farmer -->|"uses"| node_app
node_app -->|"requests data"| node_api_client
node_app -->|"renders"| node_map
node_app -->|"opens assistant"| node_assistant
node_assistant -->|"accepts speech"| node_voice
node_assistant -->|"speaks response"| node_speech
node_map -->|"requests logistics"| node_api_client
node_api_client -->|"calls API"| node_core_backend
node_api_client -->|"calls API"| node_ai_api
node_api_client -->|"calls API"| node_log_app
node_ai_api -->|"routes requests"| node_quality
node_ai_api -->|"routes requests"| node_price
node_ai_api -->|"routes requests"| node_matching
node_ai_api -->|"routes requests"| node_aggregation
node_ai_api -->|"routes requests"| node_ag_analysis
node_quality -->|"analyzes image"| node_vision_model
node_quality -->|"localizes description"| node_language
node_vision_model -->|"requests analysis"| node_hosted_model
node_price -->|"forecasts prices"| node_price_model
node_price -->|"formats advice"| node_language
node_ag_analysis -->|"assesses quality"| node_quality
node_ag_analysis -->|"forecasts prices"| node_price
node_ag_analysis -->|"forecasts demand"| node_demand
node_ag_analysis -->|"finds buyers"| node_matching
node_ag_analysis -->|"aggregates insights"| node_aggregation
node_matching -->|"localizes reasons"| node_language
node_log_app -->|"routes requests"| node_shipments
node_log_app -->|"routes requests"| node_tracking
node_log_app -->|"routes requests"| node_routes
node_log_app -->|"routes requests"| node_recalc_controller
node_tracking -->|"updates location"| node_tracking_service
node_tracking -->|"gets route"| node_routes
node_tracking -->|"recalculates route"| node_recalc_service
node_tracking -->|"emits location"| node_socket
node_recalc_controller -->|"recalculates route"| node_recalc_service
node_recalc_service -->|"requests road route"| node_osrm
node_api_client -->|"subscribes updates"| node_socket
node_farmer -.->|"submits produce"| node_quality
node_quality -.->|"continues workflow"| node_price
node_matching -.->|"contributes supply"| node_aggregation
node_aggregation -.->|"leads to order delivery"| node_shipments

click node_app "https://github.com/creativearun/agriflow/blob/main/frontend/src/components/farmlink-app.jsx"
click node_map "https://github.com/creativearun/agriflow/blob/main/frontend/src/components/MapLeaflet.jsx"
click node_voice "https://github.com/creativearun/agriflow/blob/main/frontend/src/components/VoiceInputButton.jsx"
click node_speech "https://github.com/creativearun/agriflow/blob/main/frontend/src/components/TextToSpeechButton.jsx"
click node_assistant "https://github.com/creativearun/agriflow/blob/main/frontend/src/components/AIAssistantModal.jsx"
click node_api_client "https://github.com/creativearun/agriflow/blob/main/frontend/src/lib/api/services.js"
click node_ai_api "https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/main.py"
click node_quality "https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/services/quality_service.py"
click node_vision_model "https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/models/quality_model.py"
click node_price "https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/services/price_service.py"
click node_price_model "https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/models/price_model.py"
click node_demand "https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/services/demand_service.py"
click node_matching "https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/services/matching_service.py"
click node_aggregation "https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/services/aggregation_service.py"
click node_ag_analysis "https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/services/agriculture_service.py"
click node_language "https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/services/language_service.py"
click node_log_app "https://github.com/creativearun/agriflow/blob/main/logistics-service/src/app.js"
click node_shipments "https://github.com/creativearun/agriflow/blob/main/logistics-service/src/controllers/shipment.controller.js"
click node_tracking "https://github.com/creativearun/agriflow/blob/main/logistics-service/src/controllers/tracking.controller.js"
click node_routes "https://github.com/creativearun/agriflow/blob/main/logistics-service/src/controllers/route.controller.js"
click node_recalc_controller "https://github.com/creativearun/agriflow/blob/main/logistics-service/src/controllers/recalculation.controller.js"
click node_recalc_service "https://github.com/creativearun/agriflow/blob/main/logistics-service/src/services/recalculation.service.js"
click node_tracking_service "https://github.com/creativearun/agriflow/blob/main/logistics-service/src/services/tracking.service.js"
click node_socket "https://github.com/creativearun/agriflow/blob/main/logistics-service/src/socket/socket.js"

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_map,node_voice,node_speech,node_assistant,node_api_client toneBlue
class node_ai_api,node_quality,node_vision_model,node_price,node_price_model,node_demand,node_matching,node_aggregation,node_ag_analysis,node_language toneAmber
class node_log_app,node_shipments,node_tracking,node_routes,node_recalc_controller,node_recalc_service,node_tracking_service,node_socket toneMint
class node_osrm,node_hosted_model,node_core_backend toneRose
class node_farmer toneIndigo
```

## Components

### Farmer and Buyer Client

- [FarmFlow Interface](https://github.com/creativearun/agriflow/blob/main/frontend/src/components/farmlink-app.jsx): `frontend/src/components/farmlink-app.jsx`
- [Shipment Map](https://github.com/creativearun/agriflow/blob/main/frontend/src/components/MapLeaflet.jsx): `frontend/src/components/MapLeaflet.jsx`
- [Voice Input](https://github.com/creativearun/agriflow/blob/main/frontend/src/components/VoiceInputButton.jsx): `frontend/src/components/VoiceInputButton.jsx`
- [Text to Speech](https://github.com/creativearun/agriflow/blob/main/frontend/src/components/TextToSpeechButton.jsx): `frontend/src/components/TextToSpeechButton.jsx`
- [AI Assistant](https://github.com/creativearun/agriflow/blob/main/frontend/src/components/AIAssistantModal.jsx): `frontend/src/components/AIAssistantModal.jsx`
- [API Client](https://github.com/creativearun/agriflow/blob/main/frontend/src/lib/api/services.js): `frontend/src/lib/api/services.js`

### Farm Intelligence

- [Intelligence API](https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/main.py): `agriflow-farm-intelligence-api/app/main.py`
- [Quality Assessment](https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/services/quality_service.py): `agriflow-farm-intelligence-api/app/services/quality_service.py`
- [Vision Model](https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/models/quality_model.py): `agriflow-farm-intelligence-api/app/models/quality_model.py`
- [Price Forecasting](https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/services/price_service.py): `agriflow-farm-intelligence-api/app/services/price_service.py`
- [Price Model](https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/models/price_model.py): `agriflow-farm-intelligence-api/app/models/price_model.py`
- [Demand Forecasting](https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/services/demand_service.py): `agriflow-farm-intelligence-api/app/services/demand_service.py`
- [Buyer Matching](https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/services/matching_service.py): `agriflow-farm-intelligence-api/app/services/matching_service.py`
- [Supply Aggregation](https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/services/aggregation_service.py): `agriflow-farm-intelligence-api/app/services/aggregation_service.py`
- [Combined Analysis](https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/services/agriculture_service.py): `agriflow-farm-intelligence-api/app/services/agriculture_service.py`
- [Multilingual Advice](https://github.com/creativearun/agriflow/blob/main/agriflow-farm-intelligence-api/app/services/language_service.py): `agriflow-farm-intelligence-api/app/services/language_service.py`

### Shipment Logistics

- [Logistics API](https://github.com/creativearun/agriflow/blob/main/logistics-service/src/app.js): `logistics-service/src/app.js`
- [Shipment Management](https://github.com/creativearun/agriflow/blob/main/logistics-service/src/controllers/shipment.controller.js): `logistics-service/src/controllers/shipment.controller.js`
- [GPS Tracking](https://github.com/creativearun/agriflow/blob/main/logistics-service/src/controllers/tracking.controller.js): `logistics-service/src/controllers/tracking.controller.js`
- [Route Planning](https://github.com/creativearun/agriflow/blob/main/logistics-service/src/controllers/route.controller.js): `logistics-service/src/controllers/route.controller.js`
- [Route Recalculation](https://github.com/creativearun/agriflow/blob/main/logistics-service/src/controllers/recalculation.controller.js): `logistics-service/src/controllers/recalculation.controller.js`
- [Recalculation Service](https://github.com/creativearun/agriflow/blob/main/logistics-service/src/services/recalculation.service.js): `logistics-service/src/services/recalculation.service.js`
- [Location State](https://github.com/creativearun/agriflow/blob/main/logistics-service/src/services/tracking.service.js): `logistics-service/src/services/tracking.service.js`
- [Live Events](https://github.com/creativearun/agriflow/blob/main/logistics-service/src/socket/socket.js): `logistics-service/src/socket/socket.js`

### External Services

- **OSRM Routing**
- **Hosted Vision Model**
- **Core Backend**

### Other components

- **Farmer / Buyer**

## Connections

- Farmer / Buyer → FarmFlow Interface: uses
- FarmFlow Interface → API Client: requests data (evidence: `frontend/src/components/farmlink-app.jsx`)
- FarmFlow Interface → Shipment Map: renders (evidence: `frontend/src/components/farmlink-app.jsx`)
- FarmFlow Interface → AI Assistant: opens assistant (evidence: `frontend/src/components/farmlink-app.jsx`)
- AI Assistant → Voice Input: accepts speech (evidence: `frontend/src/components/AIAssistantModal.jsx`)
- AI Assistant → Text to Speech: speaks response (evidence: `frontend/src/components/AIAssistantModal.jsx`)
- Shipment Map → API Client: requests logistics (evidence: `frontend/src/components/MapLeaflet.jsx`)
- API Client → Core Backend: calls API (evidence: `frontend/src/lib/api/services.js`)
- API Client → Intelligence API: calls API (evidence: `frontend/src/lib/api/services.js`)
- API Client → Logistics API: calls API (evidence: `frontend/src/lib/api/services.js`)
- Intelligence API → Quality Assessment: routes requests (evidence: `agriflow-farm-intelligence-api/app/main.py`)
- Intelligence API → Price Forecasting: routes requests (evidence: `agriflow-farm-intelligence-api/app/main.py`)
- Intelligence API → Buyer Matching: routes requests (evidence: `agriflow-farm-intelligence-api/app/main.py`)
- Intelligence API → Supply Aggregation: routes requests (evidence: `agriflow-farm-intelligence-api/app/main.py`)
- Intelligence API → Combined Analysis: routes requests (evidence: `agriflow-farm-intelligence-api/app/main.py`)
- Quality Assessment → Vision Model: analyzes image (evidence: `agriflow-farm-intelligence-api/app/services/quality_service.py`)
- Quality Assessment → Multilingual Advice: localizes description (evidence: `agriflow-farm-intelligence-api/app/services/quality_service.py`)
- Vision Model → Hosted Vision Model: requests analysis
- Price Forecasting → Price Model: forecasts prices (evidence: `agriflow-farm-intelligence-api/app/services/price_service.py`)
- Price Forecasting → Multilingual Advice: formats advice (evidence: `agriflow-farm-intelligence-api/app/services/price_service.py`)
- Combined Analysis → Quality Assessment: assesses quality (evidence: `agriflow-farm-intelligence-api/app/services/agriculture_service.py`)
- Combined Analysis → Price Forecasting: forecasts prices (evidence: `agriflow-farm-intelligence-api/app/services/agriculture_service.py`)
- Combined Analysis → Demand Forecasting: forecasts demand (evidence: `agriflow-farm-intelligence-api/app/services/agriculture_service.py`)
- Combined Analysis → Buyer Matching: finds buyers (evidence: `agriflow-farm-intelligence-api/app/services/agriculture_service.py`)
- Combined Analysis → Supply Aggregation: aggregates insights (evidence: `agriflow-farm-intelligence-api/app/services/agriculture_service.py`)
- Buyer Matching → Multilingual Advice: localizes reasons (evidence: `agriflow-farm-intelligence-api/app/services/matching_service.py`)
- Logistics API → Shipment Management: routes requests (evidence: `logistics-service/src/app.js`)
- Logistics API → GPS Tracking: routes requests (evidence: `logistics-service/src/app.js`)
- Logistics API → Route Planning: routes requests (evidence: `logistics-service/src/app.js`)
- Logistics API → Route Recalculation: routes requests (evidence: `logistics-service/src/app.js`)
- GPS Tracking → Location State: updates location (evidence: `logistics-service/src/controllers/tracking.controller.js`)
- GPS Tracking → Route Planning: gets route (evidence: `logistics-service/src/controllers/tracking.controller.js`)
- GPS Tracking → Recalculation Service: recalculates route (evidence: `logistics-service/src/controllers/tracking.controller.js`)
- GPS Tracking → Live Events: emits location (evidence: `logistics-service/src/controllers/tracking.controller.js`)
- Route Recalculation → Recalculation Service: recalculates route (evidence: `logistics-service/src/controllers/recalculation.controller.js`)
- Recalculation Service → OSRM Routing: requests road route (evidence: `logistics-service/src/services/recalculation.service.js`)
- API Client → Live Events: subscribes updates (evidence: `frontend/src/lib/api/services.js`)
- Farmer / Buyer → Quality Assessment: submits produce
- Quality Assessment → Price Forecasting: continues workflow
- Buyer Matching → Supply Aggregation: contributes supply
- Supply Aggregation → Shipment Management: leads to order delivery
