# momoinuddin-ali/kisanmitra-ai-smart-farming-project architecture

> Architecture diagram of the GitHub repository momoinuddin-ali/kisanmitra-ai-smart-farming-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project
- Repository: https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project

## Overview

KisanMitra AI is a farming-advice application. A farmer submits location, crop, growth stage and optionally symptoms or a leaf photo through the dashboard or CLI. The core orchestrator gathers a live farm snapshot, builds shared context, dispatches four advisory agents and returns a combined report. The README also describes crop-knowledge retrieval, market-trend analysis and Grok-backed reasoning; sampled agent excerpts show simplified fallback implementations, so those richer behaviors are documented capabilities rather than verified runtime links here. The plural market module is separate from the singular module registered in the sampled runtime.

Main entry points: [`main_core.py`](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/main_core.py) (Agent pipeline), [`agents/base_agent.py`](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/agents/base_agent.py) (Agent base), [`app.py`](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/app.py) (Flask API), [`agents/crop_advisory_agent.py`](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/agents/crop_advisory_agent.py) (Crop advice)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Farmer access"]
  node_dashboard["Web dashboard<br/>[index.html]"]
  node_web_api["Flask API<br/>[app.py]"]
  node_cli["CLI entry<br/>[main_core.py]"]
end

subgraph group_orchestration["Context and orchestration"]
  node_context["Farm context<br/>[main_core.py]"]
  node_pipeline["Agent pipeline<br/>[main_core.py]"]
  node_report["Advisory report<br/>[main_core.py]"]
end

subgraph group_advisory["Farm advisory"]
  node_weather_agent["Weather advice"]
  node_crop_agent["Crop advice"]
  node_pest_agent["Pest detection"]
  node_market_agent["Market advice"]
  node_market_logic["Market analysis logic"]
  node_agent_base["Agent base<br/>[base_agent.py]"]
end

subgraph group_services["Data and services"]
  node_weather_client["Weather client<br/>[weather_client.py]"]
  node_crop_data["Crop knowledge"]
  node_price_data["Market prices<br/>[market_prices.json]"]
  node_config["Settings<br/>[config.py]"]
end

node_farmer(("Farmer"))
node_open_meteo["Open-Meteo"]
node_grok["Grok API"]

node_farmer -->|"uses"| node_dashboard
node_dashboard -->|"submits query"| node_web_api
node_farmer -->|"provides input"| node_cli
node_web_api -->|"builds context"| node_context
node_cli -->|"builds context"| node_context
node_context -->|"fetches snapshot"| node_weather_client
node_weather_client -->|"requests weather"| node_open_meteo
node_weather_client -->|"reads settings"| node_config
node_context -->|"supplies context"| node_pipeline
node_pipeline -->|"dispatches"| node_weather_agent
node_pipeline -->|"dispatches"| node_crop_agent
node_pipeline -->|"dispatches"| node_pest_agent
node_pipeline -->|"dispatches"| node_market_agent
node_weather_agent -->|"inherits"| node_agent_base
node_crop_agent -->|"inherits"| node_agent_base
node_pest_agent -->|"inherits"| node_agent_base
node_market_agent -->|"inherits"| node_agent_base
node_pipeline -->|"assembles results"| node_report
node_web_api -->|"returns JSON"| node_report
node_market_logic -->|"reads prices"| node_price_data
node_market_logic -.->|"requests analysis"| node_grok
node_crop_agent -.->|"uses knowledge"| node_crop_data
node_agent_base -.->|"uses model"| node_grok
node_web_api -->|"serves UI"| node_dashboard

click node_dashboard "https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/index.html"
click node_web_api "https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/app.py"
click node_cli "https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/main_core.py"
click node_context "https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/main_core.py"
click node_pipeline "https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/main_core.py"
click node_weather_agent "https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/agents/weather_irrigation_agent.py"
click node_crop_agent "https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/agents/crop_advisory_agent.py"
click node_pest_agent "https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/agents/pest_detection_agent.py"
click node_market_agent "https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/agents/market_insights_agent.py"
click node_market_logic "https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/agents/market_insights_agents.py"
click node_agent_base "https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/agents/base_agent.py"
click node_weather_client "https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/utils/weather_client.py"
click node_crop_data "https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/data/crop_knowledge.json"
click node_price_data "https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/data/market_prices.json"
click node_config "https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/config.py"
click node_report "https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/main_core.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_dashboard,node_web_api,node_cli toneBlue
class node_context,node_pipeline,node_report toneAmber
class node_weather_agent,node_crop_agent,node_pest_agent,node_market_agent,node_market_logic,node_agent_base,node_grok toneMint
class node_weather_client,node_crop_data,node_price_data,node_config toneRose
class node_farmer,node_open_meteo toneIndigo
```

## Components

### Farmer access

- [Web dashboard](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/index.html): `index.html`
- [Flask API](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/app.py): `app.py`
- [CLI entry](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/main_core.py): `main_core.py`

### Context and orchestration

- [Farm context](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/main_core.py): `main_core.py`
- [Agent pipeline](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/main_core.py): `main_core.py`
- [Advisory report](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/main_core.py): `main_core.py`

### Farm advisory

- [Weather advice](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/agents/weather_irrigation_agent.py): `agents/weather_irrigation_agent.py`
- [Crop advice](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/agents/crop_advisory_agent.py): `agents/crop_advisory_agent.py`
- [Pest detection](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/agents/pest_detection_agent.py): `agents/pest_detection_agent.py`
- [Market advice](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/agents/market_insights_agent.py): `agents/market_insights_agent.py`
- [Market analysis logic](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/agents/market_insights_agents.py): `agents/market_insights_agents.py`
- [Agent base](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/agents/base_agent.py): `agents/base_agent.py`

### Data and services

- [Weather client](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/utils/weather_client.py): `utils/weather_client.py`
- [Crop knowledge](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/data/crop_knowledge.json): `data/crop_knowledge.json`
- [Market prices](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/data/market_prices.json): `data/market_prices.json`
- [Settings](https://github.com/momoinuddin-ali/kisanmitra-ai-smart-farming-project/blob/main/config.py): `config.py`

### Other components

- **Farmer**
- **Open-Meteo**
- **Grok API**

## Connections

- Farmer → Web dashboard: uses (evidence: `README.md`)
- Web dashboard → Flask API: submits query (evidence: `app.py`)
- Farmer → CLI entry: provides input (evidence: `README.md`)
- Flask API → Farm context: builds context (evidence: `app.py`)
- CLI entry → Farm context: builds context (evidence: `main_core.py`)
- Farm context → Weather client: fetches snapshot (evidence: `main_core.py`)
- Weather client → Open-Meteo: requests weather (evidence: `utils/weather_client.py`)
- Weather client → Settings: reads settings (evidence: `utils/weather_client.py`)
- Farm context → Agent pipeline: supplies context (evidence: `main_core.py`)
- Agent pipeline → Weather advice: dispatches
- Agent pipeline → Crop advice: dispatches
- Agent pipeline → Pest detection: dispatches
- Agent pipeline → Market advice: dispatches
- Weather advice → Agent base: inherits (evidence: `agents/weather_irrigation_agent.py`)
- Crop advice → Agent base: inherits (evidence: `agents/crop_advisory_agent.py`)
- Pest detection → Agent base: inherits (evidence: `agents/pest_detection_agent.py`)
- Market advice → Agent base: inherits (evidence: `agents/market_insights_agent.py`)
- Agent pipeline → Advisory report: assembles results (evidence: `main_core.py`)
- Flask API → Advisory report: returns JSON (evidence: `app.py`)
- Market analysis logic → Market prices: reads prices (evidence: `agents/market_insights_agents.py`)
- Market analysis logic → Grok API: requests analysis
- Crop advice → Crop knowledge: uses knowledge (evidence: `README.md`)
- Agent base → Grok API: uses model (evidence: `README.md`)
- Flask API → Web dashboard: serves UI (evidence: `app.py`)
