# rutukinnal0123/ai-farming-assistant architecture

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

- Interactive diagram: https://gitdiagram.com/rutukinnal0123/ai-farming-assistant
- Repository: https://github.com/rutukinnal0123/ai-farming-assistant

## Overview

AI Farming Assistant combines a Streamlit farmer-facing app with a FastAPI backend for farmer and farm management, chat, activity tracking, reminders, and history. The principal workflow is a text or voice question routed through chat handling, enriched with farmer, farm, activity, reminder, weather, and retrieved agricultural context, then answered by Gemini and returned to the farmer. The graph follows shown calls and README-documented capabilities; some storage and document-ingestion internals are unsampled, so their connections are limited to documented relationships.

Main entry points: [`backend/chat.py`](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/chat.py) (Chat orchestration), [`backend/app.py`](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/app.py) (FastAPI routes), [`backend/services/ai_service.py`](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/services/ai_service.py) (Recommendation generation), [`backend/crud.py`](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/crud.py) (Farm and history CRUD)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Farmer application"]
  node_streamlit["Streamlit interface<br/>[app.py]"]
end

subgraph group_api["Backend API"]
  node_api_entry["FastAPI routes<br/>[app.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_chat["Chat orchestration<br/>[chat.py]"]
  node_schemas["API schemas<br/>[schemas.py]"]
  node_security["JWT security<br/>[security.py]"]
end

subgraph group_advisory["Advisory services"]
  node_ai["Recommendation generation<br/>[ai_service.py]"]
  node_activity["Activity detection"]
  node_translation["Language translation"]
  node_voice["Speech conversion<br/>[voice_service.py]"]
  node_weather["Weather lookup<br/>[weather_service.py]"]
end

subgraph group_knowledge["Agricultural knowledge"]
  node_retriever["Semantic retrieval<br/>[retriever.py]"]
  node_embedding["Embedding setup<br/>[embeddings.py]"]
  node_documents["Agricultural documents"]
  node_vectorstore[("Chroma vector store<br/>[chroma.sqlite3]")]
end

subgraph group_persistence["Persistence"]
  node_crud["Farm and history CRUD<br/>[crud.py]"]
  node_models["Domain models<br/>[models.py]"]
  node_database[("Relational database<br/>[database.py]")]
end

node_farmer(("Farmer"))
node_gemini["Google Gemini"]
node_weather_api["Weather API"]
node_translation_api["Google Translate"]
node_speech_service["Speech services"]

node_farmer -->|"uses"| node_streamlit
node_streamlit -->|"calls HTTP API"| node_api_entry
node_api_entry -->|"registers router"| node_auth
node_api_entry -->|"registers router"| node_chat
node_api_entry -->|"calls CRUD"| node_crud
node_api_entry -->|"checks identity"| node_security
node_auth -->|"looks up farmer"| node_crud
node_auth -->|"verifies and issues token"| node_security
node_chat -->|"loads and saves records"| node_crud
node_chat -->|"detects activities"| node_activity
node_chat -->|"translates messages"| node_translation
node_chat -->|"converts speech"| node_voice
node_chat -->|"requests answer"| node_ai
node_chat -->|"builds record payloads"| node_schemas
node_api_entry -->|"validates route data"| node_schemas
node_crud -.->|"persists domain records"| node_models
node_models -->|"uses ORM base"| node_database
node_ai -->|"retrieves context"| node_retriever
node_ai -->|"gets local weather"| node_weather
node_ai -->|"generates response"| node_gemini
node_weather -->|"fetches conditions"| node_weather_api
node_translation -->|"translates text"| node_translation_api
node_voice -.->|"transcribes and synthesizes"| node_speech_service
node_retriever -->|"searches vectors"| node_vectorstore
node_documents -.->|"chunks and embeds"| node_embedding
node_embedding -.->|"stores embeddings"| node_vectorstore

click node_streamlit "https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/frontend/app.py"
click node_api_entry "https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/app.py"
click node_auth "https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/auth.py"
click node_chat "https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/chat.py"
click node_schemas "https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/schemas.py"
click node_security "https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/security.py"
click node_crud "https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/crud.py"
click node_models "https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/models.py"
click node_database "https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/database.py"
click node_ai "https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/services/ai_service.py"
click node_activity "https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/services/activity_service.py"
click node_translation "https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/services/translation_service.py"
click node_voice "https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/services/voice_service.py"
click node_weather "https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/services/weather_service.py"
click node_retriever "https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/rag/retriever.py"
click node_embedding "https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/rag/embeddings.py"
click node_documents "https://github.com/rutukinnal0123/ai-farming-assistant/tree/main/backend/documents"
click node_vectorstore "https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/rag/chroma.sqlite3"

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_streamlit toneBlue
class node_api_entry,node_auth,node_chat,node_schemas,node_security toneAmber
class node_ai,node_activity,node_translation,node_voice,node_weather,node_weather_api toneMint
class node_retriever,node_embedding,node_documents,node_vectorstore toneRose
class node_crud,node_models,node_database,node_farmer,node_gemini,node_translation_api,node_speech_service toneIndigo
```

## Components

### Farmer application

- [Streamlit interface](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/frontend/app.py): `frontend/app.py`

### Backend API

- [FastAPI routes](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/app.py): `backend/app.py`
- [Authentication](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/auth.py): `backend/auth.py`
- [Chat orchestration](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/chat.py): `backend/chat.py`
- [API schemas](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/schemas.py): `backend/schemas.py`
- [JWT security](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/security.py): `backend/security.py`

### Advisory services

- [Recommendation generation](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/services/ai_service.py): `backend/services/ai_service.py`
- [Activity detection](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/services/activity_service.py): `backend/services/activity_service.py`
- [Language translation](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/services/translation_service.py): `backend/services/translation_service.py`
- [Speech conversion](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/services/voice_service.py): `backend/services/voice_service.py`
- [Weather lookup](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/services/weather_service.py): `backend/services/weather_service.py`

### Agricultural knowledge

- [Semantic retrieval](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/rag/retriever.py): `backend/rag/retriever.py`
- [Embedding setup](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/rag/embeddings.py): `backend/rag/embeddings.py`
- [Agricultural documents](https://github.com/rutukinnal0123/ai-farming-assistant/tree/main/backend/documents): `backend/documents`
- [Chroma vector store](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/rag/chroma.sqlite3): `backend/rag/chroma.sqlite3`

### Persistence

- [Farm and history CRUD](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/crud.py): `backend/crud.py`
- [Domain models](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/models.py): `backend/models.py`
- [Relational database](https://github.com/rutukinnal0123/ai-farming-assistant/blob/main/backend/database.py): `backend/database.py`

### Other components

- **Farmer**
- **Google Gemini**
- **Weather API**
- **Google Translate**
- **Speech services**

## Connections

- Farmer → Streamlit interface: uses (evidence: `README.md`)
- Streamlit interface → FastAPI routes: calls HTTP API (evidence: `frontend/app.py`)
- FastAPI routes → Authentication: registers router (evidence: `backend/app.py`)
- FastAPI routes → Chat orchestration: registers router (evidence: `backend/app.py`)
- FastAPI routes → Farm and history CRUD: calls CRUD (evidence: `backend/app.py`)
- FastAPI routes → JWT security: checks identity (evidence: `backend/app.py`)
- Authentication → Farm and history CRUD: looks up farmer (evidence: `backend/auth.py`)
- Authentication → JWT security: verifies and issues token (evidence: `backend/auth.py`)
- Chat orchestration → Farm and history CRUD: loads and saves records (evidence: `backend/chat.py`)
- Chat orchestration → Activity detection: detects activities (evidence: `backend/chat.py`)
- Chat orchestration → Language translation: translates messages (evidence: `backend/chat.py`)
- Chat orchestration → Speech conversion: converts speech (evidence: `backend/chat.py`)
- Chat orchestration → Recommendation generation: requests answer (evidence: `backend/chat.py`)
- Chat orchestration → API schemas: builds record payloads (evidence: `backend/chat.py`)
- FastAPI routes → API schemas: validates route data (evidence: `backend/app.py`)
- Farm and history CRUD → Domain models: persists domain records
- Domain models → Relational database: uses ORM base (evidence: `backend/models.py`)
- Recommendation generation → Semantic retrieval: retrieves context (evidence: `backend/services/ai_service.py`)
- Recommendation generation → Weather lookup: gets local weather (evidence: `backend/services/ai_service.py`)
- Recommendation generation → Google Gemini: generates response (evidence: `backend/services/ai_service.py`)
- Weather lookup → Weather API: fetches conditions (evidence: `backend/services/weather_service.py`)
- Language translation → Google Translate: translates text (evidence: `backend/services/translation_service.py`)
- Speech conversion → Speech services: transcribes and synthesizes
- Semantic retrieval → Chroma vector store: searches vectors (evidence: `backend/rag/retriever.py`)
- Agricultural documents → Embedding setup: chunks and embeds (evidence: `README.md`)
- Embedding setup → Chroma vector store: stores embeddings (evidence: `README.md`)
