# kanavkapoor05/ai-crop-yield-backend architecture

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

- Interactive diagram: https://gitdiagram.com/kanavkapoor05/ai-crop-yield-backend
- Repository: https://github.com/kanavkapoor05/ai-crop-yield-backend

## Overview

This is a FastAPI crop-analysis API with signup/login, protected yield prediction, and protected crop-image analysis. The main workflow is a user request reaching an API route, passing authentication where required, then producing a prediction or image-based diagnosis. The excerpts show MongoDB user access, JWT/password helpers, and the yield model load and prediction path. Recommendation logic is partly elided, and no README is provided, so the graph reflects only documented or excerpted behavior.

Main entry points: [`app.py`](https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/app.py) (API routes), [`database.py`](https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/database.py) (User collection), [`schemas.py`](https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/schemas.py) (Request schemas), [`auth.py`](https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/auth.py) (Auth helpers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API workflows"]
  node_api_routes["API routes<br/>[app.py]"]
  node_schemas["Request schemas<br/>[schemas.py]"]
end

subgraph group_identity["Identity and users"]
  node_auth_helpers["Auth helpers<br/>[auth.py]"]
  node_user_store[("User collection<br/>[database.py]")]
  node_utility_helpers["Utility helpers<br/>[utils.py]"]
end

subgraph group_analysis["Crop analysis"]
  node_yield_input["Yield input<br/>[app.py]"]
  node_yield_model["Yield model"]
  node_yield_prediction["Yield prediction<br/>[app.py]"]
  node_yield_recommendations["Yield recommendations<br/>[app.py]"]
  node_image_upload["Image upload<br/>[app.py]"]
  node_image_analysis["Image analysis<br/>[app.py]"]
end

node_user(("User"))
node_mongodb[("MongoDB")]

node_user -->|"sends requests"| node_api_routes
node_api_routes -->|"uses models"| node_schemas
node_api_routes -->|"calls helpers"| node_auth_helpers
node_api_routes -->|"reads and writes"| node_user_store
node_user_store -->|"stores users"| node_mongodb
node_api_routes -->|"accepts input"| node_yield_input
node_api_routes -->|"runs prediction"| node_yield_prediction
node_yield_prediction -->|"loads and predicts"| node_yield_model
node_yield_prediction -->|"builds guidance"| node_yield_recommendations
node_api_routes -->|"accepts image"| node_image_upload
node_image_upload -->|"analyzes image"| node_image_analysis

click node_api_routes "https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/app.py"
click node_schemas "https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/schemas.py"
click node_auth_helpers "https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/auth.py"
click node_user_store "https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/database.py"
click node_utility_helpers "https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/utils.py"
click node_yield_input "https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/app.py"
click node_yield_model "https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/crop_yield_model.json"
click node_yield_prediction "https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/app.py"
click node_yield_recommendations "https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/app.py"
click node_image_upload "https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/app.py"
click node_image_analysis "https://github.com/kanavkapoor05/ai-crop-yield-backend/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_api_routes,node_schemas,node_user toneBlue
class node_auth_helpers,node_user_store,node_utility_helpers,node_mongodb toneAmber
class node_yield_input,node_yield_model,node_yield_prediction,node_yield_recommendations,node_image_upload,node_image_analysis toneMint
```

## Components

### API workflows

- [API routes](https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/app.py): `app.py`
- [Request schemas](https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/schemas.py): `schemas.py`

### Identity and users

- [Auth helpers](https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/auth.py): `auth.py`
- [User collection](https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/database.py): `database.py`
- [Utility helpers](https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/utils.py): `utils.py`

### Crop analysis

- [Yield input](https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/app.py): `app.py`
- [Yield model](https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/crop_yield_model.json): `crop_yield_model.json`
- [Yield prediction](https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/app.py): `app.py`
- [Yield recommendations](https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/app.py): `app.py`
- [Image upload](https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/app.py): `app.py`
- [Image analysis](https://github.com/kanavkapoor05/ai-crop-yield-backend/blob/main/app.py): `app.py`

### Other components

- **User**
- **MongoDB**

## Connections

- User → API routes: sends requests (evidence: `app.py`)
- API routes → Request schemas: uses models (evidence: `app.py`)
- API routes → Auth helpers: calls helpers (evidence: `app.py`)
- API routes → User collection: reads and writes (evidence: `app.py`)
- User collection → MongoDB: stores users (evidence: `database.py`)
- API routes → Yield input: accepts input (evidence: `app.py`)
- API routes → Yield prediction: runs prediction (evidence: `app.py`)
- Yield prediction → Yield model: loads and predicts (evidence: `app.py`)
- Yield prediction → Yield recommendations: builds guidance (evidence: `app.py`)
- API routes → Image upload: accepts image (evidence: `app.py`)
- Image upload → Image analysis: analyzes image (evidence: `app.py`)
