# ugeshraja/smart-farming-ai architecture

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

- Interactive diagram: https://gitdiagram.com/ugeshraja/smart-farming-ai
- Repository: https://github.com/ugeshraja/smart-farming-ai

## Overview

SmartFarm AI serves farmers through a React application and FastAPI gateway. Its main flows are crop-image diagnosis (localize, segment, classify, explain, then advise), text/voice agronomic assistance, and weather-informed planning. The repository also documents field evaluation, community, library, and government-scheme capabilities. Edges reflect shown imports/calls or README-documented flows; several feature implementations were not sampled, so their internal links are omitted or marked unverified.

Main entry points: [`src/App.jsx`](https://github.com/ugeshraja/smart-farming-ai/blob/main/src/App.jsx) (Web app and routes), [`backend/main.py`](https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/main.py) (FastAPI gateway), [`src/services/apiService.js`](https://github.com/ugeshraja/smart-farming-ai/blob/main/src/services/apiService.js) (API client), [`src/context/AuthContext.jsx`](https://github.com/ugeshraja/smart-farming-ai/blob/main/src/context/AuthContext.jsx) (Authentication state)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Farmer application"]
  node_webapp["Web app and routes<br/>[App.jsx]"]
  node_auth["Authentication state<br/>[AuthContext.jsx]"]
  node_weatherui["Weather context<br/>[WeatherContext.jsx]"]
  node_diagnosisui["Disease detection"]
  node_assistantui["Farmer assistant"]
  node_planner["Planner and field<br/>[Planner.jsx]"]
  node_otherfeatures["Community, library, schemes"]
  node_api_client["API client<br/>[apiService.js]"]
  node_weather_client["Weather service<br/>[weatherService.js]"]
end

subgraph group_gateway["API gateway"]
  node_fastapi["FastAPI gateway<br/>[main.py]"]
  node_predict_route["Prediction route<br/>[predict.py]"]
  node_chat_route["Chat route<br/>[chat.py]"]
  node_voice_route["Voice route<br/>[voice.py]"]
  node_weather_route["Weather route<br/>[weather.py]"]
  node_other_routes["Other API routes"]
end

subgraph group_intelligence["Agricultural intelligence"]
  node_vision["Vision and explainability pipeline"]
  node_rag["Agricultural knowledge retrieval<br/>[rag_service.py]"]
  node_fieldeval["Field suitability evaluator<br/>[fieldEvaluator.js]"]
  node_schemes["Scheme and library services"]
end

subgraph group_accounts["Accounts and data"]
  node_authservice["Authentication service"]
  node_dbsession["Database sessions<br/>[session.py]"]
  node_dbconnection["Database connection<br/>[connection.py]"]
end

subgraph group_integrations["External services"]
  node_supabase[("Supabase Auth and database")]
  node_gemini["Gemini language model"]
  node_openweather["OpenWeather"]
  node_voice_engine["Speech and TTS services<br/>[tts_service.py]"]
end

node_farmer(("Farmer"))

node_farmer -->|"uses"| node_webapp
node_webapp -->|"routes to"| node_diagnosisui
node_webapp -->|"routes to"| node_assistantui
node_webapp -->|"routes to"| node_planner
node_webapp -->|"routes to"| node_otherfeatures
node_webapp -->|"provides state"| node_auth
node_webapp -->|"provides state"| node_weatherui
node_diagnosisui -.->|"requests diagnosis"| node_api_client
node_assistantui -.->|"sends queries"| node_api_client
node_planner -->|"requests data"| node_api_client
node_api_client -.->|"calls API"| node_fastapi
node_weatherui -->|"uses"| node_weather_client
node_api_client -->|"fetches weather"| node_weather_client
node_weather_client -->|"requests forecasts"| node_openweather
node_fastapi -->|"registers"| node_predict_route
node_fastapi -->|"registers"| node_chat_route
node_fastapi -->|"registers"| node_voice_route
node_fastapi -->|"registers"| node_weather_route
node_fastapi -->|"registers"| node_other_routes
node_predict_route -.->|"invokes"| node_vision
node_vision -->|"retrieves context"| node_rag
node_chat_route -->|"retrieves context"| node_rag
node_chat_route -.->|"generates advice"| node_gemini
node_vision -.->|"generates advisory"| node_gemini
node_weather_route -.->|"fetches weather"| node_openweather
node_voice_route -.->|"handles speech"| node_voice_engine
node_auth -->|"authenticates"| node_supabase
node_auth -->|"evaluates field"| node_fieldeval
node_other_routes -->|"uses identity service"| node_authservice
node_authservice -->|"queries database"| node_dbconnection
node_dbsession -->|"gets engine"| node_dbconnection
node_authservice -->|"verifies and persists users"| node_supabase
node_otherfeatures -.->|"presents resources"| node_schemes
node_planner -.->|"evaluates suitability"| node_fieldeval

click node_webapp "https://github.com/ugeshraja/smart-farming-ai/blob/main/src/App.jsx"
click node_auth "https://github.com/ugeshraja/smart-farming-ai/blob/main/src/context/AuthContext.jsx"
click node_weatherui "https://github.com/ugeshraja/smart-farming-ai/blob/main/src/context/WeatherContext.jsx"
click node_diagnosisui "https://github.com/ugeshraja/smart-farming-ai/blob/main/src/pages/DiseaseDetection.jsx"
click node_assistantui "https://github.com/ugeshraja/smart-farming-ai/blob/main/src/pages/FarmerAssistant.jsx"
click node_planner "https://github.com/ugeshraja/smart-farming-ai/blob/main/src/pages/Planner.jsx"
click node_otherfeatures "https://github.com/ugeshraja/smart-farming-ai/tree/main/src/pages"
click node_api_client "https://github.com/ugeshraja/smart-farming-ai/blob/main/src/services/apiService.js"
click node_weather_client "https://github.com/ugeshraja/smart-farming-ai/blob/main/src/services/weatherService.js"
click node_fastapi "https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/main.py"
click node_predict_route "https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/routes/predict.py"
click node_chat_route "https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/routes/chat.py"
click node_voice_route "https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/routes/voice.py"
click node_weather_route "https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/routes/weather.py"
click node_other_routes "https://github.com/ugeshraja/smart-farming-ai/tree/main/backend/routes"
click node_vision "https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/services/ai_pipeline_service.py"
click node_rag "https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/services/rag_service.py"
click node_fieldeval "https://github.com/ugeshraja/smart-farming-ai/blob/main/src/services/fieldEvaluator.js"
click node_schemes "https://github.com/ugeshraja/smart-farming-ai/tree/main/backend/services"
click node_authservice "https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/services/supabase_auth_service.py"
click node_dbsession "https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/database/session.py"
click node_dbconnection "https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/database/connection.py"
click node_voice_engine "https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/services/tts_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_webapp,node_auth,node_weatherui,node_diagnosisui,node_assistantui,node_planner,node_otherfeatures,node_api_client,node_weather_client toneBlue
class node_fastapi,node_predict_route,node_chat_route,node_voice_route,node_weather_route,node_other_routes toneAmber
class node_vision,node_rag,node_fieldeval,node_schemes toneMint
class node_authservice,node_dbsession,node_dbconnection toneRose
class node_supabase,node_gemini,node_openweather,node_voice_engine,node_farmer toneIndigo
```

## Components

### Farmer application

- [Web app and routes](https://github.com/ugeshraja/smart-farming-ai/blob/main/src/App.jsx): `src/App.jsx`
- [Authentication state](https://github.com/ugeshraja/smart-farming-ai/blob/main/src/context/AuthContext.jsx): `src/context/AuthContext.jsx`
- [Weather context](https://github.com/ugeshraja/smart-farming-ai/blob/main/src/context/WeatherContext.jsx): `src/context/WeatherContext.jsx`
- [Disease detection](https://github.com/ugeshraja/smart-farming-ai/blob/main/src/pages/DiseaseDetection.jsx): `src/pages/DiseaseDetection.jsx`
- [Farmer assistant](https://github.com/ugeshraja/smart-farming-ai/blob/main/src/pages/FarmerAssistant.jsx): `src/pages/FarmerAssistant.jsx`
- [Planner and field](https://github.com/ugeshraja/smart-farming-ai/blob/main/src/pages/Planner.jsx): `src/pages/Planner.jsx`
- [Community, library, schemes](https://github.com/ugeshraja/smart-farming-ai/tree/main/src/pages): `src/pages`
- [API client](https://github.com/ugeshraja/smart-farming-ai/blob/main/src/services/apiService.js): `src/services/apiService.js`
- [Weather service](https://github.com/ugeshraja/smart-farming-ai/blob/main/src/services/weatherService.js): `src/services/weatherService.js`

### API gateway

- [FastAPI gateway](https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/main.py): `backend/main.py`
- [Prediction route](https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/routes/predict.py): `backend/routes/predict.py`
- [Chat route](https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/routes/chat.py): `backend/routes/chat.py`
- [Voice route](https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/routes/voice.py): `backend/routes/voice.py`
- [Weather route](https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/routes/weather.py): `backend/routes/weather.py`
- [Other API routes](https://github.com/ugeshraja/smart-farming-ai/tree/main/backend/routes): `backend/routes`

### Agricultural intelligence

- [Vision and explainability pipeline](https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/services/ai_pipeline_service.py): `backend/services/ai_pipeline_service.py`
- [Agricultural knowledge retrieval](https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/services/rag_service.py): `backend/services/rag_service.py`
- [Field suitability evaluator](https://github.com/ugeshraja/smart-farming-ai/blob/main/src/services/fieldEvaluator.js): `src/services/fieldEvaluator.js`
- [Scheme and library services](https://github.com/ugeshraja/smart-farming-ai/tree/main/backend/services): `backend/services`

### Accounts and data

- [Authentication service](https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/services/supabase_auth_service.py): `backend/services/supabase_auth_service.py`
- [Database sessions](https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/database/session.py): `backend/database/session.py`
- [Database connection](https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/database/connection.py): `backend/database/connection.py`

### External services

- **Supabase Auth and database**
- **Gemini language model**
- **OpenWeather**
- [Speech and TTS services](https://github.com/ugeshraja/smart-farming-ai/blob/main/backend/services/tts_service.py): `backend/services/tts_service.py`

### Other components

- **Farmer**

## Connections

- Farmer → Web app and routes: uses (evidence: `README.md`)
- Web app and routes → Disease detection: routes to (evidence: `src/App.jsx`)
- Web app and routes → Farmer assistant: routes to (evidence: `src/App.jsx`)
- Web app and routes → Planner and field: routes to (evidence: `src/App.jsx`)
- Web app and routes → Community, library, schemes: routes to (evidence: `src/App.jsx`)
- Web app and routes → Authentication state: provides state (evidence: `src/App.jsx`)
- Web app and routes → Weather context: provides state (evidence: `src/App.jsx`)
- Disease detection → API client: requests diagnosis
- Farmer assistant → API client: sends queries
- Planner and field → API client: requests data (evidence: `src/pages/Planner.jsx`)
- API client → FastAPI gateway: calls API
- Weather context → Weather service: uses (evidence: `src/context/WeatherContext.jsx`)
- API client → Weather service: fetches weather (evidence: `src/services/apiService.js`)
- Weather service → OpenWeather: requests forecasts (evidence: `src/services/weatherService.js`)
- FastAPI gateway → Prediction route: registers (evidence: `backend/main.py`)
- FastAPI gateway → Chat route: registers (evidence: `backend/main.py`)
- FastAPI gateway → Voice route: registers (evidence: `backend/main.py`)
- FastAPI gateway → Weather route: registers (evidence: `backend/main.py`)
- FastAPI gateway → Other API routes: registers (evidence: `backend/main.py`)
- Prediction route → Vision and explainability pipeline: invokes
- Vision and explainability pipeline → Agricultural knowledge retrieval: retrieves context (evidence: `backend/services/ai_pipeline_service.py`)
- Chat route → Agricultural knowledge retrieval: retrieves context (evidence: `backend/routes/chat.py`)
- Chat route → Gemini language model: generates advice
- Vision and explainability pipeline → Gemini language model: generates advisory
- Weather route → OpenWeather: fetches weather
- Voice route → Speech and TTS services: handles speech
- Authentication state → Supabase Auth and database: authenticates
- Authentication state → Field suitability evaluator: evaluates field (evidence: `src/context/AuthContext.jsx`)
- Other API routes → Authentication service: uses identity service (evidence: `backend/routes/auth.py`)
- Authentication service → Database connection: queries database (evidence: `backend/services/supabase_auth_service.py`)
- Database sessions → Database connection: gets engine (evidence: `backend/database/session.py`)
- Authentication service → Supabase Auth and database: verifies and persists users (evidence: `backend/services/supabase_auth_service.py`)
- Community, library, schemes → Scheme and library services: presents resources
- Planner and field → Field suitability evaluator: evaluates suitability
