# prithiga06/sugarcane-crop-detection architecture

> Architecture diagram of the GitHub repository prithiga06/sugarcane-crop-detection, 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/prithiga06/sugarcane-crop-detection
- Repository: https://github.com/prithiga06/sugarcane-crop-detection

## Overview

Sugarcane AI Guard is a mobile-first web system for sugarcane leaf diagnosis and farmer guidance. Farmers submit a photo through the web UI; the API validates it, classifies the condition (with a demo fallback), estimates visible severity, and returns recommendations. The UI also supports localized content, scan history, feedback, and agronomist review. Model training and evaluation are a separate supporting lifecycle. Edges reflect README statements and SOURCE INDEX references; unsampled modules are included where documented, but their internal calls are not inferred.

Main entry points: [`backend/app/ml/inference.py`](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/ml/inference.py) (Disease Inference), [`frontend/js/api.js`](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/api.js) (REST Client), [`backend/app/main.py`](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/main.py) (FastAPI Routes), [`frontend/js/components/uploader.js`](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/components/uploader.js) (Photo Uploader)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Farmer Web UI"]
  node_controller["App Controller<br/>[app.js]"]
  node_uploader["Photo Uploader<br/>[uploader.js]"]
  node_results["Diagnosis Results<br/>[results.js]"]
  node_recommendation_ui["Guidance Cards<br/>[recommendations.js]"]
  node_history_ui["Scan History<br/>[history.js]"]
  node_feedback_ui["Farmer Feedback<br/>[feedback.js]"]
  node_admin_ui["Agronomist Review<br/>[admin.js]"]
  node_i18n_ui["Language UI<br/>[i18n.js]"]
  node_api_client["REST Client<br/>[api.js]"]
end

subgraph group_api["API and Contracts"]
  node_http_api["FastAPI Routes<br/>[main.py]"]
  node_contracts["API Schemas<br/>[api_models.py]"]
  node_config["Runtime Configuration<br/>[config.py]"]
end

subgraph group_diagnosis["Diagnosis and Guidance"]
  node_quality["Image Quality Check<br/>[quality.py]"]
  node_inference["Disease Inference<br/>[inference.py]"]
  node_severity["Severity and Overlay<br/>[severity.py]"]
  node_guidance["Agronomic Rules<br/>[recommendations.py]"]
  node_translations["Backend Translations<br/>[translations.py]"]
end

subgraph group_ml["Model Lifecycle"]
  node_model["MobileNetV2 Model<br/>[model.py]"]
  node_training["Model Training<br/>[train.py]"]
  node_evaluation["Model Evaluation<br/>[evaluate.py]"]
  node_dataset["Dataset Utilities<br/>[dataset_utils.py]"]
end

subgraph group_records["History and Review"]
  node_database[("SQLite Records<br/>[database.py]")]
  node_seeding["Demo Record Seeding<br/>[seed_data.py]"]
end

node_farmer(("Farmer or Agronomist"))

node_farmer -->|"submits photo"| node_uploader
node_controller -->|"coordinates"| node_uploader
node_uploader -->|"sends image"| node_api_client
node_api_client -->|"calls REST"| node_http_api
node_http_api -->|"runs diagnosis"| node_inference
node_inference -->|"checks quality"| node_quality
node_inference -->|"loads classifier"| node_model
node_inference -->|"estimates severity"| node_severity
node_inference -->|"gets guidance"| node_guidance
node_http_api -->|"stores and reads"| node_database
node_http_api -->|"serves strings"| node_translations
node_http_api -->|"validates responses"| node_contracts
node_inference -->|"builds response"| node_contracts
node_http_api -->|"uses settings"| node_config
node_inference -->|"reads thresholds"| node_config
node_results -->|"renders response"| node_api_client
node_recommendation_ui -->|"renders guidance"| node_api_client
node_controller -->|"coordinates language"| node_i18n_ui
node_history_ui -->|"requests history"| node_api_client
node_feedback_ui -->|"submits feedback"| node_api_client
node_admin_ui -->|"requests review"| node_api_client
node_training -->|"trains architecture"| node_model
node_evaluation -->|"evaluates architecture"| node_model
node_seeding -->|"seeds records"| node_database

click node_controller "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/app.js"
click node_uploader "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/components/uploader.js"
click node_results "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/components/results.js"
click node_recommendation_ui "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/components/recommendations.js"
click node_history_ui "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/components/history.js"
click node_feedback_ui "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/components/feedback.js"
click node_admin_ui "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/components/admin.js"
click node_i18n_ui "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/i18n.js"
click node_api_client "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/api.js"
click node_http_api "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/main.py"
click node_contracts "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/schemas/api_models.py"
click node_config "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/config.py"
click node_quality "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/core/quality.py"
click node_inference "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/ml/inference.py"
click node_severity "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/core/severity.py"
click node_guidance "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/core/recommendations.py"
click node_translations "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/core/translations.py"
click node_model "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/ml/model.py"
click node_training "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/ml/train.py"
click node_evaluation "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/ml/evaluate.py"
click node_dataset "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/ml/dataset_utils.py"
click node_database "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/database.py"
click node_seeding "https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/seed_data.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_controller,node_uploader,node_results,node_recommendation_ui,node_history_ui,node_feedback_ui,node_admin_ui,node_i18n_ui,node_api_client toneBlue
class node_http_api,node_contracts,node_config toneAmber
class node_quality,node_inference,node_severity,node_guidance,node_translations toneMint
class node_model,node_training,node_evaluation,node_dataset toneRose
class node_database,node_seeding,node_farmer toneIndigo
```

## Components

### Farmer Web UI

- [App Controller](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/app.js): `frontend/js/app.js`
- [Photo Uploader](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/components/uploader.js): `frontend/js/components/uploader.js`
- [Diagnosis Results](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/components/results.js): `frontend/js/components/results.js`
- [Guidance Cards](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/components/recommendations.js): `frontend/js/components/recommendations.js`
- [Scan History](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/components/history.js): `frontend/js/components/history.js`
- [Farmer Feedback](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/components/feedback.js): `frontend/js/components/feedback.js`
- [Agronomist Review](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/components/admin.js): `frontend/js/components/admin.js`
- [Language UI](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/i18n.js): `frontend/js/i18n.js`
- [REST Client](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/frontend/js/api.js): `frontend/js/api.js`

### API and Contracts

- [FastAPI Routes](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/main.py): `backend/app/main.py`
- [API Schemas](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/schemas/api_models.py): `backend/app/schemas/api_models.py`
- [Runtime Configuration](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/config.py): `backend/app/config.py`

### Diagnosis and Guidance

- [Image Quality Check](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/core/quality.py): `backend/app/core/quality.py`
- [Disease Inference](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/ml/inference.py): `backend/app/ml/inference.py`
- [Severity and Overlay](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/core/severity.py): `backend/app/core/severity.py`
- [Agronomic Rules](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/core/recommendations.py): `backend/app/core/recommendations.py`
- [Backend Translations](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/core/translations.py): `backend/app/core/translations.py`

### Model Lifecycle

- [MobileNetV2 Model](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/ml/model.py): `backend/app/ml/model.py`
- [Model Training](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/ml/train.py): `backend/app/ml/train.py`
- [Model Evaluation](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/ml/evaluate.py): `backend/app/ml/evaluate.py`
- [Dataset Utilities](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/ml/dataset_utils.py): `backend/app/ml/dataset_utils.py`

### History and Review

- [SQLite Records](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/database.py): `backend/app/database.py`
- [Demo Record Seeding](https://github.com/prithiga06/sugarcane-crop-detection/blob/main/backend/app/seed_data.py): `backend/app/seed_data.py`

### Other components

- **Farmer or Agronomist**

## Connections

- Farmer or Agronomist → Photo Uploader: submits photo (evidence: `README.md`)
- App Controller → Photo Uploader: coordinates (evidence: `README.md`)
- Photo Uploader → REST Client: sends image (evidence: `README.md`)
- REST Client → FastAPI Routes: calls REST (evidence: `README.md`)
- FastAPI Routes → Disease Inference: runs diagnosis (evidence: `backend/app/main.py`)
- Disease Inference → Image Quality Check: checks quality (evidence: `backend/app/ml/inference.py`)
- Disease Inference → MobileNetV2 Model: loads classifier (evidence: `backend/app/ml/inference.py`)
- Disease Inference → Severity and Overlay: estimates severity (evidence: `backend/app/ml/inference.py`)
- Disease Inference → Agronomic Rules: gets guidance (evidence: `backend/app/ml/inference.py`)
- FastAPI Routes → SQLite Records: stores and reads (evidence: `backend/app/main.py`)
- FastAPI Routes → Backend Translations: serves strings (evidence: `backend/app/main.py`)
- FastAPI Routes → API Schemas: validates responses (evidence: `backend/app/main.py`)
- Disease Inference → API Schemas: builds response (evidence: `backend/app/ml/inference.py`)
- FastAPI Routes → Runtime Configuration: uses settings (evidence: `backend/app/main.py`)
- Disease Inference → Runtime Configuration: reads thresholds (evidence: `backend/app/ml/inference.py`)
- Diagnosis Results → REST Client: renders response (evidence: `README.md`)
- Guidance Cards → REST Client: renders guidance (evidence: `README.md`)
- App Controller → Language UI: coordinates language (evidence: `README.md`)
- Scan History → REST Client: requests history (evidence: `README.md`)
- Farmer Feedback → REST Client: submits feedback (evidence: `README.md`)
- Agronomist Review → REST Client: requests review (evidence: `README.md`)
- Model Training → MobileNetV2 Model: trains architecture (evidence: `backend/app/ml/train.py`)
- Model Evaluation → MobileNetV2 Model: evaluates architecture (evidence: `backend/app/ml/evaluate.py`)
- Demo Record Seeding → SQLite Records: seeds records (evidence: `backend/app/seed_data.py`)
