# dinraj910/smart-farming-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/dinraj910/smart-farming-assistant
- Repository: https://github.com/dinraj910/smart-farming-assistant

## Overview

NatureSync is a Kerala-focused precision-agriculture mobile app backed by a FastAPI service. Farmers sign in, manage field profiles, and use those details for AI advice; separate app flows provide crop recommendations, leaf-disease diagnosis, weather, and market intelligence. The sampled source confirms app navigation, authentication requests, backend router registration, and the agent’s tool dispatch. Several product screens and API handlers were not sampled, so their relationships are shown only where the README documents them; database and third-party integrations are likewise represented at the documented level.

Main entry points: [`backend/main.py`](https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/main.py) (FastAPI gateway), [`mobile/src/navigation/MainTabNavigator.tsx`](https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/navigation/MainTabNavigator.tsx) (Feature tabs), [`backend/app/agent/orchestrator.py`](https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/agent/orchestrator.py) (Agent orchestrator), [`mobile/App.tsx`](https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/App.tsx) (App navigation)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_mobile["Mobile experience"]
  node_app["App navigation<br/>[App.tsx]"]
  node_tabs["Feature tabs"]
  node_farms_ui["Farm management<br/>[FarmsScreen.tsx]"]
  node_field_ui["Field details"]
  node_chat_ui["AI chat"]
  node_crop_ui["Crop advice<br/>[HomeScreen.tsx]"]
  node_doctor_ui["Leaf Doctor"]
  node_weather_ui["Weather view<br/>[WeatherScreen.tsx]"]
  node_market_ui["Market view<br/>[MarketScreen.tsx]"]
  node_api_client["API client<br/>[client.ts]"]
end

subgraph group_api["Backend API"]
  node_gateway["FastAPI gateway<br/>[main.py]"]
  node_auth_api["Authentication API<br/>[auth.py]"]
  node_farm_api["Farm API<br/>[farm.py]"]
  node_crop_api["Crop API<br/>[crop.py]"]
  node_disease_api["Disease API<br/>[disease.py]"]
  node_market_api["Market API<br/>[market.py]"]
  node_agent_api["Agent API<br/>[agent.py]"]
end

subgraph group_intelligence["Agricultural intelligence"]
  node_orchestrator["Agent orchestrator<br/>[orchestrator.py]"]
  node_memory["Conversation memory<br/>[memory.py]"]
  node_crop_model["Crop classifier<br/>[crop_model.py]"]
  node_agent_tools["Agronomy tools"]
  node_kau_search["KAU knowledge search<br/>[kau_search_tool.py]"]
  node_embed["Query embeddings<br/>[embed_utils.py]"]
end

subgraph group_identity["Identity and state"]
  node_auth_state["Auth state<br/>[authStore.ts]"]
  node_security["Password and tokens<br/>[security.py]"]
end

node_farmer(("Farmer"))
node_vector_store[("KAU vector store")]
node_weather_service["Weather data service"]
node_market_service["Agmarknet"]
node_vision_service["Disease classifier"]

node_farmer -->|"uses"| node_app
node_app -->|"checks sign-in"| node_auth_state
node_app -->|"opens"| node_tabs
node_tabs -->|"routes to"| node_farms_ui
node_tabs -->|"routes to"| node_chat_ui
node_tabs -->|"routes to"| node_crop_ui
node_tabs -->|"routes to"| node_doctor_ui
node_tabs -->|"routes to"| node_weather_ui
node_tabs -->|"routes to"| node_market_ui
node_farms_ui -.->|"opens field"| node_field_ui
node_auth_state -->|"sends auth requests"| node_api_client
node_api_client -->|"calls REST API"| node_gateway
node_gateway -->|"mounts"| node_auth_api
node_gateway -->|"mounts"| node_farm_api
node_gateway -->|"mounts"| node_crop_api
node_gateway -->|"mounts"| node_disease_api
node_gateway -->|"mounts"| node_market_api
node_gateway -->|"mounts"| node_agent_api
node_auth_api -->|"uses"| node_security
node_gateway -->|"loads model"| node_crop_model
node_agent_api -->|"invokes"| node_orchestrator
node_orchestrator -->|"uses"| node_memory
node_orchestrator -->|"dispatches tools"| node_agent_tools
node_orchestrator -->|"dispatches search"| node_kau_search
node_kau_search -->|"embeds query"| node_embed
node_kau_search -->|"queries vectors"| node_vector_store
node_agent_tools -.->|"fetches forecasts"| node_weather_service
node_agent_tools -.->|"fetches prices"| node_market_service
node_disease_api -.->|"classifies image"| node_vision_service
node_market_api -.->|"fetches mandi rates"| node_market_service

click node_app "https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/App.tsx"
click node_tabs "https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/navigation/MainTabNavigator.tsx"
click node_farms_ui "https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/screens/FarmsScreen.tsx"
click node_field_ui "https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/screens/FieldDetailScreen.tsx"
click node_chat_ui "https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/screens/AgentChatScreen.tsx"
click node_crop_ui "https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/screens/HomeScreen.tsx"
click node_doctor_ui "https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/screens/LeafDoctorScreen.tsx"
click node_weather_ui "https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/screens/WeatherScreen.tsx"
click node_market_ui "https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/screens/MarketScreen.tsx"
click node_api_client "https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/api/client.ts"
click node_auth_state "https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/store/authStore.ts"
click node_gateway "https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/main.py"
click node_auth_api "https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/routers/auth.py"
click node_farm_api "https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/routers/farm.py"
click node_crop_api "https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/routers/crop.py"
click node_disease_api "https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/routers/disease.py"
click node_market_api "https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/routers/market.py"
click node_agent_api "https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/routers/agent.py"
click node_security "https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/auth/security.py"
click node_orchestrator "https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/agent/orchestrator.py"
click node_memory "https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/agent/memory.py"
click node_crop_model "https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/ml/crop_model.py"
click node_agent_tools "https://github.com/dinraj910/smart-farming-assistant/tree/main/backend/app/agent/tools"
click node_kau_search "https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/agent/tools/kau_search_tool.py"
click node_embed "https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/rag/embed_utils.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_tabs,node_farms_ui,node_field_ui,node_chat_ui,node_crop_ui,node_doctor_ui,node_weather_ui,node_market_ui,node_api_client toneBlue
class node_gateway,node_auth_api,node_farm_api,node_crop_api,node_disease_api,node_market_api,node_agent_api,node_vector_store toneAmber
class node_orchestrator,node_memory,node_crop_model,node_agent_tools,node_kau_search,node_embed toneMint
class node_auth_state,node_security toneRose
class node_farmer,node_weather_service,node_market_service,node_vision_service toneIndigo
```

## Components

### Mobile experience

- [App navigation](https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/App.tsx): `mobile/App.tsx`
- [Feature tabs](https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/navigation/MainTabNavigator.tsx): `mobile/src/navigation/MainTabNavigator.tsx`
- [Farm management](https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/screens/FarmsScreen.tsx): `mobile/src/screens/FarmsScreen.tsx`
- [Field details](https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/screens/FieldDetailScreen.tsx): `mobile/src/screens/FieldDetailScreen.tsx`
- [AI chat](https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/screens/AgentChatScreen.tsx): `mobile/src/screens/AgentChatScreen.tsx`
- [Crop advice](https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/screens/HomeScreen.tsx): `mobile/src/screens/HomeScreen.tsx`
- [Leaf Doctor](https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/screens/LeafDoctorScreen.tsx): `mobile/src/screens/LeafDoctorScreen.tsx`
- [Weather view](https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/screens/WeatherScreen.tsx): `mobile/src/screens/WeatherScreen.tsx`
- [Market view](https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/screens/MarketScreen.tsx): `mobile/src/screens/MarketScreen.tsx`
- [API client](https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/api/client.ts): `mobile/src/api/client.ts`

### Backend API

- [FastAPI gateway](https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/main.py): `backend/main.py`
- [Authentication API](https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/routers/auth.py): `backend/app/routers/auth.py`
- [Farm API](https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/routers/farm.py): `backend/app/routers/farm.py`
- [Crop API](https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/routers/crop.py): `backend/app/routers/crop.py`
- [Disease API](https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/routers/disease.py): `backend/app/routers/disease.py`
- [Market API](https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/routers/market.py): `backend/app/routers/market.py`
- [Agent API](https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/routers/agent.py): `backend/app/routers/agent.py`

### Agricultural intelligence

- [Agent orchestrator](https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/agent/orchestrator.py): `backend/app/agent/orchestrator.py`
- [Conversation memory](https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/agent/memory.py): `backend/app/agent/memory.py`
- [Crop classifier](https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/ml/crop_model.py): `backend/app/ml/crop_model.py`
- [Agronomy tools](https://github.com/dinraj910/smart-farming-assistant/tree/main/backend/app/agent/tools): `backend/app/agent/tools`
- [KAU knowledge search](https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/agent/tools/kau_search_tool.py): `backend/app/agent/tools/kau_search_tool.py`
- [Query embeddings](https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/rag/embed_utils.py): `backend/app/rag/embed_utils.py`

### Identity and state

- [Auth state](https://github.com/dinraj910/smart-farming-assistant/blob/main/mobile/src/store/authStore.ts): `mobile/src/store/authStore.ts`
- [Password and tokens](https://github.com/dinraj910/smart-farming-assistant/blob/main/backend/app/auth/security.py): `backend/app/auth/security.py`

### Other components

- **Farmer**
- **KAU vector store**
- **Weather data service**
- **Agmarknet**
- **Disease classifier**

## Connections

- Farmer → App navigation: uses
- App navigation → Auth state: checks sign-in (evidence: `mobile/App.tsx`)
- App navigation → Feature tabs: opens (evidence: `mobile/App.tsx`)
- Feature tabs → Farm management: routes to (evidence: `mobile/src/navigation/MainTabNavigator.tsx`)
- Feature tabs → AI chat: routes to (evidence: `mobile/src/navigation/MainTabNavigator.tsx`)
- Feature tabs → Crop advice: routes to (evidence: `mobile/src/navigation/MainTabNavigator.tsx`)
- Feature tabs → Leaf Doctor: routes to (evidence: `mobile/src/navigation/MainTabNavigator.tsx`)
- Feature tabs → Weather view: routes to (evidence: `mobile/src/navigation/MainTabNavigator.tsx`)
- Feature tabs → Market view: routes to (evidence: `mobile/src/navigation/MainTabNavigator.tsx`)
- Farm management → Field details: opens field
- Auth state → API client: sends auth requests (evidence: `mobile/src/store/authStore.ts`)
- API client → FastAPI gateway: calls REST API
- FastAPI gateway → Authentication API: mounts (evidence: `backend/main.py`)
- FastAPI gateway → Farm API: mounts (evidence: `backend/main.py`)
- FastAPI gateway → Crop API: mounts (evidence: `backend/main.py`)
- FastAPI gateway → Disease API: mounts (evidence: `backend/main.py`)
- FastAPI gateway → Market API: mounts (evidence: `backend/main.py`)
- FastAPI gateway → Agent API: mounts (evidence: `backend/main.py`)
- Authentication API → Password and tokens: uses (evidence: `backend/app/routers/auth.py`)
- FastAPI gateway → Crop classifier: loads model (evidence: `backend/main.py`)
- Agent API → Agent orchestrator: invokes (evidence: `backend/app/routers/agent.py`)
- Agent orchestrator → Conversation memory: uses (evidence: `backend/app/agent/orchestrator.py`)
- Agent orchestrator → Agronomy tools: dispatches tools (evidence: `backend/app/agent/orchestrator.py`)
- Agent orchestrator → KAU knowledge search: dispatches search (evidence: `backend/app/agent/orchestrator.py`)
- KAU knowledge search → Query embeddings: embeds query (evidence: `backend/app/agent/tools/kau_search_tool.py`)
- KAU knowledge search → KAU vector store: queries vectors (evidence: `backend/app/agent/tools/kau_search_tool.py`)
- Agronomy tools → Weather data service: fetches forecasts
- Agronomy tools → Agmarknet: fetches prices
- Disease API → Disease classifier: classifies image
- Market API → Agmarknet: fetches mandi rates
