# ashutoshdebug/kisan-mitr architecture

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

- Interactive diagram: https://gitdiagram.com/ashutoshdebug/kisan-mitr
- Repository: https://github.com/ashutoshdebug/kisan-mitr
- Video tour (about a minute): https://gitdiagram.com/ashutoshdebug/kisan-mitr/video

## Overview

Kisan-Mitr is a Flask crop-diagnosis web app. A farmer signs in, uploads a crop image, enters field conditions, and receives a structured AI diagnosis saved for later display. The graph preserves the documented browser geocoding/weather branch and account/profile capabilities. Edge evidence comes from the shown source excerpts, SOURCE INDEX references, and README; unsampled frontend and route details are represented only where documented.

Main entry points: [`app.py`](https://github.com/ashutoshdebug/kisan-mitr/blob/main/app.py) (Flask app), [`routes/acquire.py`](https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/acquire.py) (Field details), [`database/db_handler.py`](https://github.com/ashutoshdebug/kisan-mitr/blob/main/database/db_handler.py) (Database handler), [`routes/upload.py`](https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/upload.py) (Image upload)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web workflow"]
  node_flask["Flask app<br/>[app.py]"]
  node_landing["Landing page<br/>[landing.py]"]
  node_motive["Motive page<br/>[motivePage.py]"]
  node_notfound["Not found<br/>[pageNotFound.py]"]
  node_error["Error page<br/>[errorPage.py]"]
  node_upload["Image upload<br/>[upload.py]"]
  node_uploadui["Upload interface<br/>[upload.js]"]
  node_acquire["Field details<br/>[acquire.py]"]
  node_fieldui["Field form<br/>[acquireInfo.js]"]
  node_results["Diagnosis results<br/>[results.py]"]
end

subgraph group_accounts["Accounts and profile"]
  node_login["Login and signup<br/>[login.py]"]
  node_logout["Logout<br/>[logout.py]"]
  node_profile["Profile management<br/>[profile.py]"]
  node_hash["Password hashing<br/>[password_hash.py]"]
end

subgraph group_diagnosis["Diagnosis pipeline"]
  node_prompt["Prompt builder<br/>[dataAcquisition.py]"]
  node_vision["Vision model<br/>[vision_model.py]"]
  node_gemini{{"Gemini service"}}
end

subgraph group_persistence["Persistence and files"]
  node_dbhandler["Database handler<br/>[db_handler.py]"]
  node_mysql[("MySQL")]
  node_files["User file manager<br/>[filenFolderPath.py]"]
  node_userfiles[("User files")]
end

subgraph group_environment["Field environment"]
  node_geocoding{{"Geocoding service"}}
  node_weather{{"Weather service"}}
end

node_farmer(("Farmer"))

node_farmer -->|"uses app"| node_flask
node_flask -->|"registers"| node_landing
node_flask -->|"registers"| node_motive
node_flask -->|"registers"| node_notfound
node_flask -->|"registers"| node_error
node_flask -->|"registers"| node_upload
node_flask -->|"registers"| node_acquire
node_flask -->|"registers"| node_results
node_flask -->|"registers"| node_login
node_flask -->|"registers"| node_logout
node_flask -->|"registers"| node_profile
node_farmer -->|"selects image"| node_uploadui
node_uploadui -.->|"posts image"| node_upload
node_upload -->|"saves image"| node_files
node_upload -->|"records image"| node_dbhandler
node_upload -->|"redirects to"| node_acquire
node_farmer -->|"enters details"| node_fieldui
node_fieldui -->|"geocodes location"| node_geocoding
node_fieldui -->|"fetches weather"| node_weather
node_fieldui -.->|"submits fields"| node_acquire
node_acquire -->|"builds prompt"| node_prompt
node_acquire -->|"stores field data"| node_dbhandler
node_acquire -->|"sends image and prompt"| node_vision
node_vision -->|"requests analysis"| node_gemini
node_acquire -->|"saves result JSON"| node_files
node_acquire -->|"records result name"| node_dbhandler
node_acquire -->|"renders diagnosis"| node_results
node_farmer -->|"registers or signs in"| node_login
node_login -->|"authenticates account"| node_dbhandler
node_dbhandler -->|"hashes password"| node_hash
node_login -->|"creates user folders"| node_files
node_farmer -->|"manages profile"| node_profile
node_profile -->|"loads profile"| node_dbhandler
node_profile -->|"manages profile image"| node_files
node_logout -->|"ends session"| node_farmer
node_dbhandler -->|"reads and writes"| node_mysql
node_files -->|"reads and writes"| node_userfiles
node_results -->|"checks account data"| node_dbhandler

click node_flask "https://github.com/ashutoshdebug/kisan-mitr/blob/main/app.py"
click node_landing "https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/landing.py"
click node_motive "https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/motivePage.py"
click node_notfound "https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/pageNotFound.py"
click node_error "https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/errorPage.py"
click node_upload "https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/upload.py"
click node_uploadui "https://github.com/ashutoshdebug/kisan-mitr/blob/main/static/js/upload.js"
click node_acquire "https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/acquire.py"
click node_fieldui "https://github.com/ashutoshdebug/kisan-mitr/blob/main/static/js/acquireInfo.js"
click node_results "https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/results.py"
click node_login "https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/login.py"
click node_logout "https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/logout.py"
click node_profile "https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/profile.py"
click node_hash "https://github.com/ashutoshdebug/kisan-mitr/blob/main/utils/password_hash.py"
click node_prompt "https://github.com/ashutoshdebug/kisan-mitr/blob/main/engine/dataAcquisition.py"
click node_vision "https://github.com/ashutoshdebug/kisan-mitr/blob/main/engine/vision_model.py"
click node_dbhandler "https://github.com/ashutoshdebug/kisan-mitr/blob/main/database/db_handler.py"
click node_files "https://github.com/ashutoshdebug/kisan-mitr/blob/main/utils/filenFolderPath.py"
click node_userfiles "https://github.com/ashutoshdebug/kisan-mitr/tree/main/static/uploads"

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_flask,node_landing,node_motive,node_notfound,node_error,node_upload,node_uploadui,node_acquire,node_fieldui,node_results toneBlue
class node_login,node_logout,node_profile,node_hash toneAmber
class node_prompt,node_vision,node_gemini toneMint
class node_dbhandler,node_mysql,node_files,node_userfiles toneRose
class node_geocoding,node_weather,node_farmer toneIndigo
```

## Components

### Web workflow

- [Flask app](https://github.com/ashutoshdebug/kisan-mitr/blob/main/app.py): `app.py`
- [Landing page](https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/landing.py): `routes/landing.py`
- [Motive page](https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/motivePage.py): `routes/motivePage.py`
- [Not found](https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/pageNotFound.py): `routes/pageNotFound.py`
- [Error page](https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/errorPage.py): `routes/errorPage.py`
- [Image upload](https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/upload.py): `routes/upload.py`
- [Upload interface](https://github.com/ashutoshdebug/kisan-mitr/blob/main/static/js/upload.js): `static/js/upload.js`
- [Field details](https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/acquire.py): `routes/acquire.py`
- [Field form](https://github.com/ashutoshdebug/kisan-mitr/blob/main/static/js/acquireInfo.js): `static/js/acquireInfo.js`
- [Diagnosis results](https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/results.py): `routes/results.py`

### Accounts and profile

- [Login and signup](https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/login.py): `routes/login.py`
- [Logout](https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/logout.py): `routes/logout.py`
- [Profile management](https://github.com/ashutoshdebug/kisan-mitr/blob/main/routes/profile.py): `routes/profile.py`
- [Password hashing](https://github.com/ashutoshdebug/kisan-mitr/blob/main/utils/password_hash.py): `utils/password_hash.py`

### Diagnosis pipeline

- [Prompt builder](https://github.com/ashutoshdebug/kisan-mitr/blob/main/engine/dataAcquisition.py): `engine/dataAcquisition.py`
- [Vision model](https://github.com/ashutoshdebug/kisan-mitr/blob/main/engine/vision_model.py): `engine/vision_model.py`
- **Gemini service**

### Persistence and files

- [Database handler](https://github.com/ashutoshdebug/kisan-mitr/blob/main/database/db_handler.py): `database/db_handler.py`
- **MySQL**
- [User file manager](https://github.com/ashutoshdebug/kisan-mitr/blob/main/utils/filenFolderPath.py): `utils/filenFolderPath.py`
- [User files](https://github.com/ashutoshdebug/kisan-mitr/tree/main/static/uploads): `static/uploads`

### Field environment

- **Geocoding service**
- **Weather service**

### Other components

- **Farmer**

## Connections

- Farmer → Flask app: uses app (evidence: `README.md`)
- Flask app → Landing page: registers (evidence: `app.py`)
- Flask app → Motive page: registers (evidence: `app.py`)
- Flask app → Not found: registers (evidence: `app.py`)
- Flask app → Error page: registers (evidence: `app.py`)
- Flask app → Image upload: registers (evidence: `app.py`)
- Flask app → Field details: registers (evidence: `app.py`)
- Flask app → Diagnosis results: registers (evidence: `app.py`)
- Flask app → Login and signup: registers (evidence: `app.py`)
- Flask app → Logout: registers (evidence: `app.py`)
- Flask app → Profile management: registers (evidence: `app.py`)
- Farmer → Upload interface: selects image (evidence: `README.md`)
- Upload interface → Image upload: posts image (evidence: `README.md`)
- Image upload → User file manager: saves image (evidence: `routes/upload.py`)
- Image upload → Database handler: records image (evidence: `routes/upload.py`)
- Image upload → Field details: redirects to (evidence: `routes/upload.py`)
- Farmer → Field form: enters details (evidence: `README.md`)
- Field form → Geocoding service: geocodes location (evidence: `README.md`)
- Field form → Weather service: fetches weather (evidence: `README.md`)
- Field form → Field details: submits fields (evidence: `README.md`)
- Field details → Prompt builder: builds prompt (evidence: `routes/acquire.py`)
- Field details → Database handler: stores field data (evidence: `routes/acquire.py`)
- Field details → Vision model: sends image and prompt (evidence: `routes/acquire.py`)
- Vision model → Gemini service: requests analysis (evidence: `engine/vision_model.py`)
- Field details → User file manager: saves result JSON (evidence: `routes/acquire.py`)
- Field details → Database handler: records result name (evidence: `routes/acquire.py`)
- Field details → Diagnosis results: renders diagnosis (evidence: `routes/acquire.py`)
- Farmer → Login and signup: registers or signs in (evidence: `README.md`)
- Login and signup → Database handler: authenticates account (evidence: `routes/login.py`)
- Database handler → Password hashing: hashes password (evidence: `database/db_handler.py`)
- Login and signup → User file manager: creates user folders (evidence: `routes/login.py`)
- Farmer → Profile management: manages profile (evidence: `README.md`)
- Profile management → Database handler: loads profile (evidence: `routes/profile.py`)
- Profile management → User file manager: manages profile image (evidence: `routes/profile.py`)
- Logout → Farmer: ends session (evidence: `README.md`)
- Database handler → MySQL: reads and writes (evidence: `README.md`)
- User file manager → User files: reads and writes (evidence: `utils/filenFolderPath.py`)
- Diagnosis results → Database handler: checks account data (evidence: `routes/results.py`)
