# yagnasuthar/farmxpert architecture

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

- Interactive diagram: https://gitdiagram.com/yagnasuthar/farmxpert
- Repository: https://github.com/yagnasuthar/farmxpert

## Overview

FarmXpert is a multi-agent farm-advisory product: a farmer uses the web app to ask a question or request farm operations guidance; the Node API supplies farm context to the stateless AI service, returns an answer, and owns persistence. The graph also preserves the documented specialist-advisory and task-planning capabilities, plus authentication, farm data, and knowledge retrieval. The README and sampled entry points support the cross-service flow; some internal agent wiring is not shown, so only documented relationships are drawn.

Main entry points: [`AI_Backend/orchestration/engine.py`](https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/orchestration/engine.py) (Execution engine), [`Backend/src/app.js`](https://github.com/yagnasuthar/farmxpert/blob/main/Backend/src/app.js) (HTTP API), [`Backend/src/modules/chat/routes.js`](https://github.com/yagnasuthar/farmxpert/blob/main/Backend/src/modules/chat/routes.js) (Chat and voice), [`Backend/src/db/pool.js`](https://github.com/yagnasuthar/farmxpert/blob/main/Backend/src/db/pool.js) (PostgreSQL data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Farmer experience"]
  node_web["Web app<br/>[page.jsx]"]
  node_authui["Sign-in and onboarding<br/>[page.jsx]"]
end

subgraph group_api["Application API"]
  node_apiapp["HTTP API<br/>[app.js]"]
  node_auth["Authentication<br/>[routes.js]"]
  node_chat["Chat and voice<br/>[routes.js]"]
  node_farmdata["Farm and soil API<br/>[farms.js]"]
  node_plans["Plans and tasks API<br/>[plans.js]"]
  node_aiclient["AI service client<br/>[ai.js]"]
end

subgraph group_ai["AI advisory"]
  node_aiapp["FastAPI service<br/>[main.py]"]
  node_orchestrator["Agent orchestrator<br/>[service.py]"]
  node_engine["Execution engine<br/>[engine.py]"]
  node_crop["Crop recommendations<br/>[service.py]"]
  node_weather["Weather advisories<br/>[service.py]"]
  node_soil["Soil analysis<br/>[service.py]"]
  node_irrigation["Irrigation planning<br/>[service.py]"]
  node_market["Market intelligence<br/>[service.py]"]
  node_scheduler["Task planning<br/>[service.py]"]
  node_retrieval["Knowledge retrieval<br/>[service.py]"]
end

subgraph group_data["Farm data"]
  node_pg[("PostgreSQL data<br/>[pool.js]")]
  node_knowledge[("Knowledge index<br/>[store.py]")]
end

subgraph group_integrations["External services"]
  node_weatherapi["Weather providers"]
  node_llm["Language model"]
  node_mandi["Mandi data"]
end

node_farmer(("Farmer"))

node_farmer -->|"asks or views"| node_web
node_web -->|"sends requests"| node_apiapp
node_apiapp -->|"routes auth"| node_auth
node_apiapp -->|"routes chat"| node_chat
node_apiapp -->|"routes farm data"| node_farmdata
node_apiapp -->|"routes plans"| node_plans
node_authui -->|"submits credentials"| node_apiapp
node_auth -->|"reads and writes"| node_pg
node_farmdata -->|"reads and writes"| node_pg
node_plans -->|"reads and writes"| node_pg
node_chat -->|"loads context and history"| node_pg
node_chat -->|"requests advisory"| node_aiclient
node_aiclient -->|"sends farm context"| node_aiapp
node_aiapp -->|"routes advisory"| node_orchestrator
node_orchestrator -->|"executes plan"| node_engine
node_engine -->|"dispatches agent"| node_crop
node_engine -->|"dispatches agent"| node_weather
node_engine -->|"dispatches agent"| node_soil
node_engine -->|"dispatches agent"| node_irrigation
node_engine -->|"dispatches agent"| node_market
node_engine -->|"dispatches agent"| node_scheduler
node_engine -->|"dispatches agent"| node_retrieval
node_weather -->|"fetches forecasts"| node_weatherapi
node_market -->|"fetches market data"| node_mandi
node_retrieval -->|"reads index"| node_knowledge
node_orchestrator -.->|"generates language output"| node_llm
node_aiapp -->|"returns advisory"| node_chat
node_chat -->|"returns answer"| node_web
node_chat -->|"records answered turn"| node_pg

click node_web "https://github.com/yagnasuthar/farmxpert/blob/main/Frontend/src/app/%5Blocale%5D/(app)/dashboard/assistant/page.jsx"
click node_authui "https://github.com/yagnasuthar/farmxpert/blob/main/Frontend/src/app/%5Blocale%5D/(app)/auth/login/page.jsx"
click node_apiapp "https://github.com/yagnasuthar/farmxpert/blob/main/Backend/src/app.js"
click node_auth "https://github.com/yagnasuthar/farmxpert/blob/main/Backend/src/modules/auth/routes.js"
click node_chat "https://github.com/yagnasuthar/farmxpert/blob/main/Backend/src/modules/chat/routes.js"
click node_farmdata "https://github.com/yagnasuthar/farmxpert/blob/main/Backend/src/modules/farms.js"
click node_plans "https://github.com/yagnasuthar/farmxpert/blob/main/Backend/src/modules/plans.js"
click node_aiclient "https://github.com/yagnasuthar/farmxpert/blob/main/Backend/src/clients/ai.js"
click node_pg "https://github.com/yagnasuthar/farmxpert/blob/main/Backend/src/db/pool.js"
click node_aiapp "https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/main.py"
click node_orchestrator "https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/orchestration/service.py"
click node_engine "https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/orchestration/engine.py"
click node_crop "https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/agents/crop_planning_growth/crop_prediction/service.py"
click node_weather "https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/agents/crop_planning_growth/weather_watcher/service.py"
click node_soil "https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/agents/crop_planning_growth/soil_health/service.py"
click node_irrigation "https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/agents/crop_planning_growth/irrigation_planner/service.py"
click node_market "https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/agents/supplychain_market_access/market_intelligence/service.py"
click node_scheduler "https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/agents/farm_operations_automation/task_scheduler/service.py"
click node_retrieval "https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/agents/retrieval_agent/service.py"
click node_knowledge "https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/agents/retrieval_agent/store.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_web,node_authui toneBlue
class node_apiapp,node_auth,node_chat,node_farmdata,node_plans,node_aiclient toneAmber
class node_aiapp,node_orchestrator,node_engine,node_crop,node_weather,node_soil,node_irrigation,node_market,node_scheduler,node_retrieval toneMint
class node_pg,node_knowledge toneRose
class node_weatherapi,node_llm,node_mandi,node_farmer toneIndigo
```

## Components

### Farmer experience

- [Web app](https://github.com/yagnasuthar/farmxpert/blob/main/Frontend/src/app/%5Blocale%5D/(app)/dashboard/assistant/page.jsx): `Frontend/src/app/[locale]/(app)/dashboard/assistant/page.jsx`
- [Sign-in and onboarding](https://github.com/yagnasuthar/farmxpert/blob/main/Frontend/src/app/%5Blocale%5D/(app)/auth/login/page.jsx): `Frontend/src/app/[locale]/(app)/auth/login/page.jsx`

### Application API

- [HTTP API](https://github.com/yagnasuthar/farmxpert/blob/main/Backend/src/app.js): `Backend/src/app.js`
- [Authentication](https://github.com/yagnasuthar/farmxpert/blob/main/Backend/src/modules/auth/routes.js): `Backend/src/modules/auth/routes.js`
- [Chat and voice](https://github.com/yagnasuthar/farmxpert/blob/main/Backend/src/modules/chat/routes.js): `Backend/src/modules/chat/routes.js`
- [Farm and soil API](https://github.com/yagnasuthar/farmxpert/blob/main/Backend/src/modules/farms.js): `Backend/src/modules/farms.js`
- [Plans and tasks API](https://github.com/yagnasuthar/farmxpert/blob/main/Backend/src/modules/plans.js): `Backend/src/modules/plans.js`
- [AI service client](https://github.com/yagnasuthar/farmxpert/blob/main/Backend/src/clients/ai.js): `Backend/src/clients/ai.js`

### AI advisory

- [FastAPI service](https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/main.py): `AI_Backend/main.py`
- [Agent orchestrator](https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/orchestration/service.py): `AI_Backend/orchestration/service.py`
- [Execution engine](https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/orchestration/engine.py): `AI_Backend/orchestration/engine.py`
- [Crop recommendations](https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/agents/crop_planning_growth/crop_prediction/service.py): `AI_Backend/agents/crop_planning_growth/crop_prediction/service.py`
- [Weather advisories](https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/agents/crop_planning_growth/weather_watcher/service.py): `AI_Backend/agents/crop_planning_growth/weather_watcher/service.py`
- [Soil analysis](https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/agents/crop_planning_growth/soil_health/service.py): `AI_Backend/agents/crop_planning_growth/soil_health/service.py`
- [Irrigation planning](https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/agents/crop_planning_growth/irrigation_planner/service.py): `AI_Backend/agents/crop_planning_growth/irrigation_planner/service.py`
- [Market intelligence](https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/agents/supplychain_market_access/market_intelligence/service.py): `AI_Backend/agents/supplychain_market_access/market_intelligence/service.py`
- [Task planning](https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/agents/farm_operations_automation/task_scheduler/service.py): `AI_Backend/agents/farm_operations_automation/task_scheduler/service.py`
- [Knowledge retrieval](https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/agents/retrieval_agent/service.py): `AI_Backend/agents/retrieval_agent/service.py`

### Farm data

- [PostgreSQL data](https://github.com/yagnasuthar/farmxpert/blob/main/Backend/src/db/pool.js): `Backend/src/db/pool.js`
- [Knowledge index](https://github.com/yagnasuthar/farmxpert/blob/main/AI_Backend/agents/retrieval_agent/store.py): `AI_Backend/agents/retrieval_agent/store.py`

### External services

- **Weather providers**
- **Language model**
- **Mandi data**

### Other components

- **Farmer**

## Connections

- Farmer → Web app: asks or views
- Web app → HTTP API: sends requests
- HTTP API → Authentication: routes auth
- HTTP API → Chat and voice: routes chat
- HTTP API → Farm and soil API: routes farm data
- HTTP API → Plans and tasks API: routes plans
- Sign-in and onboarding → HTTP API: submits credentials
- Authentication → PostgreSQL data: reads and writes
- Farm and soil API → PostgreSQL data: reads and writes
- Plans and tasks API → PostgreSQL data: reads and writes
- Chat and voice → PostgreSQL data: loads context and history
- Chat and voice → AI service client: requests advisory
- AI service client → FastAPI service: sends farm context
- FastAPI service → Agent orchestrator: routes advisory
- Agent orchestrator → Execution engine: executes plan
- Execution engine → Crop recommendations: dispatches agent
- Execution engine → Weather advisories: dispatches agent
- Execution engine → Soil analysis: dispatches agent
- Execution engine → Irrigation planning: dispatches agent
- Execution engine → Market intelligence: dispatches agent
- Execution engine → Task planning: dispatches agent
- Execution engine → Knowledge retrieval: dispatches agent
- Weather advisories → Weather providers: fetches forecasts
- Market intelligence → Mandi data: fetches market data
- Knowledge retrieval → Knowledge index: reads index
- Agent orchestrator → Language model: generates language output
- FastAPI service → Chat and voice: returns advisory
- Chat and voice → Web app: returns answer
- Chat and voice → PostgreSQL data: records answered turn
