# nandakumar005/ai_crop_prediction architecture

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

- Interactive diagram: https://gitdiagram.com/nandakumar005/ai_crop_prediction
- Repository: https://github.com/nandakumar005/ai_crop_prediction

## Overview

AI Crop Prediction is a Flask application that combines submitted soil values and GPS coordinates with weather and location lookups, ranks suitable crops with a trained model, adds market estimates, and generates a comparison chart. Users can also request a separate Gemini farming advisory. The app and service calls are visible in the sampled source; UI interactions and some presentation details are based on the README, since the template was not sampled.

Main entry points: [`app.py`](https://github.com/nandakumar005/ai_crop_prediction/blob/main/app.py) (Flask API), [`templates/index.html`](https://github.com/nandakumar005/ai_crop_prediction/blob/main/templates/index.html) (Web Interface), [`services/crop_service.py`](https://github.com/nandakumar005/ai_crop_prediction/blob/main/services/crop_service.py) (Crop Ranking), [`services/weather_data.py`](https://github.com/nandakumar005/ai_crop_prediction/blob/main/services/weather_data.py) (Weather Lookup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web Workflow"]
  node_ui["Web Interface<br/>[index.html]"]
  node_app["Flask API<br/>[app.py]"]
end

subgraph group_prediction["Crop Prediction"]
  node_cropmodel["Crop Ranking<br/>[crop_service.py]"]
  node_model["Trained Model"]
end

subgraph group_context["Farm Context"]
  node_weather["Weather Lookup<br/>[weather_data.py]"]
  node_openweather["OpenWeatherMap"]
  node_location["Reverse Geocoding"]
  node_nominatim["Nominatim"]
end

subgraph group_advisory["Market And Advice"]
  node_market["Price Estimation<br/>[market_service.py]"]
  node_datagov["data.gov API"]
  node_chart["Price Chart<br/>[app.py]"]
  node_gemini["Advisory Service<br/>[gemini_service.py]"]
  node_google["Google Gemini"]
end

node_farmer(("Farmer"))

node_farmer -->|"enters inputs"| node_ui
node_ui -->|"submits analysis"| node_app
node_app -->|"renders interface"| node_ui
node_app -->|"fetches weather"| node_weather
node_weather -->|"requests conditions"| node_openweather
node_app -->|"fetches location"| node_location
node_location -->|"reverse geocodes"| node_nominatim
node_app -->|"ranks crops"| node_cropmodel
node_cropmodel -->|"loads probabilities"| node_model
node_app -->|"prices crops"| node_market
node_market -->|"requests prices"| node_datagov
node_app -->|"builds chart"| node_chart
node_app -->|"returns results"| node_ui
node_farmer -->|"requests advice"| node_ui
node_ui -->|"posts advisory data"| node_app
node_app -->|"requests summary"| node_gemini
node_gemini -->|"generates advice"| node_google
node_app -->|"returns advisory"| node_ui

click node_ui "https://github.com/nandakumar005/ai_crop_prediction/blob/main/templates/index.html"
click node_app "https://github.com/nandakumar005/ai_crop_prediction/blob/main/app.py"
click node_weather "https://github.com/nandakumar005/ai_crop_prediction/blob/main/services/weather_data.py"
click node_location "https://github.com/nandakumar005/ai_crop_prediction/blob/main/services/location_service.py"
click node_cropmodel "https://github.com/nandakumar005/ai_crop_prediction/blob/main/services/crop_service.py"
click node_model "https://github.com/nandakumar005/ai_crop_prediction/blob/main/models/crop_recommendation_model.pkl"
click node_market "https://github.com/nandakumar005/ai_crop_prediction/blob/main/services/market_service.py"
click node_chart "https://github.com/nandakumar005/ai_crop_prediction/blob/main/app.py"
click node_gemini "https://github.com/nandakumar005/ai_crop_prediction/blob/main/services/gemini_service.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_ui,node_app toneBlue
class node_cropmodel,node_model toneAmber
class node_weather,node_openweather,node_location,node_nominatim toneMint
class node_market,node_datagov,node_chart,node_gemini,node_google toneRose
class node_farmer toneIndigo
```

## Components

### Web Workflow

- [Web Interface](https://github.com/nandakumar005/ai_crop_prediction/blob/main/templates/index.html): `templates/index.html`
- [Flask API](https://github.com/nandakumar005/ai_crop_prediction/blob/main/app.py): `app.py`

### Crop Prediction

- [Crop Ranking](https://github.com/nandakumar005/ai_crop_prediction/blob/main/services/crop_service.py): `services/crop_service.py`
- [Trained Model](https://github.com/nandakumar005/ai_crop_prediction/blob/main/models/crop_recommendation_model.pkl): `models/crop_recommendation_model.pkl`

### Farm Context

- [Weather Lookup](https://github.com/nandakumar005/ai_crop_prediction/blob/main/services/weather_data.py): `services/weather_data.py`
- **OpenWeatherMap**
- [Reverse Geocoding](https://github.com/nandakumar005/ai_crop_prediction/blob/main/services/location_service.py): `services/location_service.py`
- **Nominatim**

### Market And Advice

- [Price Estimation](https://github.com/nandakumar005/ai_crop_prediction/blob/main/services/market_service.py): `services/market_service.py`
- **data.gov API**
- [Price Chart](https://github.com/nandakumar005/ai_crop_prediction/blob/main/app.py): `app.py`
- [Advisory Service](https://github.com/nandakumar005/ai_crop_prediction/blob/main/services/gemini_service.py): `services/gemini_service.py`
- **Google Gemini**

### Other components

- **Farmer**

## Connections

- Farmer → Web Interface: enters inputs (evidence: `README.md`)
- Web Interface → Flask API: submits analysis (evidence: `README.md`)
- Flask API → Web Interface: renders interface (evidence: `app.py`)
- Flask API → Weather Lookup: fetches weather (evidence: `app.py`)
- Weather Lookup → OpenWeatherMap: requests conditions (evidence: `services/weather_data.py`)
- Flask API → Reverse Geocoding: fetches location (evidence: `app.py`)
- Reverse Geocoding → Nominatim: reverse geocodes (evidence: `services/location_service.py`)
- Flask API → Crop Ranking: ranks crops (evidence: `app.py`)
- Crop Ranking → Trained Model: loads probabilities (evidence: `services/crop_service.py`)
- Flask API → Price Estimation: prices crops (evidence: `app.py`)
- Price Estimation → data.gov API: requests prices (evidence: `services/market_service.py`)
- Flask API → Price Chart: builds chart (evidence: `app.py`)
- Flask API → Web Interface: returns results (evidence: `README.md`)
- Farmer → Web Interface: requests advice (evidence: `README.md`)
- Web Interface → Flask API: posts advisory data (evidence: `README.md`)
- Flask API → Advisory Service: requests summary (evidence: `app.py`)
- Advisory Service → Google Gemini: generates advice (evidence: `services/gemini_service.py`)
- Flask API → Web Interface: returns advisory (evidence: `app.py`)
