# inflixop/smart-agriculture-advisory-system architecture

> Architecture diagram of the GitHub repository inflixop/smart-agriculture-advisory-system, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-22). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/inflixop/smart-agriculture-advisory-system
- Repository: https://github.com/inflixop/smart-agriculture-advisory-system

## Overview

#### Purpose and Entry Points
This repository delivers a local Smart Agriculture Advisory System that recommends a crop from soil and weather inputs. The deployable entry point is `app.py`; its browser interface is `templates/index.html` with styling in `static/styles.css`. Exploratory/training workflows are preserved in `Smart_Agriculture_System.ipynb` and `knn-model.ipynb`.

#### Web Application Boundary
`app.py` is the application controller: it accepts user-supplied nitrogen, phosphorus, potassium, temperature, humidity, pH, and rainfall values, invokes a persisted model, and returns a recommendation to the rendered UI. `templates/index.html` is the presentation/input boundary, while `static/styles.css` supplies client-side appearance. No separate API service, database, or authentication layer is present in the repository tree.

#### Feature Contract and Dataset
`Crop_recommendation.csv` defines the model-facing tabular contract: seven numeric agronomic/environmental features and the target crop `label`. The same ordered feature set must be maintained from form extraction in `app.py` through model inference; model artifacts cannot safely accept reordered or differently transformed inputs.

#### Model Training and Experimentation
`Smart_Agriculture_System.ipynb` is the primary analysis/model-development artifact described by the README, covering preprocessing, classifier evaluation, and prediction exploration. `knn-model.ipynb` indicates a parallel KNN experiment. These notebooks are offline development stages rather than application runtime dependencies, but they define how the CSV data becomes serialized inference artifacts.

#### Persisted Inference Artifacts
Three binary artifacts are checked into the repository: `smart-agriculture.joblib`, `knn_model.joblib`, and `smart-agripkl.pkl`. They separate model training from request-time prediction and require compatible Python ML-library serialization versions at runtime. The README identifies Random Forest as the selected deployment model, while the KNN artifact provides an alternate or experimental classifier; `app.py` is the source of truth for which artifact is loaded.

#### Primary Control Flow
A user opens the HTML form (`templates/index.html`), submits soil/weather values to `app.py`, and the server converts those values into the model’s expected feature vector. The loaded serialized classifier (`smart-agriculture.joblib`, `smart-agripkl.pkl`, or `knn_model.joblib`) predicts a crop label, which `app.py` passes back into the rendered response. The browser displays that recommendation using `templates/index.html` and `static/styles.css`.

#### Runtime and Infrastructure
The runtime is Python, expected to be managed through Conda per `README.md`, with Jupyter used for notebook-based training/analysis. `package.json` exists but no JavaScript source, build pipeline, or Node service is visible, so it is not a core execution path based on the tree. The only identified external data source is the Kaggle Crop Recommendation Dataset, materialized locally as `Crop_recommendation.csv`; inference itself appears local and does not depend on external services.

Main entry points: [`app.py`](https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/app.py) (Application controller), [`Smart_Agriculture_System.ipynb`](https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/Smart_Agriculture_System.ipynb) (Primary model development), [`templates/index.html`](https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/templates/index.html) (Crop input form), [`Crop_recommendation.csv`](https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/Crop_recommendation.csv) (Crop recommendation data)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_offline["Offline model development"]
  node_dataset[("Crop recommendation data<br/>CSV dataset")]
  node_primary_notebook["Primary model development<br/>Jupyter notebook"]
  node_knn_notebook["KNN experiment<br/>Jupyter notebook<br/>[knn-model.ipynb]"]
  node_rf_artifact[("Selected RF model<br/>Joblib artifact")]
  node_knn_artifact[("KNN model<br/>Joblib artifact<br/>[knn_model.joblib]")]
  node_pkl_artifact[("Serialized model<br/>Pickle artifact<br/>[smart-agripkl.pkl]")]
end

subgraph group_runtime["Local web application"]
  node_browser_ui["Crop input form<br/>HTML template<br/>[index.html]"]
  node_styles["UI styling<br/>CSS stylesheet<br/>[styles.css]"]
  node_app["Application controller<br/>Python web app<br/>[app.py]"]
  node_feature_vector["Ordered feature vector<br/>Inference contract"]
  node_classifier{{"Loaded classifier<br/>Python ML runtime"}}
  node_recommendation["Crop recommendation<br/>Prediction result"]
end

node_dataset -->|"training data"| node_primary_notebook
node_dataset -->|"training data"| node_knn_notebook
node_primary_notebook -->|"trains and serializes"| node_rf_artifact
node_primary_notebook -.->|"serializes"| node_pkl_artifact
node_knn_notebook -->|"trains and serializes"| node_knn_artifact
node_styles -->|"styles"| node_browser_ui
node_browser_ui -->|"submits seven inputs"| node_app
node_app -->|"extracts in contract order"| node_feature_vector
node_feature_vector -->|"predicts with"| node_classifier
node_rf_artifact -.->|"possible loaded artifact"| node_classifier
node_knn_artifact -.->|"possible loaded artifact"| node_classifier
node_pkl_artifact -.->|"possible loaded artifact"| node_classifier
node_classifier -->|"predicts crop label"| node_recommendation
node_recommendation -->|"returned for rendering"| node_app
node_app -->|"renders result"| node_browser_ui

click node_dataset "https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/Crop_recommendation.csv"
click node_primary_notebook "https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/Smart_Agriculture_System.ipynb"
click node_knn_notebook "https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/knn-model.ipynb"
click node_rf_artifact "https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/smart-agriculture.joblib"
click node_knn_artifact "https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/knn_model.joblib"
click node_pkl_artifact "https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/smart-agripkl.pkl"
click node_browser_ui "https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/templates/index.html"
click node_styles "https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/static/styles.css"
click node_app "https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/app.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_dataset,node_primary_notebook,node_knn_notebook,node_rf_artifact,node_knn_artifact,node_pkl_artifact toneBlue
class node_browser_ui,node_styles,node_app,node_feature_vector,node_classifier,node_recommendation toneAmber
```

## Components

### Offline model development

Notebook-based analysis and training.

- [Crop recommendation data](https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/Crop_recommendation.csv): CSV dataset · Seven ordered numeric features plus crop label. · `Crop_recommendation.csv`
- [Primary model development](https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/Smart_Agriculture_System.ipynb): Jupyter notebook · Preprocessing, evaluation, and prediction exploration. · `Smart_Agriculture_System.ipynb`
- [KNN experiment](https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/knn-model.ipynb): Jupyter notebook · Parallel classifier experiment. · `knn-model.ipynb`
- [Selected RF model](https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/smart-agriculture.joblib): Joblib artifact · README-selected deployed classifier artifact. · `smart-agriculture.joblib`
- [KNN model](https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/knn_model.joblib): Joblib artifact · Alternate experimental classifier. · `knn_model.joblib`
- [Serialized model](https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/smart-agripkl.pkl): Pickle artifact · Additional persisted inference artifact. · `smart-agripkl.pkl`

### Local web application

Python-hosted crop recommendation flow.

- [Crop input form](https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/templates/index.html): HTML template · Collects soil and weather values and displays recommendations. · `templates/index.html`
- [UI styling](https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/static/styles.css): CSS stylesheet · `static/styles.css`
- [Application controller](https://github.com/inflixop/smart-agriculture-advisory-system/blob/main/app.py): Python web app · Extracts ordered features, loads the configured artifact, and renders predictions. · `app.py`
- **Ordered feature vector**: Inference contract · Nitrogen, phosphorus, potassium, temperature, humidity, pH, and rainfall.
- **Loaded classifier**: Python ML runtime · Deserialized artifact selected by app.py.
- **Crop recommendation**: Prediction result · Predicted crop label returned to the rendered page.

## Connections

- Crop recommendation data → Primary model development: training data
- Crop recommendation data → KNN experiment: training data
- Primary model development → Selected RF model: trains and serializes
- Primary model development → Serialized model: serializes
- KNN experiment → KNN model: trains and serializes
- UI styling → Crop input form: styles
- Crop input form → Application controller: submits seven inputs
- Application controller → Ordered feature vector: extracts in contract order
- Ordered feature vector → Loaded classifier: predicts with
- Selected RF model → Loaded classifier: possible loaded artifact · app.py determines the actual artifact.
- KNN model → Loaded classifier: possible loaded artifact · app.py determines the actual artifact.
- Serialized model → Loaded classifier: possible loaded artifact · app.py determines the actual artifact.
- Loaded classifier → Crop recommendation: predicts crop label
- Crop recommendation → Application controller: returned for rendering
- Application controller → Crop input form: renders result
