# thegit-69/cropsafe-ai architecture

> Architecture diagram of the GitHub repository thegit-69/cropsafe-ai, 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/thegit-69/cropsafe-ai
- Repository: https://github.com/thegit-69/cropsafe-ai

## Overview

CropSafe AI analyzes crop-leaf images for disease and accepts soil measurements for health scoring and fertilizer guidance. Its evidenced runtime workflow is a FastAPI request routed to crop preprocessing/model/recommendation or soil analysis/recommendation, then returned as structured output. The tree also contains a Flutter platform host and registered Firebase, file-selection, location, and sign-in plugins, but no Dart application source, so their user-interface behavior and connections to the API cannot be verified. The README describes broader pest/disease and nutrient detection; sampled crop classes specifically name diseases.

Main entry points: [`app/routes/crop_routes.py`](https://github.com/thegit-69/cropsafe-ai/blob/main/app/routes/crop_routes.py) (Crop endpoint), [`app/main.py`](https://github.com/thegit-69/cropsafe-ai/blob/main/app/main.py) (FastAPI app), [`cropsafe_app/android/app/src/main/kotlin/com/kalki/cropdoc/MainActivity.kt`](https://github.com/thegit-69/cropsafe-ai/blob/main/cropsafe_app/android/app/src/main/kotlin/com/kalki/cropdoc/MainActivity.kt) (Flutter platform host), [`app/routes/soil_routes.py`](https://github.com/thegit-69/cropsafe-ai/blob/main/app/routes/soil_routes.py) (Soil endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API runtime"]
  node_crop_req["Crop endpoint<br/>[crop_routes.py]"]
  node_soil_req["Soil endpoint<br/>[soil_routes.py]"]
  node_app["FastAPI app<br/>[main.py]"]
end

subgraph group_crop["Crop analysis"]
  node_crop_prep["Image preprocessing"]
  node_crop_model["Disease prediction<br/>[crop_model.py]"]
  node_crop_advice["Disease treatment"]
end

subgraph group_soil["Soil analysis"]
  node_soil_model["Soil scoring and fertilizer<br/>[soil_model.py]"]
  node_soil_advice["Soil recommendations"]
end

subgraph group_mobile["Mobile integrations"]
  node_mobile_host["Flutter platform host<br/>[MainActivity.kt]"]
  node_firebase["Firebase plugins"]
  node_signin["Google sign-in plugin"]
  node_location["Location plugin"]
  node_file_select["File selector plugin"]
end

node_farmer(("Farmer"))

node_farmer -.->|"submits image"| node_crop_req
node_farmer -.->|"submits soil data"| node_soil_req
node_app -->|"registers route"| node_crop_req
node_app -->|"registers route"| node_soil_req
node_app -->|"loads model"| node_crop_model
node_app -->|"loads model"| node_soil_model
node_crop_req -->|"preprocesses image"| node_crop_prep
node_crop_req -->|"predicts disease"| node_crop_model
node_crop_req -->|"gets treatment"| node_crop_advice
node_soil_req -->|"analyzes measurements"| node_soil_model
node_soil_req -->|"gets recommendations"| node_soil_advice
node_mobile_host -.->|"registers plugins"| node_firebase
node_mobile_host -.->|"registers plugins"| node_signin
node_mobile_host -.->|"registers plugins"| node_location
node_mobile_host -.->|"registers plugins"| node_file_select

click node_crop_req "https://github.com/thegit-69/cropsafe-ai/blob/main/app/routes/crop_routes.py"
click node_soil_req "https://github.com/thegit-69/cropsafe-ai/blob/main/app/routes/soil_routes.py"
click node_app "https://github.com/thegit-69/cropsafe-ai/blob/main/app/main.py"
click node_crop_prep "https://github.com/thegit-69/cropsafe-ai/blob/main/app/utils/image_preprocessing.py"
click node_crop_model "https://github.com/thegit-69/cropsafe-ai/blob/main/app/models/crop_model.py"
click node_crop_advice "https://github.com/thegit-69/cropsafe-ai/blob/main/app/services/recommendation_service.py"
click node_soil_model "https://github.com/thegit-69/cropsafe-ai/blob/main/app/models/soil_model.py"
click node_soil_advice "https://github.com/thegit-69/cropsafe-ai/blob/main/app/services/recommendation_service.py"
click node_mobile_host "https://github.com/thegit-69/cropsafe-ai/blob/main/cropsafe_app/android/app/src/main/kotlin/com/kalki/cropdoc/MainActivity.kt"
click node_firebase "https://github.com/thegit-69/cropsafe-ai/blob/main/cropsafe_app/macos/Flutter/GeneratedPluginRegistrant.swift"
click node_signin "https://github.com/thegit-69/cropsafe-ai/blob/main/cropsafe_app/macos/Flutter/GeneratedPluginRegistrant.swift"
click node_location "https://github.com/thegit-69/cropsafe-ai/blob/main/cropsafe_app/macos/Flutter/GeneratedPluginRegistrant.swift"
click node_file_select "https://github.com/thegit-69/cropsafe-ai/blob/main/cropsafe_app/macos/Flutter/GeneratedPluginRegistrant.swift"

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_crop_req,node_soil_req,node_app toneBlue
class node_crop_prep,node_crop_model,node_crop_advice toneAmber
class node_soil_model,node_soil_advice toneMint
class node_mobile_host,node_firebase,node_signin,node_location,node_file_select toneRose
class node_farmer toneIndigo
```

## Components

### API runtime

- [Crop endpoint](https://github.com/thegit-69/cropsafe-ai/blob/main/app/routes/crop_routes.py): `app/routes/crop_routes.py`
- [Soil endpoint](https://github.com/thegit-69/cropsafe-ai/blob/main/app/routes/soil_routes.py): `app/routes/soil_routes.py`
- [FastAPI app](https://github.com/thegit-69/cropsafe-ai/blob/main/app/main.py): `app/main.py`

### Crop analysis

- [Image preprocessing](https://github.com/thegit-69/cropsafe-ai/blob/main/app/utils/image_preprocessing.py): `app/utils/image_preprocessing.py`
- [Disease prediction](https://github.com/thegit-69/cropsafe-ai/blob/main/app/models/crop_model.py): `app/models/crop_model.py`
- [Disease treatment](https://github.com/thegit-69/cropsafe-ai/blob/main/app/services/recommendation_service.py): `app/services/recommendation_service.py`

### Soil analysis

- [Soil scoring and fertilizer](https://github.com/thegit-69/cropsafe-ai/blob/main/app/models/soil_model.py): `app/models/soil_model.py`
- [Soil recommendations](https://github.com/thegit-69/cropsafe-ai/blob/main/app/services/recommendation_service.py): `app/services/recommendation_service.py`

### Mobile integrations

- [Flutter platform host](https://github.com/thegit-69/cropsafe-ai/blob/main/cropsafe_app/android/app/src/main/kotlin/com/kalki/cropdoc/MainActivity.kt): `cropsafe_app/android/app/src/main/kotlin/com/kalki/cropdoc/MainActivity.kt`
- [Firebase plugins](https://github.com/thegit-69/cropsafe-ai/blob/main/cropsafe_app/macos/Flutter/GeneratedPluginRegistrant.swift): `cropsafe_app/macos/Flutter/GeneratedPluginRegistrant.swift`
- [Google sign-in plugin](https://github.com/thegit-69/cropsafe-ai/blob/main/cropsafe_app/macos/Flutter/GeneratedPluginRegistrant.swift): `cropsafe_app/macos/Flutter/GeneratedPluginRegistrant.swift`
- [Location plugin](https://github.com/thegit-69/cropsafe-ai/blob/main/cropsafe_app/macos/Flutter/GeneratedPluginRegistrant.swift): `cropsafe_app/macos/Flutter/GeneratedPluginRegistrant.swift`
- [File selector plugin](https://github.com/thegit-69/cropsafe-ai/blob/main/cropsafe_app/macos/Flutter/GeneratedPluginRegistrant.swift): `cropsafe_app/macos/Flutter/GeneratedPluginRegistrant.swift`

### Other components

- **Farmer**

## Connections

- Farmer → Crop endpoint: submits image
- Farmer → Soil endpoint: submits soil data
- FastAPI app → Crop endpoint: registers route (evidence: `app/main.py`)
- FastAPI app → Soil endpoint: registers route (evidence: `app/main.py`)
- FastAPI app → Disease prediction: loads model (evidence: `app/main.py`)
- FastAPI app → Soil scoring and fertilizer: loads model (evidence: `app/main.py`)
- Crop endpoint → Image preprocessing: preprocesses image (evidence: `app/routes/crop_routes.py`)
- Crop endpoint → Disease prediction: predicts disease (evidence: `app/routes/crop_routes.py`)
- Crop endpoint → Disease treatment: gets treatment (evidence: `app/routes/crop_routes.py`)
- Soil endpoint → Soil scoring and fertilizer: analyzes measurements (evidence: `app/routes/soil_routes.py`)
- Soil endpoint → Soil recommendations: gets recommendations (evidence: `app/routes/soil_routes.py`)
- Flutter platform host → Firebase plugins: registers plugins
- Flutter platform host → Google sign-in plugin: registers plugins
- Flutter platform host → Location plugin: registers plugins
- Flutter platform host → File selector plugin: registers plugins
