# keerthipandala/smartfarmerassistant architecture

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

- Interactive diagram: https://gitdiagram.com/keerthipandala/smartfarmerassistant
- Repository: https://github.com/keerthipandala/smartfarmerassistant

## Overview

Smart Farmer Assistant is an agricultural decision-support web app. A farmer uses the React pages to submit crop, fertilizer, yield, or weather requests; the FastAPI backend authenticates protected requests, computes predictions or retrieves weather, and returns results. Crop and fertilizer predictions, yield predictions, and account records are persisted for dashboard/history use. The README documents the broader feature set; source excerpts directly show crop/fertilizer, authentication, and persistence paths, while some page-to-endpoint wiring is documented rather than excerpted.

Main entry points: [`backend/main.py`](https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/main.py) (FastAPI endpoints), [`frontend/src/App.js`](https://github.com/keerthipandala/smartfarmerassistant/blob/main/frontend/src/App.js) (React app routing), [`backend/routes/auth.py`](https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/routes/auth.py) (Account operations), [`frontend/src/pages/Crop.jsx`](https://github.com/keerthipandala/smartfarmerassistant/blob/main/frontend/src/pages/Crop.jsx) (Crop recommendation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Farmer interface"]
  node_react_app["React app routing<br/>[App.js]"]
  node_crop_page["Crop recommendation<br/>[Crop.jsx]"]
  node_fertilizer_page["Fertilizer recommendation<br/>[Fertilizer.jsx]"]
  node_yield_page["Yield prediction<br/>[Yield.jsx]"]
  node_weather_page["Weather lookup<br/>[Weather.jsx]"]
  node_dashboard_page["Dashboard summary<br/>[Dashboard.jsx]"]
  node_history_page["Prediction history<br/>[History.jsx]"]
end

subgraph group_api["Prediction and API"]
  node_api["FastAPI endpoints<br/>[main.py]"]
  node_crop_logic["Crop inference<br/>[crop.py]"]
  node_fertilizer_logic["Fertilizer inference<br/>[fertilizer.py]"]
  node_yield_logic["Yield inference<br/>[main.py]"]
  node_weather_logic["Weather retrieval<br/>[weather.py]"]
end

subgraph group_identity["Identity and access"]
  node_auth_logic["Account operations<br/>[auth.py]"]
  node_auth_guard["Token verification<br/>[jwt_handler.py]"]
  node_password_security["Password security<br/>[security.py]"]
end

subgraph group_data["Persistence"]
  node_db_session["Database sessions<br/>[database.py]"]
  node_records[("Users and predictions<br/>[models.py]")]
end

subgraph group_integrations["External services"]
  node_ml_artifacts["Trained ML models"]
  node_postgres[("PostgreSQL")]
  node_weather_service["Weather API"]
end

node_farmer(("Farmer"))

node_farmer -->|"uses"| node_react_app
node_react_app -->|"routes to"| node_crop_page
node_react_app -->|"routes to"| node_fertilizer_page
node_react_app -->|"routes to"| node_yield_page
node_react_app -->|"routes to"| node_weather_page
node_react_app -->|"routes to"| node_dashboard_page
node_react_app -->|"routes to"| node_history_page
node_crop_page -->|"posts request"| node_api
node_fertilizer_page -->|"requests prediction"| node_api
node_yield_page -->|"requests prediction"| node_api
node_weather_page -->|"requests weather"| node_api
node_dashboard_page -->|"requests summary"| node_api
node_history_page -->|"requests records"| node_api
node_api -->|"calls"| node_crop_logic
node_api -->|"calls"| node_fertilizer_logic
node_api -->|"predicts"| node_yield_logic
node_api -->|"calls"| node_weather_logic
node_api -->|"calls"| node_auth_logic
node_api -->|"verifies token"| node_auth_guard
node_auth_logic -->|"hashes passwords"| node_password_security
node_auth_logic -->|"creates token"| node_auth_guard
node_api -->|"opens sessions"| node_db_session
node_api -->|"reads and writes"| node_records
node_auth_logic -->|"stores accounts"| node_records
node_db_session -->|"connects"| node_postgres
node_crop_logic -.->|"uses model"| node_ml_artifacts
node_fertilizer_logic -->|"loads model"| node_ml_artifacts
node_yield_logic -->|"loads model"| node_ml_artifacts
node_weather_logic -.->|"retrieves weather"| node_weather_service

click node_react_app "https://github.com/keerthipandala/smartfarmerassistant/blob/main/frontend/src/App.js"
click node_crop_page "https://github.com/keerthipandala/smartfarmerassistant/blob/main/frontend/src/pages/Crop.jsx"
click node_fertilizer_page "https://github.com/keerthipandala/smartfarmerassistant/blob/main/frontend/src/pages/Fertilizer.jsx"
click node_yield_page "https://github.com/keerthipandala/smartfarmerassistant/blob/main/frontend/src/pages/Yield.jsx"
click node_weather_page "https://github.com/keerthipandala/smartfarmerassistant/blob/main/frontend/src/pages/Weather.jsx"
click node_dashboard_page "https://github.com/keerthipandala/smartfarmerassistant/blob/main/frontend/src/pages/Dashboard.jsx"
click node_history_page "https://github.com/keerthipandala/smartfarmerassistant/blob/main/frontend/src/pages/History.jsx"
click node_api "https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/main.py"
click node_crop_logic "https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/routes/crop.py"
click node_fertilizer_logic "https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/routes/fertilizer.py"
click node_yield_logic "https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/main.py"
click node_weather_logic "https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/routes/weather.py"
click node_auth_logic "https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/routes/auth.py"
click node_auth_guard "https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/jwt_handler.py"
click node_password_security "https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/security.py"
click node_db_session "https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/database.py"
click node_records "https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/models.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_react_app,node_crop_page,node_fertilizer_page,node_yield_page,node_weather_page,node_dashboard_page,node_history_page toneBlue
class node_api,node_crop_logic,node_fertilizer_logic,node_yield_logic,node_weather_logic toneAmber
class node_auth_logic,node_auth_guard,node_password_security toneMint
class node_db_session,node_records toneRose
class node_ml_artifacts,node_postgres,node_weather_service,node_farmer toneIndigo
```

## Components

### Farmer interface

- [React app routing](https://github.com/keerthipandala/smartfarmerassistant/blob/main/frontend/src/App.js): `frontend/src/App.js`
- [Crop recommendation](https://github.com/keerthipandala/smartfarmerassistant/blob/main/frontend/src/pages/Crop.jsx): `frontend/src/pages/Crop.jsx`
- [Fertilizer recommendation](https://github.com/keerthipandala/smartfarmerassistant/blob/main/frontend/src/pages/Fertilizer.jsx): `frontend/src/pages/Fertilizer.jsx`
- [Yield prediction](https://github.com/keerthipandala/smartfarmerassistant/blob/main/frontend/src/pages/Yield.jsx): `frontend/src/pages/Yield.jsx`
- [Weather lookup](https://github.com/keerthipandala/smartfarmerassistant/blob/main/frontend/src/pages/Weather.jsx): `frontend/src/pages/Weather.jsx`
- [Dashboard summary](https://github.com/keerthipandala/smartfarmerassistant/blob/main/frontend/src/pages/Dashboard.jsx): `frontend/src/pages/Dashboard.jsx`
- [Prediction history](https://github.com/keerthipandala/smartfarmerassistant/blob/main/frontend/src/pages/History.jsx): `frontend/src/pages/History.jsx`

### Prediction and API

- [FastAPI endpoints](https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/main.py): `backend/main.py`
- [Crop inference](https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/routes/crop.py): `backend/routes/crop.py`
- [Fertilizer inference](https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/routes/fertilizer.py): `backend/routes/fertilizer.py`
- [Yield inference](https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/main.py): `backend/main.py`
- [Weather retrieval](https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/routes/weather.py): `backend/routes/weather.py`

### Identity and access

- [Account operations](https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/routes/auth.py): `backend/routes/auth.py`
- [Token verification](https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/jwt_handler.py): `backend/jwt_handler.py`
- [Password security](https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/security.py): `backend/security.py`

### Persistence

- [Database sessions](https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/database.py): `backend/database.py`
- [Users and predictions](https://github.com/keerthipandala/smartfarmerassistant/blob/main/backend/models.py): `backend/models.py`

### External services

- **Trained ML models**
- **PostgreSQL**
- **Weather API**

### Other components

- **Farmer**

## Connections

- Farmer → React app routing: uses
- React app routing → Crop recommendation: routes to (evidence: `frontend/src/App.js`)
- React app routing → Fertilizer recommendation: routes to (evidence: `frontend/src/App.js`)
- React app routing → Yield prediction: routes to (evidence: `frontend/src/App.js`)
- React app routing → Weather lookup: routes to (evidence: `frontend/src/App.js`)
- React app routing → Dashboard summary: routes to (evidence: `frontend/src/App.js`)
- React app routing → Prediction history: routes to (evidence: `frontend/src/App.js`)
- Crop recommendation → FastAPI endpoints: posts request (evidence: `frontend/src/pages/Crop.jsx`)
- Fertilizer recommendation → FastAPI endpoints: requests prediction
- Yield prediction → FastAPI endpoints: requests prediction
- Weather lookup → FastAPI endpoints: requests weather
- Dashboard summary → FastAPI endpoints: requests summary
- Prediction history → FastAPI endpoints: requests records
- FastAPI endpoints → Crop inference: calls (evidence: `backend/main.py`)
- FastAPI endpoints → Fertilizer inference: calls (evidence: `backend/main.py`)
- FastAPI endpoints → Yield inference: predicts (evidence: `backend/main.py`)
- FastAPI endpoints → Weather retrieval: calls (evidence: `backend/main.py`)
- FastAPI endpoints → Account operations: calls (evidence: `backend/main.py`)
- FastAPI endpoints → Token verification: verifies token (evidence: `backend/main.py`)
- Account operations → Password security: hashes passwords (evidence: `backend/routes/auth.py`)
- Account operations → Token verification: creates token (evidence: `backend/routes/auth.py`)
- FastAPI endpoints → Database sessions: opens sessions (evidence: `backend/main.py`)
- FastAPI endpoints → Users and predictions: reads and writes (evidence: `backend/main.py`)
- Account operations → Users and predictions: stores accounts (evidence: `backend/routes/auth.py`)
- Database sessions → PostgreSQL: connects (evidence: `backend/database.py`)
- Crop inference → Trained ML models: uses model
- Fertilizer inference → Trained ML models: loads model (evidence: `backend/routes/fertilizer.py`)
- Yield inference → Trained ML models: loads model (evidence: `backend/main.py`)
- Weather retrieval → Weather API: retrieves weather
