# mureri-hilary-99/smart-agriculture-system architecture

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

- Interactive diagram: https://gitdiagram.com/mureri-hilary-99/smart-agriculture-system
- Repository: https://github.com/mureri-hilary-99/smart-agriculture-system

## Overview

This is a crop decision-support product: farmers provide soil and climate measurements, the API validates them, and a Random Forest service returns a crop recommendation, confidence, and alternatives. Model training is a separate lifecycle stage that produces the artifact used for inference. The README documents a Next.js dashboard, but the supplied tree contains no dashboard source beyond its environment example; IoT and database integration are explicitly planned, not implemented. Relationships shown are supported by excerpts or README statements.

Main entry points: [`backend/app/main.py`](https://github.com/mureri-hilary-99/smart-agriculture-system/blob/main/backend/app/main.py) (FastAPI application), [`backend/app/routers/prediction.py`](https://github.com/mureri-hilary-99/smart-agriculture-system/blob/main/backend/app/routers/prediction.py) (Prediction endpoint), [`frontend`](https://github.com/mureri-hilary-99/smart-agriculture-system/tree/main/frontend) (Farmer dashboard), [`backend/app/services/crop_service.py`](https://github.com/mureri-hilary-99/smart-agriculture-system/blob/main/backend/app/services/crop_service.py) (Recommendation inference)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Farmer interface"]
  node_dashboard["Farmer dashboard"]
end

subgraph group_api["Recommendation API"]
  node_api_entry["FastAPI application<br/>[main.py]"]
  node_settings["Application settings<br/>[config.py]"]
  node_prediction_route["Prediction endpoint<br/>[prediction.py]"]
  node_crop_schema["Input and output schemas<br/>[crop.py]"]
end

subgraph group_ml["Model lifecycle"]
  node_recommendation_service["Recommendation inference<br/>[crop_service.py]"]
  node_training["Random Forest training<br/>[train_model.py]"]
  node_model_artifact["Trained model artifact"]
end

node_farmer(("Farmer"))

node_farmer -->|"enters conditions"| node_dashboard
node_dashboard -->|"submits measurements"| node_api_entry
node_api_entry -->|"configures from"| node_settings
node_api_entry -->|"registers route"| node_prediction_route
node_prediction_route -->|"validates and formats"| node_crop_schema
node_prediction_route -->|"requests prediction"| node_recommendation_service
node_recommendation_service -->|"loads for inference"| node_model_artifact
node_training -->|"saves trained model"| node_model_artifact

click node_dashboard "https://github.com/mureri-hilary-99/smart-agriculture-system/tree/main/frontend"
click node_api_entry "https://github.com/mureri-hilary-99/smart-agriculture-system/blob/main/backend/app/main.py"
click node_settings "https://github.com/mureri-hilary-99/smart-agriculture-system/blob/main/backend/app/core/config.py"
click node_prediction_route "https://github.com/mureri-hilary-99/smart-agriculture-system/blob/main/backend/app/routers/prediction.py"
click node_crop_schema "https://github.com/mureri-hilary-99/smart-agriculture-system/blob/main/backend/app/schemas/crop.py"
click node_recommendation_service "https://github.com/mureri-hilary-99/smart-agriculture-system/blob/main/backend/app/services/crop_service.py"
click node_training "https://github.com/mureri-hilary-99/smart-agriculture-system/blob/main/backend/app/ml/train_model.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_dashboard toneBlue
class node_api_entry,node_settings,node_prediction_route,node_crop_schema toneAmber
class node_recommendation_service,node_training,node_model_artifact toneMint
class node_farmer toneIndigo
```

## Components

### Farmer interface

- [Farmer dashboard](https://github.com/mureri-hilary-99/smart-agriculture-system/tree/main/frontend): `frontend`

### Recommendation API

- [FastAPI application](https://github.com/mureri-hilary-99/smart-agriculture-system/blob/main/backend/app/main.py): `backend/app/main.py`
- [Application settings](https://github.com/mureri-hilary-99/smart-agriculture-system/blob/main/backend/app/core/config.py): `backend/app/core/config.py`
- [Prediction endpoint](https://github.com/mureri-hilary-99/smart-agriculture-system/blob/main/backend/app/routers/prediction.py): `backend/app/routers/prediction.py`
- [Input and output schemas](https://github.com/mureri-hilary-99/smart-agriculture-system/blob/main/backend/app/schemas/crop.py): `backend/app/schemas/crop.py`

### Model lifecycle

- [Recommendation inference](https://github.com/mureri-hilary-99/smart-agriculture-system/blob/main/backend/app/services/crop_service.py): `backend/app/services/crop_service.py`
- [Random Forest training](https://github.com/mureri-hilary-99/smart-agriculture-system/blob/main/backend/app/ml/train_model.py): `backend/app/ml/train_model.py`
- **Trained model artifact**

### Other components

- **Farmer**

## Connections

- Farmer → Farmer dashboard: enters conditions (evidence: `README.md`)
- Farmer dashboard → FastAPI application: submits measurements (evidence: `README.md`)
- FastAPI application → Application settings: configures from (evidence: `backend/app/main.py`)
- FastAPI application → Prediction endpoint: registers route (evidence: `backend/app/main.py`)
- Prediction endpoint → Input and output schemas: validates and formats (evidence: `backend/app/routers/prediction.py`)
- Prediction endpoint → Recommendation inference: requests prediction (evidence: `backend/app/routers/prediction.py`)
- Recommendation inference → Trained model artifact: loads for inference (evidence: `backend/app/services/crop_service.py`)
- Random Forest training → Trained model artifact: saves trained model (evidence: `backend/app/ml/train_model.py`)
