# suraj-juluri/smart-crop-detection architecture

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

- Interactive diagram: https://gitdiagram.com/suraj-juluri/smart-crop-detection
- Repository: https://github.com/suraj-juluri/smart-crop-detection

## Overview

1. **Repository shape**
   - This is a single Flask-based application with one Python entrypoint (`run.py`) and no separate backend/frontend services.
   - The repo is centered around two packaged AI artifacts: `keras_model.h5` for disease classification and `labels.txt` for mapping model outputs to human-readable classes.

2. **Primary runtime boundary**
   - The server is the main application boundary: it receives browser requests, renders pages, processes form/image submissions, and returns results.
   - There is no visible database or message queue, so the app appears to be mostly **stateless** and request-driven.

3. **UI layer**
   - The frontend is described as HTML/CSS/JavaScript, likely served through Flask templates and static assets.
   - The UI supports multiple workflows: image upload, symptom selection, crop recommendation form inputs, roadmap viewing, nearby shop lookup, and language switching.

4. **Disease detection pipeline**
   - User uploads a crop image.
   - The backend preprocesses the image using PIL/NumPy, runs it through the Keras/TensorFlow model, then converts the predicted class index into a label via `labels.txt`.
   - The result includes disease name, confidence, and treatment/product guidance.

5. **Symptom-based detection path**
   - There is a second diagnostic path that does not depend on the model.
   - Users choose symptoms manually, and the backend uses rule-based mapping to infer a likely disease and present the same treatment-oriented output.

6. **Crop recommendation subsystem**
   - Separate from disease diagnosis, the app contains a rule-based recommendation engine.
   - Inputs include soil type, weather conditions, location, budget, and water source.
   - The output is a suggested crop set, so this subsystem behaves more like decision logic than ML inference.

7. **Crop roadmap content**
   - The roadmap feature is a guidance module that returns a stage-wise farming plan.
   - It covers sowing, fertilization, irrigation, and harvest timing, implying mostly curated domain knowledge embedded in app logic or templates.

8. **Nearby shops / map integration**
   - The “nearby shops” feature integrates with Google Maps.
   - This is the only clearly external service in the architecture, used to help users locate fertilizer or farm-product shops.

9. **Language support**
   - English and Telugu are supported at the UI/content layer.
   - This likely affects templates and text resources rather than the inference pipeline itself.

10. **Deployment and hosting**
   - `vercel.json` indicates the app is intended to be deployable in a Vercel-style environment, even though the core app is Flask/Python.
   - That suggests an adapter or serverless hosting configuration around the Flask entrypoint, but the application logic remains backend-centric.

11. **Data flow summary**
   - Inputs enter through browser forms and image uploads.
   - The backend either runs model inference or applies rule-based logic.
   - Results are rendered back to the user as treatment guidance, crop recommendations, roadmap steps, or map links.

12. **Architectural takeaway**
   - This is best diagrammed as a **monolithic smart-farming assistant** with four main internal modules: disease detection, symptom rules, crop recommendation, and farming guidance.
   - The only external dependency that materially changes the architecture is Google Maps; the rest of the intelligence is packaged in code and model artifacts within the repo.

Main entry points: [`run.py`](https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py) (Flask app), [`vercel.json`](https://github.com/suraj-juluri/smart-crop-detection/blob/main/vercel.json) (Vercel config), [`keras_model.h5`](https://github.com/suraj-juluri/smart-crop-detection/blob/main/keras_model.h5) (Keras model), [`labels.txt`](https://github.com/suraj-juluri/smart-crop-detection/blob/main/labels.txt) (Class labels)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Flask application"]
  node_server["Flask app<br/>web server<br/>[run.py]"]
  node_upload["Upload flow<br/>image intake<br/>[run.py]"]
  node_preprocess["Preprocess<br/>image prep<br/>[run.py]"]
  node_predict["Disease model<br/>inference<br/>[run.py]"]
  node_symptoms["Symptom rules<br/>rule engine<br/>[run.py]"]
  node_recommend["Crop advice<br/>decision rules<br/>[run.py]"]
  node_roadmap["Roadmap<br/>guidance module<br/>[run.py]"]
  node_localize["Language support<br/>i18n<br/>[run.py]"]
  node_maps["Nearby shops<br/>maps integration<br/>[run.py]"]
  node_treat["Treatment output<br/>response assembly<br/>[run.py]"]
end

subgraph group_assets["Packaged AI assets"]
  node_model[("Keras model<br/>artifact<br/>[keras_model.h5]")]
  node_labels["Class labels<br/>mapping file<br/>[labels.txt]"]
end

subgraph group_deploy["Deployment"]
  node_deps["Python deps<br/>requirements<br/>[requirements.txt]"]
  node_vercel["Vercel config<br/>deployment config<br/>[vercel.json]"]
end

node_server -->|"routes"| node_upload
node_server -->|"routes"| node_symptoms
node_server -->|"routes"| node_recommend
node_server -->|"routes"| node_roadmap
node_server -->|"routes"| node_maps
node_server -->|"switches"| node_localize
node_upload -->|"feeds"| node_preprocess
node_preprocess -->|"inputs"| node_predict
node_predict -->|"loads"| node_model
node_predict -->|"decodes"| node_labels
node_predict -->|"returns"| node_treat
node_symptoms -->|"returns"| node_treat
node_recommend -->|"returns"| node_treat
node_roadmap -->|"returns"| node_treat
node_maps -->|"returns"| node_treat
node_server -.->|"depends on"| node_deps
node_vercel -.->|"hosts"| node_server

click node_server "https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py"
click node_upload "https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py"
click node_preprocess "https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py"
click node_predict "https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py"
click node_symptoms "https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py"
click node_recommend "https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py"
click node_roadmap "https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py"
click node_localize "https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py"
click node_maps "https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py"
click node_treat "https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py"
click node_model "https://github.com/suraj-juluri/smart-crop-detection/blob/main/keras_model.h5"
click node_labels "https://github.com/suraj-juluri/smart-crop-detection/blob/main/labels.txt"
click node_deps "https://github.com/suraj-juluri/smart-crop-detection/blob/main/requirements.txt"
click node_vercel "https://github.com/suraj-juluri/smart-crop-detection/blob/main/vercel.json"

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_server,node_upload,node_preprocess,node_predict,node_symptoms,node_recommend,node_roadmap,node_localize,node_maps,node_treat toneBlue
class node_model,node_labels toneAmber
class node_deps,node_vercel toneMint
```

## Components

### Flask application

Browser-facing request handling and domain logic

- [Flask app](https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py): web server · Main request boundary for uploads, forms, rendering, and results · `run.py`
- [Upload flow](https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py): image intake · Handles crop image submission from the browser · `run.py`
- [Preprocess](https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py): image prep · Converts uploaded images into model-ready tensors · `run.py`
- [Disease model](https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py): inference · Runs crop image classification against the bundled Keras model · `run.py`
- [Symptom rules](https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py): rule engine · Maps selected symptoms to a likely disease without ML inference · `run.py`
- [Crop advice](https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py): decision rules · Suggests crops from soil, weather, location, budget, and water inputs · `run.py`
- [Roadmap](https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py): guidance module · Returns stage-wise farming guidance from sowing to harvest · `run.py`
- [Language support](https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py): i18n · Switches user-facing content between English and Telugu · `run.py`
- [Nearby shops](https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py): maps integration · Links users to nearby fertilizer or farm-product shops · `run.py`
- [Treatment output](https://github.com/suraj-juluri/smart-crop-detection/blob/main/run.py): response assembly · Combines disease name, confidence, and treatment or product guidance · `run.py`

### Packaged AI assets

Model and label artifacts bundled with the repo

- [Keras model](https://github.com/suraj-juluri/smart-crop-detection/blob/main/keras_model.h5): artifact · Bundled disease-classification network used by the inference path · `keras_model.h5`
- [Class labels](https://github.com/suraj-juluri/smart-crop-detection/blob/main/labels.txt): mapping file · Maps model output indices to readable disease classes · `labels.txt`

### Deployment

Hosting and runtime packaging

- [Python deps](https://github.com/suraj-juluri/smart-crop-detection/blob/main/requirements.txt): requirements · Runtime library set for Flask, ML, and image processing · `requirements.txt`
- [Vercel config](https://github.com/suraj-juluri/smart-crop-detection/blob/main/vercel.json): deployment config · Serverless hosting and entrypoint wiring for deployment · `vercel.json`

## Connections

- Flask app → Upload flow: routes · Receives image upload requests
- Flask app → Symptom rules: routes · Handles symptom-based diagnosis
- Flask app → Crop advice: routes · Handles crop recommendation requests
- Flask app → Roadmap: routes · Serves farming roadmap guidance
- Flask app → Nearby shops: routes · Serves nearby shop lookup
- Flask app → Language support: switches · Selects English or Telugu content
- Upload flow → Preprocess: feeds · Prepares the uploaded image for inference
- Preprocess → Disease model: inputs · Passes model-ready image data
- Disease model → Keras model: loads · Uses the bundled Keras model
- Disease model → Class labels: decodes · Translates predicted class index to disease name
- Disease model → Treatment output: returns · Produces diagnosis and guidance output
- Symptom rules → Treatment output: returns · Produces rule-based diagnosis and guidance output
- Crop advice → Treatment output: returns · Produces crop recommendation response
- Roadmap → Treatment output: returns · Produces stage-wise farming plan
- Nearby shops → Treatment output: returns · Produces map links or shop lookup results
- Flask app → Python deps: depends on · Requires Flask and supporting libraries
- Vercel config → Flask app: hosts · Deploys the Flask entrypoint in a Vercel-style environment
