# himani9545/agrosolution architecture

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

- Interactive diagram: https://gitdiagram.com/himani9545/agrosolution
- Repository: https://github.com/himani9545/agrosolution

## Overview

1. **Overall shape**
   - This repository is a Python-based agricultural decision-support web app.
   - The system is split into a thin web/UI layer, a set of ML recommendation modules, and bundled training/runtime artifacts used for inference.

2. **Primary entrypoint and web app boundary**
   - `UI - Copy/appUi.py` is the main application entrypoint.
   - It serves the HTML pages in `templates/`, connects user actions to model predictions, and likely acts as the central router/controller for the site.

3. **Presentation layer**
   - `templates/` contains the user-facing pages: home, about, crops, crop info, and three embedded tool pages for crop, fertilizer, and pesticide flows.
   - `static/` holds the CSS and JavaScript that shape the experience, including animations, image handling, login/signup behavior, and language switching.

4. **Multilingual UI support**
   - `static/js/language.js` indicates client-side language switching between English and Hindi.
   - This is a UI concern rather than a model concern; it changes presentation text without affecting prediction logic.

5. **Crop recommendation subsystem**
   - `models/crop.py` and `models/crop_app.py` form the crop recommendation logic.
   - The runtime prediction path uses `crop_recommendation_model.pkl` plus `crop_label_encoder.pkl` to map environmental inputs into a crop suggestion.

6. **Fertilizer recommendation subsystem**
   - `models/fertilizer.py` and `models/ferti_app.py` implement fertilizer guidance.
   - It uses `fertilizer_recommendation_model.pkl`, `fertilizer_dosage_model.pkl`, and `fertilizer_label_encoder.pkl`, suggesting both product selection and dosage/amount prediction.
   - The supporting datasets live in `data/expanded_fertilizer_dataset.csv` and `data/updated_fertilizer_dataset.csv`.

7. **Pesticide / pest-disease subsystem**
   - `models/pesticide.py` and `models/pesticide_app.py` handle the pest/pesticide flow.
   - This subsystem is more complex: it includes `pesticide_model.pkl`, a `scaler.pkl`, and several label encoders (`le_crop.pkl`, `le_pest.pkl`, `le_disease.pkl`, `le_pesticide.pkl`, `le_method.pkl`, `le_dosage.pkl`).
   - That indicates a preprocessing step, then classification, then decoding predicted labels into actionable pesticide guidance.

8. **Image-based input path**
   - The README highlights image-based pest detection, and `static/js/image.js` suggests the UI supports image upload/preview behavior.
   - The expected flow is: user supplies an image → app preprocesses it → model predicts pest/disease-related output → encoded labels are converted into a recommendation.

9. **Data layer**
   - The repository includes training/reference datasets in `data/`, notably `Crop_recommendation.csv`, fertilizer datasets, and `pesticide_recommendation_large.csv`.
   - `users.csv` appears both under `UI - Copy/data/` and at the project root, which suggests a simple CSV-backed user store rather than a database.
   - There is no sign of an external database or cloud storage layer in the repo.

10. **Embedded Streamlit experience**
   - The presence of `templates/streamlit_iframe_crop.html`, `streamlit_iframe_ferti.html`, and `streamlit_iframe_pesticide.html` suggests some tools are exposed through embedded Streamlit views.
   - This creates a boundary between the main web UI and the interactive ML widgets, with the UI hosting those tools inside iframes.

11. **Model artifact packaging**
   - The `.pkl` files under `models/` are the deployed inference assets, separate from the source code that wraps them.
   - This implies the training pipeline is not part of the runtime app; the app consumes frozen models and encoders only.

12. **Functional flow for the whole system**
   - User visits the UI → selects a service (crop, fertilizer, or pesticide) → submits agronomic parameters or an image → server-side code in `appUi.py` and the relevant module invokes the serialized model → prediction is rendered back through HTML/Streamlit UI.
   - Authentication-like behavior is handled separately through `login.js`, `signup.js`, and CSV-based user data.

13. **Key architectural boundaries to show in a diagram**
   - Browser/UI layer: HTML, CSS, JS, image upload, language switching.
   - Python web layer: route handling and page rendering.
   - ML inference layer: crop/fertilizer/pesticide modules plus model artifacts.
   - Data assets layer: CSV datasets and user records.
   - Embedded Streamlit layer: iframe-hosted interactive prediction tools.

Main entry points: [`UI - Copy/appUi.py`](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/appUi.py) (App entry), [`UI - Copy/templates/streamlit_iframe_crop.html`](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/templates/streamlit_iframe_crop.html) (Tool frames), [`UI - Copy/models/pesticide_app.py`](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/models/pesticide_app.py) (Pesticide flow), [`UI - Copy/models/crop.py`](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/models/crop.py) (Crop model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Web UI"]
  node_app["App entry<br/>Flask UI<br/>[appUi.py]"]
  node_templates_home["Pages<br/>HTML views<br/>[home.html]"]
  node_templates_tools["Tool frames<br/>iframe views"]
  node_templates_misc["Support pages<br/>HTML views<br/>[about.html]"]
  node_styles["Stylesheets<br/>CSS assets<br/>[style.css]"]
  node_lang_js["Language switch<br/>client i18n<br/>[language.js]"]
  node_image_js["Image upload<br/>client image UI<br/>[image.js]"]
  node_auth_js["Auth scripts<br/>client auth UI<br/>[login.js]"]
end

subgraph group_ml["ML Inference"]
  node_crop_flow["Crop flow<br/>recommendation module<br/>[crop_app.py]"]
  node_crop_core["Crop model<br/>inference wrapper<br/>[crop.py]"]
  node_fert_flow["Fertilizer flow<br/>recommendation module<br/>[ferti_app.py]"]
  node_fert_core["Fertilizer model<br/>inference wrapper<br/>[fertilizer.py]"]
  node_pest_flow["Pesticide flow<br/>recommendation module<br/>[pesticide_app.py]"]
  node_pest_core["Pesticide model<br/>inference wrapper<br/>[pesticide.py]"]
  node_crop_artifacts[("Crop artifacts<br/>model bundle")]
  node_fert_artifacts[("Fertilizer artifacts<br/>model bundle")]
  node_pest_artifacts[("Pesticide artifacts<br/>model bundle")]
end

subgraph group_data["Data Assets"]
  node_crop_data["Crop data<br/>training csv"]
  node_fert_data["Fertilizer data<br/>training csv"]
  node_pest_data["Pesticide data<br/>training csv"]
  node_users[("Users CSV<br/>csv store<br/>[users.csv]")]
end

node_app -->|"renders"| node_templates_home
node_app -->|"hosts"| node_templates_tools
node_app -->|"renders"| node_templates_misc
node_app -->|"uses"| node_styles
node_app -->|"serves"| node_lang_js
node_app -->|"serves"| node_image_js
node_app -->|"supports"| node_auth_js
node_app -->|"routes to"| node_crop_flow
node_app -->|"routes to"| node_fert_flow
node_app -->|"routes to"| node_pest_flow
node_auth_js -->|"reads/writes"| node_users
node_crop_flow -->|"invokes"| node_crop_core
node_crop_core -->|"loads"| node_crop_artifacts
node_crop_core -.->|"trained from"| node_crop_data
node_fert_flow -->|"invokes"| node_fert_core
node_fert_core -->|"loads"| node_fert_artifacts
node_fert_core -.->|"trained from"| node_fert_data
node_pest_flow -->|"invokes"| node_pest_core
node_pest_core -->|"loads"| node_pest_artifacts
node_pest_core -.->|"trained from"| node_pest_data
node_image_js -->|"feeds input"| node_pest_flow
node_templates_tools -->|"embeds"| node_crop_flow
node_templates_tools -->|"embeds"| node_fert_flow
node_templates_tools -->|"embeds"| node_pest_flow

click node_app "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/appUi.py"
click node_templates_home "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/templates/home.html"
click node_templates_tools "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/templates/streamlit_iframe_crop.html"
click node_templates_misc "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/templates/about.html"
click node_styles "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/static/style.css"
click node_lang_js "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/static/js/language.js"
click node_image_js "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/static/js/image.js"
click node_auth_js "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/static/js/login.js"
click node_crop_flow "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/models/crop_app.py"
click node_crop_core "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/models/crop.py"
click node_fert_flow "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/models/ferti_app.py"
click node_fert_core "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/models/fertilizer.py"
click node_pest_flow "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/models/pesticide_app.py"
click node_pest_core "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/models/pesticide.py"
click node_crop_artifacts "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/models/crop_recommendation_model.pkl"
click node_fert_artifacts "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/models/fertilizer_recommendation_model.pkl"
click node_pest_artifacts "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/models/pesticide_model.pkl"
click node_crop_data "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/data/Crop_recommendation.csv"
click node_fert_data "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/data/updated_fertilizer_dataset.csv"
click node_pest_data "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/data/pesticide_recommendation_large.csv"
click node_users "https://github.com/himani9545/agrosolution/blob/main/UI - Copy/users.csv"

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_templates_home,node_templates_tools,node_templates_misc,node_styles,node_lang_js,node_image_js,node_auth_js toneBlue
class node_crop_flow,node_crop_core,node_fert_flow,node_fert_core,node_pest_flow,node_pest_core,node_crop_artifacts,node_fert_artifacts,node_pest_artifacts toneAmber
class node_crop_data,node_fert_data,node_pest_data,node_users toneMint
```

## Components

### Web UI

Browser-facing pages, scripts, and request handling

- [App entry](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/appUi.py): Flask UI · Main web entrypoint and controller for the site · `UI - Copy/appUi.py`
- [Pages](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/templates/home.html): HTML views · User-facing templates for landing and informational pages · `UI - Copy/templates/home.html`
- [Tool frames](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/templates/streamlit_iframe_crop.html): iframe views · Embedded pages that host interactive recommendation tools · `UI - Copy/templates/streamlit_iframe_crop.html`
- [Support pages](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/templates/about.html): HTML views · About, crop info, and auxiliary pages used by the site · `UI - Copy/templates/about.html`
- [Stylesheets](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/static/style.css): CSS assets · Site styling for layout, branding, and embedded tool shells · `UI - Copy/static/style.css`
- [Language switch](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/static/js/language.js): client i18n · Client-side English/Hindi text switching · `UI - Copy/static/js/language.js`
- [Image upload](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/static/js/image.js): client image UI · Image preview and upload behavior for pest/disease flows · `UI - Copy/static/js/image.js`
- [Auth scripts](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/static/js/login.js): client auth UI · Login and signup interactions backed by simple CSV user data · `UI - Copy/static/js/login.js`

### ML Inference

Recommendation flows and serialized model assets

- [Crop flow](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/models/crop_app.py): recommendation module · Crop recommendation request handling and feature-to-label mapping · `UI - Copy/models/crop_app.py`
- [Crop model](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/models/crop.py): inference wrapper · Crop recommendation logic used by the runtime app · `UI - Copy/models/crop.py`
- [Fertilizer flow](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/models/ferti_app.py): recommendation module · Fertilizer selection and dosage guidance · `UI - Copy/models/ferti_app.py`
- [Fertilizer model](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/models/fertilizer.py): inference wrapper · Fertilizer recommendation logic and decoded outputs · `UI - Copy/models/fertilizer.py`
- [Pesticide flow](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/models/pesticide_app.py): recommendation module · Pest and pesticide recommendation pipeline · `UI - Copy/models/pesticide_app.py`
- [Pesticide model](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/models/pesticide.py): inference wrapper · Preprocesses inputs and decodes pesticide guidance · `UI - Copy/models/pesticide.py`
- [Crop artifacts](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/models/crop_recommendation_model.pkl): model bundle · Serialized crop classifier and label encoder · `UI - Copy/models/crop_recommendation_model.pkl`
- [Fertilizer artifacts](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/models/fertilizer_recommendation_model.pkl): model bundle · Serialized fertilizer and dosage models plus encoder · `UI - Copy/models/fertilizer_recommendation_model.pkl`
- [Pesticide artifacts](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/models/pesticide_model.pkl): model bundle · Serialized pesticide model, scaler, and label encoders · `UI - Copy/models/pesticide_model.pkl`

### Data Assets

Reference datasets and simple CSV-backed records

- [Crop data](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/data/Crop_recommendation.csv): training csv · Reference dataset for crop recommendation · `UI - Copy/data/Crop_recommendation.csv`
- [Fertilizer data](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/data/updated_fertilizer_dataset.csv): training csv · Datasets used to train fertilizer guidance models · `UI - Copy/data/updated_fertilizer_dataset.csv`
- [Pesticide data](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/data/pesticide_recommendation_large.csv): training csv · Reference dataset for pesticide recommendation · `UI - Copy/data/pesticide_recommendation_large.csv`
- [Users CSV](https://github.com/himani9545/agrosolution/blob/HEAD/UI%20-%20Copy/users.csv): csv store · Lightweight user record storage used by the auth flow · `UI - Copy/users.csv`

## Connections

- App entry → Pages: renders · Serves the main pages and route responses
- App entry → Tool frames: hosts · Embeds interactive recommendation tools in the UI
- App entry → Support pages: renders · Serves support and informational pages
- App entry → Stylesheets: uses · Loads CSS for page layout and embedded shells
- App entry → Language switch: serves · Delivers multilingual UI behavior to the browser
- App entry → Image upload: serves · Supports image-based input interactions
- App entry → Auth scripts: supports · Connects the web app to login and signup behavior
- App entry → Crop flow: routes to · Dispatches crop requests to the crop subsystem
- App entry → Fertilizer flow: routes to · Dispatches fertilizer requests to the fertilizer subsystem
- App entry → Pesticide flow: routes to · Dispatches pest and pesticide requests to the pesticide subsystem
- Auth scripts → Users CSV: reads/writes · Uses CSV-backed user records instead of a database
- Crop flow → Crop model: invokes · Delegates crop recommendation logic to the core wrapper
- Crop model → Crop artifacts: loads · Consumes frozen crop model and label encoder
- Crop model → Crop data: trained from · Uses crop dataset as the reference training source
- Fertilizer flow → Fertilizer model: invokes · Delegates fertilizer recommendation and dosage prediction
- Fertilizer model → Fertilizer artifacts: loads · Consumes fertilizer models and encoders
- Fertilizer model → Fertilizer data: trained from · Uses fertilizer datasets as the reference source
- Pesticide flow → Pesticide model: invokes · Delegates pesticide recommendation logic to the core wrapper
- Pesticide model → Pesticide artifacts: loads · Consumes scaler, model, and label encoders
- Pesticide model → Pesticide data: trained from · Uses pesticide dataset as the reference source
- Image upload → Pesticide flow: feeds input · Supports image-based pest detection workflow
- Tool frames → Crop flow: embeds · Hosts crop tool UI in an iframe
- Tool frames → Fertilizer flow: embeds · Hosts fertilizer tool UI in an iframe
- Tool frames → Pesticide flow: embeds · Hosts pesticide tool UI in an iframe
