# chirag0071/farmora-ai architecture

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

- Interactive diagram: https://gitdiagram.com/chirag0071/farmora-ai
- Repository: https://github.com/chirag0071/farmora-ai

## Overview

Farmora combines a Streamlit interface with a FastAPI service for Indian crop-market insights. The user selects a location, crop, cost, and optional historical date; the prediction page stores those inputs and opens results, which request market history and display prices, forecasts, and profitability. Results also request mapped market locations and crop suggestions. The backend fetches and normalizes Agmarknet data, then derives forecasts, coordinates, or recommendation scores. API routes and service calls are evidenced in excerpts; home/about and some backend behavior are only partly sampled, so their connections are omitted where unverified.

Main entry points: [`backend/main.py`](https://github.com/chirag0071/farmora-ai/blob/main/backend/main.py) (FastAPI routes), [`app.py`](https://github.com/chirag0071/farmora-ai/blob/main/app.py) (Navigation shell), [`pages/predict.py`](https://github.com/chirag0071/farmora-ai/blob/main/pages/predict.py) (Prediction inputs), [`pages/result.py`](https://github.com/chirag0071/farmora-ai/blob/main/pages/result.py) (Results dashboard)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Streamlit interface"]
  node_app["Navigation shell<br/>[app.py]"]
  node_home["Home and info<br/>[home.py]"]
  node_help["Usage help<br/>[help.py]"]
  node_predict["Prediction inputs<br/>[predict.py]"]
  node_crops["Crop catalog<br/>[crops.py]"]
  node_results["Results dashboard<br/>[result.py]"]
  node_suggestions_page["Suggestion view<br/>[suggestions.py]"]
end

subgraph group_api["API orchestration"]
  node_api["FastAPI routes<br/>[main.py]"]
end

subgraph group_market["Market data"]
  node_prices["Price history<br/>[agmarknet.py]"]
  node_agmarknet(("Agmarknet API"))
end

subgraph group_insights["Market insights"]
  node_forecast["Price forecasting<br/>[forecasting.py]"]
  node_geocoding["Market geocoding<br/>[geocoding.py]"]
  node_nominatim(("Nominatim"))
  node_recommendations["Crop recommendations<br/>[recommendations.py]"]
end

node_farmer(("Farmer"))
node_states_service(("Location lookup API"))

node_farmer -->|"opens"| node_app
node_app -->|"navigates"| node_home
node_app -->|"navigates"| node_help
node_app -->|"navigates"| node_predict
node_app -->|"routes to"| node_results
node_app -->|"routes to"| node_suggestions_page
node_predict -->|"collects inputs"| node_farmer
node_predict -->|"uses catalog"| node_crops
node_predict -->|"fetches locations"| node_states_service
node_predict -->|"switches page"| node_results
node_results -->|"requests history"| node_api
node_api -->|"loads and filters"| node_prices
node_prices -->|"fetches records"| node_agmarknet
node_api -->|"forecasts prices"| node_forecast
node_results -->|"requests locations"| node_api
node_api -->|"gets locations"| node_geocoding
node_geocoding -->|"loads market history"| node_prices
node_geocoding -->|"geocodes markets"| node_nominatim
node_results -->|"requests suggestions"| node_api
node_suggestions_page -->|"requests suggestions"| node_api
node_api -->|"gets suggestions"| node_recommendations
node_recommendations -->|"fetches records"| node_prices

click node_app "https://github.com/chirag0071/farmora-ai/blob/main/app.py"
click node_home "https://github.com/chirag0071/farmora-ai/blob/main/pages/home.py"
click node_help "https://github.com/chirag0071/farmora-ai/blob/main/pages/help.py"
click node_predict "https://github.com/chirag0071/farmora-ai/blob/main/pages/predict.py"
click node_crops "https://github.com/chirag0071/farmora-ai/blob/main/utils/crops.py"
click node_results "https://github.com/chirag0071/farmora-ai/blob/main/pages/result.py"
click node_suggestions_page "https://github.com/chirag0071/farmora-ai/blob/main/pages/suggestions.py"
click node_api "https://github.com/chirag0071/farmora-ai/blob/main/backend/main.py"
click node_prices "https://github.com/chirag0071/farmora-ai/blob/main/backend/services/agmarknet.py"
click node_forecast "https://github.com/chirag0071/farmora-ai/blob/main/backend/services/forecasting.py"
click node_geocoding "https://github.com/chirag0071/farmora-ai/blob/main/backend/services/geocoding.py"
click node_recommendations "https://github.com/chirag0071/farmora-ai/blob/main/backend/services/recommendations.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_app,node_home,node_help,node_predict,node_crops,node_results,node_suggestions_page toneBlue
class node_api toneAmber
class node_prices,node_agmarknet,node_states_service toneMint
class node_forecast,node_geocoding,node_nominatim,node_recommendations toneRose
class node_farmer toneIndigo
```

## Components

### Streamlit interface

- [Navigation shell](https://github.com/chirag0071/farmora-ai/blob/main/app.py): `app.py`
- [Home and info](https://github.com/chirag0071/farmora-ai/blob/main/pages/home.py): `pages/home.py`
- [Usage help](https://github.com/chirag0071/farmora-ai/blob/main/pages/help.py): `pages/help.py`
- [Prediction inputs](https://github.com/chirag0071/farmora-ai/blob/main/pages/predict.py): `pages/predict.py`
- [Crop catalog](https://github.com/chirag0071/farmora-ai/blob/main/utils/crops.py): `utils/crops.py`
- [Results dashboard](https://github.com/chirag0071/farmora-ai/blob/main/pages/result.py): `pages/result.py`
- [Suggestion view](https://github.com/chirag0071/farmora-ai/blob/main/pages/suggestions.py): `pages/suggestions.py`

### API orchestration

- [FastAPI routes](https://github.com/chirag0071/farmora-ai/blob/main/backend/main.py): `backend/main.py`

### Market data

- [Price history](https://github.com/chirag0071/farmora-ai/blob/main/backend/services/agmarknet.py): `backend/services/agmarknet.py`
- **Agmarknet API**

### Market insights

- [Price forecasting](https://github.com/chirag0071/farmora-ai/blob/main/backend/services/forecasting.py): `backend/services/forecasting.py`
- [Market geocoding](https://github.com/chirag0071/farmora-ai/blob/main/backend/services/geocoding.py): `backend/services/geocoding.py`
- **Nominatim**
- [Crop recommendations](https://github.com/chirag0071/farmora-ai/blob/main/backend/services/recommendations.py): `backend/services/recommendations.py`

### Other components

- **Farmer**
- **Location lookup API**

## Connections

- Farmer → Navigation shell: opens (evidence: `app.py`)
- Navigation shell → Home and info: navigates (evidence: `app.py`)
- Navigation shell → Usage help: navigates (evidence: `app.py`)
- Navigation shell → Prediction inputs: navigates (evidence: `app.py`)
- Navigation shell → Results dashboard: routes to (evidence: `app.py`)
- Navigation shell → Suggestion view: routes to (evidence: `app.py`)
- Prediction inputs → Farmer: collects inputs (evidence: `pages/predict.py`)
- Prediction inputs → Crop catalog: uses catalog (evidence: `pages/predict.py`)
- Prediction inputs → Location lookup API: fetches locations (evidence: `pages/predict.py`)
- Prediction inputs → Results dashboard: switches page (evidence: `pages/predict.py`)
- Results dashboard → FastAPI routes: requests history (evidence: `pages/result.py`)
- FastAPI routes → Price history: loads and filters (evidence: `backend/main.py`)
- Price history → Agmarknet API: fetches records (evidence: `backend/services/agmarknet.py`)
- FastAPI routes → Price forecasting: forecasts prices (evidence: `backend/main.py`)
- Results dashboard → FastAPI routes: requests locations (evidence: `pages/result.py`)
- FastAPI routes → Market geocoding: gets locations (evidence: `backend/main.py`)
- Market geocoding → Price history: loads market history (evidence: `backend/services/geocoding.py`)
- Market geocoding → Nominatim: geocodes markets (evidence: `backend/services/geocoding.py`)
- Results dashboard → FastAPI routes: requests suggestions (evidence: `pages/result.py`)
- Suggestion view → FastAPI routes: requests suggestions (evidence: `pages/suggestions.py`)
- FastAPI routes → Crop recommendations: gets suggestions (evidence: `backend/main.py`)
- Crop recommendations → Price history: fetches records (evidence: `backend/services/recommendations.py`)
