# varshith385/agrisage-ai architecture

> Architecture diagram of the GitHub repository varshith385/agrisage-ai, 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/varshith385/agrisage-ai
- Repository: https://github.com/varshith385/agrisage-ai

## Overview

Grow2Gain is a farmer-facing smart-agriculture platform for farm management and decision support, including crop recommendations, disease detection, irrigation planning, yield/advisory analysis, economics, markets, calendars, and voice assistance. The main workflow is through the web app into versioned API routes; the backend’s agent orchestrator coordinates agricultural analyses and advisory output. The excerpts show selected routing, agent handoffs, authentication, and voice-service dependencies; other capability links reflect the README or remain unconnected where implementation evidence was not sampled.

Main entry points: [`frontend/src/App.tsx`](https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/App.tsx) (Routed web app), [`backend/app/database/session.py`](https://github.com/varshith385/agrisage-ai/blob/main/backend/app/database/session.py) (Database sessions), [`backend/app/models/farm.py`](https://github.com/varshith385/agrisage-ai/blob/main/backend/app/models/farm.py) (Farm records), [`backend/app/agents/orchestrator.py`](https://github.com/varshith385/agrisage-ai/blob/main/backend/app/agents/orchestrator.py) (Agent orchestrator)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Farmer web app"]
  node_webapp["Routed web app<br/>[App.tsx]"]
  node_authui["Authentication page<br/>[AuthPage.tsx]"]
  node_farmui["Farm registration"]
  node_dashboard["Farm dashboard<br/>[DashboardPage.tsx]"]
  node_cropui["Crop recommendations"]
  node_economicsui["Profit planning<br/>[EconomicsPage.tsx]"]
  node_marketui["Market information<br/>[MarketPage.tsx]"]
  node_authstate["Session and farm state<br/>[AuthContext.tsx]"]
  node_apitypes["Shared API types<br/>[api.ts]"]
end

subgraph group_api["API and identity"]
  node_apiapp["API application<br/>[main.py]"]
  node_routes["Versioned API routes"]
  node_authroute["Authentication routes<br/>[auth.py]"]
end

subgraph group_decision["Agricultural decision support"]
  node_orchestrator["Agent orchestrator<br/>[orchestrator.py]"]
  node_agenttypes["Agent contracts<br/>[schemas.py]"]
  node_domainagents["Agriculture agents"]
  node_ml["Agriculture models"]
end

subgraph group_services["Domain services"]
  node_economics["Economics calculation<br/>[economics.py]"]
  node_voice["Voice assistant service<br/>[voice_service.py]"]
  node_llm["LLM provider client<br/>[llm_client.py]"]
  node_economicschema["Economics schemas<br/>[economics.py]"]
end

subgraph group_persistence["Persistence"]
  node_config["Application settings<br/>[config.py]"]
  node_dbsession["Database sessions<br/>[session.py]"]
  node_farmmodel[("Farm records<br/>[farm.py]")]
  node_usermodel[("User records<br/>[user.py]")]
end

node_farmer(("Farmer"))

node_farmer -->|"uses"| node_webapp
node_webapp -->|"routes to"| node_authui
node_webapp -->|"routes to"| node_farmui
node_webapp -->|"routes to"| node_dashboard
node_webapp -->|"routes to"| node_cropui
node_webapp -->|"routes to"| node_economicsui
node_webapp -->|"routes to"| node_marketui
node_authstate -->|"fetches farm"| node_farmmodel
node_authroute -->|"queries and writes"| node_usermodel
node_authroute -->|"creates demo farm"| node_farmmodel
node_apiapp -->|"mounts routes"| node_routes
node_apiapp -->|"initializes"| node_dbsession
node_orchestrator -->|"runs agents"| node_domainagents
node_domainagents -->|"uses disease model"| node_ml
node_orchestrator -->|"calculates economics"| node_economics
node_orchestrator -->|"loads farm"| node_farmmodel
node_voice -->|"uses calculations"| node_economics
node_voice -->|"requests generation"| node_llm
node_voice -->|"uses irrigation model"| node_domainagents
node_economics -->|"uses schemas"| node_economicschema
node_dbsession -->|"reads settings"| node_config
node_dbsession -->|"registers model"| node_farmmodel
node_dbsession -->|"registers model"| node_usermodel
node_llm -->|"reads provider settings"| node_config

click node_webapp "https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/App.tsx"
click node_authui "https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/pages/AuthPage.tsx"
click node_farmui "https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/pages/FarmRegistrationPage.tsx"
click node_dashboard "https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/pages/DashboardPage.tsx"
click node_cropui "https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/pages/CropRecommendationPage.tsx"
click node_economicsui "https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/pages/EconomicsPage.tsx"
click node_marketui "https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/pages/MarketPage.tsx"
click node_authstate "https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/context/AuthContext.tsx"
click node_apitypes "https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/types/api.ts"
click node_apiapp "https://github.com/varshith385/agrisage-ai/blob/main/backend/app/main.py"
click node_routes "https://github.com/varshith385/agrisage-ai/tree/main/backend/app/api/v1"
click node_authroute "https://github.com/varshith385/agrisage-ai/blob/main/backend/app/api/v1/auth.py"
click node_orchestrator "https://github.com/varshith385/agrisage-ai/blob/main/backend/app/agents/orchestrator.py"
click node_agenttypes "https://github.com/varshith385/agrisage-ai/blob/main/backend/app/agents/schemas.py"
click node_domainagents "https://github.com/varshith385/agrisage-ai/tree/main/backend/app/agents"
click node_ml "https://github.com/varshith385/agrisage-ai/tree/main/backend/app/ml"
click node_economics "https://github.com/varshith385/agrisage-ai/blob/main/backend/app/services/economics.py"
click node_voice "https://github.com/varshith385/agrisage-ai/blob/main/backend/app/services/voice_service.py"
click node_llm "https://github.com/varshith385/agrisage-ai/blob/main/backend/app/services/llm_client.py"
click node_economicschema "https://github.com/varshith385/agrisage-ai/blob/main/backend/app/schemas/economics.py"
click node_config "https://github.com/varshith385/agrisage-ai/blob/main/backend/app/config.py"
click node_dbsession "https://github.com/varshith385/agrisage-ai/blob/main/backend/app/database/session.py"
click node_farmmodel "https://github.com/varshith385/agrisage-ai/blob/main/backend/app/models/farm.py"
click node_usermodel "https://github.com/varshith385/agrisage-ai/blob/main/backend/app/models/user.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_authui,node_farmui,node_dashboard,node_cropui,node_economicsui,node_marketui,node_authstate,node_apitypes toneBlue
class node_apiapp,node_routes,node_authroute toneAmber
class node_orchestrator,node_agenttypes,node_domainagents,node_ml toneMint
class node_economics,node_voice,node_llm,node_economicschema toneRose
class node_config,node_dbsession,node_farmmodel,node_usermodel,node_farmer toneIndigo
```

## Components

### Farmer web app

- [Routed web app](https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Authentication page](https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/pages/AuthPage.tsx): `frontend/src/pages/AuthPage.tsx`
- [Farm registration](https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/pages/FarmRegistrationPage.tsx): `frontend/src/pages/FarmRegistrationPage.tsx`
- [Farm dashboard](https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/pages/DashboardPage.tsx): `frontend/src/pages/DashboardPage.tsx`
- [Crop recommendations](https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/pages/CropRecommendationPage.tsx): `frontend/src/pages/CropRecommendationPage.tsx`
- [Profit planning](https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/pages/EconomicsPage.tsx): `frontend/src/pages/EconomicsPage.tsx`
- [Market information](https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/pages/MarketPage.tsx): `frontend/src/pages/MarketPage.tsx`
- [Session and farm state](https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/context/AuthContext.tsx): `frontend/src/context/AuthContext.tsx`
- [Shared API types](https://github.com/varshith385/agrisage-ai/blob/main/frontend/src/types/api.ts): `frontend/src/types/api.ts`

### API and identity

- [API application](https://github.com/varshith385/agrisage-ai/blob/main/backend/app/main.py): `backend/app/main.py`
- [Versioned API routes](https://github.com/varshith385/agrisage-ai/tree/main/backend/app/api/v1): `backend/app/api/v1`
- [Authentication routes](https://github.com/varshith385/agrisage-ai/blob/main/backend/app/api/v1/auth.py): `backend/app/api/v1/auth.py`

### Agricultural decision support

- [Agent orchestrator](https://github.com/varshith385/agrisage-ai/blob/main/backend/app/agents/orchestrator.py): `backend/app/agents/orchestrator.py`
- [Agent contracts](https://github.com/varshith385/agrisage-ai/blob/main/backend/app/agents/schemas.py): `backend/app/agents/schemas.py`
- [Agriculture agents](https://github.com/varshith385/agrisage-ai/tree/main/backend/app/agents): `backend/app/agents`
- [Agriculture models](https://github.com/varshith385/agrisage-ai/tree/main/backend/app/ml): `backend/app/ml`

### Domain services

- [Economics calculation](https://github.com/varshith385/agrisage-ai/blob/main/backend/app/services/economics.py): `backend/app/services/economics.py`
- [Voice assistant service](https://github.com/varshith385/agrisage-ai/blob/main/backend/app/services/voice_service.py): `backend/app/services/voice_service.py`
- [LLM provider client](https://github.com/varshith385/agrisage-ai/blob/main/backend/app/services/llm_client.py): `backend/app/services/llm_client.py`
- [Economics schemas](https://github.com/varshith385/agrisage-ai/blob/main/backend/app/schemas/economics.py): `backend/app/schemas/economics.py`

### Persistence

- [Application settings](https://github.com/varshith385/agrisage-ai/blob/main/backend/app/config.py): `backend/app/config.py`
- [Database sessions](https://github.com/varshith385/agrisage-ai/blob/main/backend/app/database/session.py): `backend/app/database/session.py`
- [Farm records](https://github.com/varshith385/agrisage-ai/blob/main/backend/app/models/farm.py): `backend/app/models/farm.py`
- [User records](https://github.com/varshith385/agrisage-ai/blob/main/backend/app/models/user.py): `backend/app/models/user.py`

### Other components

- **Farmer**

## Connections

- Farmer → Routed web app: uses
- Routed web app → Authentication page: routes to (evidence: `frontend/src/App.tsx`)
- Routed web app → Farm registration: routes to (evidence: `frontend/src/App.tsx`)
- Routed web app → Farm dashboard: routes to (evidence: `frontend/src/App.tsx`)
- Routed web app → Crop recommendations: routes to (evidence: `frontend/src/App.tsx`)
- Routed web app → Profit planning: routes to (evidence: `frontend/src/App.tsx`)
- Routed web app → Market information: routes to (evidence: `frontend/src/App.tsx`)
- Session and farm state → Farm records: fetches farm (evidence: `frontend/src/context/AuthContext.tsx`)
- Authentication routes → User records: queries and writes (evidence: `backend/app/api/v1/auth.py`)
- Authentication routes → Farm records: creates demo farm (evidence: `backend/app/api/v1/auth.py`)
- API application → Versioned API routes: mounts routes (evidence: `backend/app/main.py`)
- API application → Database sessions: initializes (evidence: `backend/app/main.py`)
- Agent orchestrator → Agriculture agents: runs agents (evidence: `backend/app/agents/orchestrator.py`)
- Agriculture agents → Agriculture models: uses disease model (evidence: `backend/app/agents/disease_agent.py`)
- Agent orchestrator → Economics calculation: calculates economics (evidence: `backend/app/agents/orchestrator.py`)
- Agent orchestrator → Farm records: loads farm (evidence: `backend/app/agents/orchestrator.py`)
- Voice assistant service → Economics calculation: uses calculations (evidence: `backend/app/services/voice_service.py`)
- Voice assistant service → LLM provider client: requests generation (evidence: `backend/app/services/voice_service.py`)
- Voice assistant service → Agriculture agents: uses irrigation model (evidence: `backend/app/services/voice_service.py`)
- Economics calculation → Economics schemas: uses schemas (evidence: `backend/app/services/economics.py`)
- Database sessions → Application settings: reads settings (evidence: `backend/app/database/session.py`)
- Database sessions → Farm records: registers model (evidence: `backend/app/database/session.py`)
- Database sessions → User records: registers model (evidence: `backend/app/database/session.py`)
- LLM provider client → Application settings: reads provider settings (evidence: `backend/app/services/llm_client.py`)
