# chethu-1004/agri-mithra architecture

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

- Interactive diagram: https://gitdiagram.com/chethu-1004/agri-mithra
- Repository: https://github.com/chethu-1004/agri-mithra

## Overview

Agri Mitra is a farmer-facing agriculture API with a small JavaScript frontend. The principal workflow is an authenticated farmer submitting a crop image, receiving a disease or species assessment and recommendations, and retaining scan history. Other major branches cover accounts, farm and crop records, marketplace, weather notifications, and agricultural chat. The graph follows visible router registration and source-index references; unsampled routes and service internals are represented at module level, without asserting unshown call sequences.

Main entry points: [`backend/backend/main.py`](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/main.py) (API application), [`backend/backend/agrinetra/database/models.py`](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/database/models.py) (Domain records), [`backend/backend/agrinetra/api/disease_routes.py`](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/disease_routes.py) (Disease scan routes), [`backend/backend/agrinetra/api/species_routes.py`](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/species_routes.py) (Species scan routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API entry and identity"]
  node_app["API application<br/>[main.py]"]
  node_accounts["Account routes<br/>[auth_routes.py]"]
  node_auth["Token authorization<br/>[dependencies.py]"]
end

subgraph group_farm["Farm and crop intelligence"]
  node_farms["Farm and crop routes"]
  node_disease["Disease scan routes<br/>[disease_routes.py]"]
  node_species["Species scan routes<br/>[species_routes.py]"]
  node_disease_model["Disease predictor<br/>[model_loader.py]"]
  node_species_model["Species predictor<br/>[predictor.py]"]
  node_plant_analysis["Plant analysis<br/>[plant_analysis.py]"]
  node_recommendations["Treatment recommendations<br/>[recommendations.py]"]
end

subgraph group_engagement["Farmer services"]
  node_weather["Weather notifications"]
  node_market["Marketplace routes<br/>[market_routes.py]"]
  node_admin["Administration routes<br/>[admin_routes.py]"]
  node_ai_routes["AI routes<br/>[ai_routes.py]"]
  node_weather_service["Weather service<br/>[weather.py]"]
end

subgraph group_data["Persistence and files"]
  node_db_session["Database sessions<br/>[connection.py]"]
  node_models[("Domain records<br/>[models.py]")]
  node_storage["Image storage<br/>[service.py]"]
end

subgraph group_ai["Chat and knowledge"]
  node_chat["Chat routes<br/>[chat_routes.py]"]
  node_chat_context["Farmer chat context<br/>[chat_context.py]"]
  node_chatbot["Chatbot service<br/>[chatbot.py]"]
  node_ollama["Ollama chatbot<br/>[ollama_chatbot.py]"]
  node_knowledge["Agriculture knowledge<br/>[knowledge_base.py]"]
end

node_farmer(("Farmer"))

node_farmer -->|"uses API"| node_app
node_app -->|"registers router"| node_accounts
node_app -->|"registers router"| node_farms
node_app -->|"registers router"| node_disease
node_app -->|"registers router"| node_species
node_app -->|"registers router"| node_weather
node_app -->|"registers router"| node_chat
node_app -->|"registers router"| node_admin
node_app -->|"registers router"| node_market
node_app -->|"registers router"| node_ai_routes
node_accounts -->|"queries via"| node_db_session
node_accounts -->|"reads and writes"| node_models
node_accounts -->|"uses token checks"| node_auth
node_farms -->|"queries via"| node_db_session
node_farms -->|"reads and writes"| node_models
node_disease -->|"queries via"| node_db_session
node_disease -->|"stores scan"| node_models
node_disease -->|"saves image"| node_storage
node_disease -->|"predicts image"| node_disease_model
node_disease -->|"gets recommendation"| node_recommendations
node_disease -->|"builds analysis"| node_plant_analysis
node_species -->|"predicts image"| node_species_model
node_species -->|"checks disease"| node_disease_model
node_species -->|"builds analysis"| node_plant_analysis
node_species -->|"saves image"| node_storage
node_species -->|"stores scan"| node_models
node_weather -->|"gets forecasts"| node_weather_service
node_weather -->|"reads and writes"| node_models
node_market -->|"reads and writes"| node_models
node_admin -->|"manages records"| node_models
node_admin -->|"uses image storage"| node_storage
node_chat -->|"builds context"| node_chat_context
node_chat -->|"requests reply"| node_chatbot
node_chat -->|"retrieves evidence"| node_knowledge
node_chat -->|"reads and writes"| node_models
node_chat_context -->|"reads records"| node_models
node_chatbot -->|"delegates to"| node_ollama
node_auth -->|"checks revocation"| node_db_session
node_auth -->|"loads account"| node_models

click node_app "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/main.py"
click node_accounts "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/auth_routes.py"
click node_auth "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/auth/dependencies.py"
click node_farms "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/farm_crop_routes.py"
click node_disease "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/disease_routes.py"
click node_species "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/species_routes.py"
click node_disease_model "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/disease_detection/model_loader.py"
click node_species_model "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/species_detection/predictor.py"
click node_plant_analysis "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/services/plant_analysis.py"
click node_recommendations "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/disease_detection/recommendations.py"
click node_weather "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/weather_notification_routes.py"
click node_market "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/market_routes.py"
click node_admin "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/admin_routes.py"
click node_ai_routes "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/ai_routes.py"
click node_weather_service "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/services/weather.py"
click node_chat "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/chat_routes.py"
click node_chat_context "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/services/chat_context.py"
click node_chatbot "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/services/chatbot.py"
click node_ollama "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/services/ollama_chatbot.py"
click node_knowledge "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/services/knowledge_base.py"
click node_db_session "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/database/connection.py"
click node_models "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/database/models.py"
click node_storage "https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/storage/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_app,node_accounts,node_auth toneBlue
class node_farms,node_disease,node_species,node_disease_model,node_species_model,node_plant_analysis,node_recommendations toneAmber
class node_weather,node_market,node_admin,node_ai_routes,node_weather_service toneMint
class node_db_session,node_models,node_storage toneRose
class node_chat,node_chat_context,node_chatbot,node_ollama,node_knowledge,node_farmer toneIndigo
```

## Components

### API entry and identity

- [API application](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/main.py): `backend/backend/main.py`
- [Account routes](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/auth_routes.py): `backend/backend/agrinetra/api/auth_routes.py`
- [Token authorization](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/auth/dependencies.py): `backend/backend/agrinetra/auth/dependencies.py`

### Farm and crop intelligence

- [Farm and crop routes](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/farm_crop_routes.py): `backend/backend/agrinetra/api/farm_crop_routes.py`
- [Disease scan routes](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/disease_routes.py): `backend/backend/agrinetra/api/disease_routes.py`
- [Species scan routes](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/species_routes.py): `backend/backend/agrinetra/api/species_routes.py`
- [Disease predictor](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/disease_detection/model_loader.py): `backend/backend/agrinetra/disease_detection/model_loader.py`
- [Species predictor](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/species_detection/predictor.py): `backend/backend/agrinetra/species_detection/predictor.py`
- [Plant analysis](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/services/plant_analysis.py): `backend/backend/agrinetra/services/plant_analysis.py`
- [Treatment recommendations](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/disease_detection/recommendations.py): `backend/backend/agrinetra/disease_detection/recommendations.py`

### Farmer services

- [Weather notifications](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/weather_notification_routes.py): `backend/backend/agrinetra/api/weather_notification_routes.py`
- [Marketplace routes](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/market_routes.py): `backend/backend/agrinetra/api/market_routes.py`
- [Administration routes](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/admin_routes.py): `backend/backend/agrinetra/api/admin_routes.py`
- [AI routes](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/ai_routes.py): `backend/backend/agrinetra/api/ai_routes.py`
- [Weather service](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/services/weather.py): `backend/backend/agrinetra/services/weather.py`

### Persistence and files

- [Database sessions](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/database/connection.py): `backend/backend/agrinetra/database/connection.py`
- [Domain records](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/database/models.py): `backend/backend/agrinetra/database/models.py`
- [Image storage](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/storage/service.py): `backend/backend/agrinetra/storage/service.py`

### Chat and knowledge

- [Chat routes](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/api/chat_routes.py): `backend/backend/agrinetra/api/chat_routes.py`
- [Farmer chat context](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/services/chat_context.py): `backend/backend/agrinetra/services/chat_context.py`
- [Chatbot service](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/services/chatbot.py): `backend/backend/agrinetra/services/chatbot.py`
- [Ollama chatbot](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/services/ollama_chatbot.py): `backend/backend/agrinetra/services/ollama_chatbot.py`
- [Agriculture knowledge](https://github.com/chethu-1004/agri-mithra/blob/main/backend/backend/agrinetra/services/knowledge_base.py): `backend/backend/agrinetra/services/knowledge_base.py`

### Other components

- **Farmer**

## Connections

- Farmer → API application: uses API (evidence: `backend/backend/main.py`)
- API application → Account routes: registers router (evidence: `backend/backend/main.py`)
- API application → Farm and crop routes: registers router (evidence: `backend/backend/main.py`)
- API application → Disease scan routes: registers router (evidence: `backend/backend/main.py`)
- API application → Species scan routes: registers router (evidence: `backend/backend/main.py`)
- API application → Weather notifications: registers router (evidence: `backend/backend/main.py`)
- API application → Chat routes: registers router (evidence: `backend/backend/main.py`)
- API application → Administration routes: registers router (evidence: `backend/backend/main.py`)
- API application → Marketplace routes: registers router (evidence: `backend/backend/main.py`)
- API application → AI routes: registers router (evidence: `backend/backend/main.py`)
- Account routes → Database sessions: queries via (evidence: `backend/backend/agrinetra/api/auth_routes.py`)
- Account routes → Domain records: reads and writes (evidence: `backend/backend/agrinetra/api/auth_routes.py`)
- Account routes → Token authorization: uses token checks (evidence: `backend/backend/agrinetra/api/auth_routes.py`)
- Farm and crop routes → Database sessions: queries via (evidence: `backend/backend/agrinetra/api/farm_crop_routes.py`)
- Farm and crop routes → Domain records: reads and writes (evidence: `backend/backend/agrinetra/api/farm_crop_routes.py`)
- Disease scan routes → Database sessions: queries via (evidence: `backend/backend/agrinetra/api/disease_routes.py`)
- Disease scan routes → Domain records: stores scan (evidence: `backend/backend/agrinetra/api/disease_routes.py`)
- Disease scan routes → Image storage: saves image (evidence: `backend/backend/agrinetra/api/disease_routes.py`)
- Disease scan routes → Disease predictor: predicts image (evidence: `backend/backend/agrinetra/api/disease_routes.py`)
- Disease scan routes → Treatment recommendations: gets recommendation (evidence: `backend/backend/agrinetra/api/disease_routes.py`)
- Disease scan routes → Plant analysis: builds analysis (evidence: `backend/backend/agrinetra/api/disease_routes.py`)
- Species scan routes → Species predictor: predicts image (evidence: `backend/backend/agrinetra/api/species_routes.py`)
- Species scan routes → Disease predictor: checks disease (evidence: `backend/backend/agrinetra/api/species_routes.py`)
- Species scan routes → Plant analysis: builds analysis (evidence: `backend/backend/agrinetra/api/species_routes.py`)
- Species scan routes → Image storage: saves image (evidence: `backend/backend/agrinetra/api/species_routes.py`)
- Species scan routes → Domain records: stores scan (evidence: `backend/backend/agrinetra/api/species_routes.py`)
- Weather notifications → Weather service: gets forecasts (evidence: `backend/backend/agrinetra/api/weather_notification_routes.py`)
- Weather notifications → Domain records: reads and writes (evidence: `backend/backend/agrinetra/api/weather_notification_routes.py`)
- Marketplace routes → Domain records: reads and writes (evidence: `backend/backend/agrinetra/api/market_routes.py`)
- Administration routes → Domain records: manages records (evidence: `backend/backend/agrinetra/api/admin_routes.py`)
- Administration routes → Image storage: uses image storage (evidence: `backend/backend/agrinetra/api/admin_routes.py`)
- Chat routes → Farmer chat context: builds context (evidence: `backend/backend/agrinetra/api/chat_routes.py`)
- Chat routes → Chatbot service: requests reply (evidence: `backend/backend/agrinetra/api/chat_routes.py`)
- Chat routes → Agriculture knowledge: retrieves evidence (evidence: `backend/backend/agrinetra/api/chat_routes.py`)
- Chat routes → Domain records: reads and writes (evidence: `backend/backend/agrinetra/api/chat_routes.py`)
- Farmer chat context → Domain records: reads records (evidence: `backend/backend/agrinetra/services/chat_context.py`)
- Chatbot service → Ollama chatbot: delegates to (evidence: `backend/backend/agrinetra/services/chatbot.py`)
- Token authorization → Database sessions: checks revocation (evidence: `backend/backend/agrinetra/auth/dependencies.py`)
- Token authorization → Domain records: loads account (evidence: `backend/backend/agrinetra/auth/dependencies.py`)
