# darshantribhuwan/cep-project architecture

> Architecture diagram of the GitHub repository darshantribhuwan/cep-project, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/darshantribhuwan/cep-project
- Repository: https://github.com/darshantribhuwan/cep-project

## Overview

SAMPADA AI is a decision-support backend for Maharashtra smallholder farmers. Its main workflow is farmer authentication and farm setup, followed by soil and crop suitability analysis and recommendations, with live weather and market context; farmers can then record harvest outcomes for held-out evaluation and gated model promotion. Separate capabilities include localized package-of-practices guidance, security and retention, and honest provider-data handling. The README documents these capabilities; several route and service implementations were not excerpted, so their detailed call paths are not asserted.

Main entry points: [`sampada-ai/backend/app/main.py`](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/main.py) (HTTP application), [`sampada-ai/backend/app/services/recommendation.py`](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/services/recommendation.py) (Recommendation scoring), [`sampada-ai/backend/app/repositories/farms.py`](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/repositories/farms.py) (Farm records), [`sampada-ai/backend/app/api/evaluation.py`](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/evaluation.py) (Evaluation API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["API and identity"]
  node_api["HTTP application<br/>[main.py]"]
  node_auth["Authentication<br/>[auth.py]"]
  node_farm_api["Farm management<br/>[farmer.py]"]
  node_recommend_api["Recommendation API<br/>[recommendation.py]"]
  node_soil_api["Soil API<br/>[soil.py]"]
  node_weather_api["Weather API<br/>[weather.py]"]
  node_market_api["Market API<br/>[market.py]"]
  node_outcomes_api["Outcomes API<br/>[outcomes.py]"]
  node_evaluation_api["Evaluation API<br/>[evaluation.py]"]
end

subgraph group_advice["Farm decision support"]
  node_soil["Soil estimation<br/>[soil.py]"]
  node_suitability["Crop suitability<br/>[suitability.py]"]
  node_crops["Crop knowledge<br/>[crops.py]"]
  node_recommendation["Recommendation scoring<br/>[recommendation.py]"]
  node_practices["Practices and localization<br/>[community.py]"]
  node_prices["Price analysis<br/>[price.py]"]
end

subgraph group_feeds["External data"]
  node_weather["Weather provider<br/>[weather.py]"]
  node_market["Market provider<br/>[market.py]"]
  node_http["HTTP cache and retry<br/>[http.py]"]
end

subgraph group_learning["Outcomes and evaluation"]
  node_outcomes["Harvest outcomes<br/>[outcomes.py]"]
  node_heldout["Held-out evaluation<br/>[heldout.py]"]
  node_evidence["Factor evidence<br/>[factor_evidence.py]"]
  node_promotion["Promotion gates<br/>[promotion.py]"]
end

subgraph group_platform["Persistence and safeguards"]
  node_farms["Farm records<br/>[farms.py]"]
  node_farmers["Farmer accounts<br/>[farmers.py]"]
  node_db[("SQLite persistence<br/>[db.py]")]
  node_security["Encryption and config<br/>[crypto.py]"]
  node_retention["Retention policy<br/>[retention.py]"]
end

node_farmer(("Farmer"))
node_agmarknet["data.gov.in"]
node_openmeteo["Open-Meteo"]

node_farmer -->|"uses"| node_api
node_api -->|"routes"| node_auth
node_api -->|"routes"| node_farm_api
node_api -->|"routes"| node_recommend_api
node_api -->|"routes"| node_soil_api
node_api -->|"routes"| node_weather_api
node_api -->|"routes"| node_market_api
node_api -->|"routes"| node_outcomes_api
node_api -->|"routes"| node_evaluation_api
node_auth -->|"authenticates"| node_farmers
node_farm_api -->|"manages"| node_farms
node_farms -->|"persists"| node_db
node_farms -->|"encrypts locations"| node_security
node_farmers -->|"persists"| node_db
node_farmers -->|"protects identifiers"| node_security
node_soil_api -.->|"estimates"| node_soil
node_recommend_api -.->|"requests scoring"| node_recommendation
node_recommendation -->|"scores suitability"| node_suitability
node_recommendation -->|"uses crop data"| node_crops
node_recommendation -->|"uses soil estimate"| node_soil
node_recommendation -->|"uses price analysis"| node_prices
node_recommendation -->|"reads farm"| node_farms
node_recommendation -->|"uses guidance"| node_practices
node_suitability -->|"uses crop data"| node_crops
node_suitability -->|"uses forecast"| node_weather
node_weather_api -.->|"requests forecast"| node_weather
node_market_api -.->|"requests prices"| node_market
node_prices -->|"fetches prices"| node_market
node_market -->|"fetches feed"| node_agmarknet
node_weather -->|"fetches forecast"| node_openmeteo
node_market -->|"fetches via"| node_http
node_weather -->|"fetches via"| node_http
node_outcomes_api -.->|"records harvest"| node_farms
node_evaluation_api -->|"evaluates"| node_heldout
node_evaluation_api -->|"builds evidence"| node_evidence
node_evidence -->|"supplies factors"| node_heldout
node_evaluation_api -->|"checks promotion"| node_promotion
node_promotion -->|"gates on evaluation"| node_heldout
node_promotion -->|"stores decisions"| node_db
node_retention -->|"purges configured data"| node_db

click node_api "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/main.py"
click node_auth "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/auth.py"
click node_farm_api "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/farmer.py"
click node_recommend_api "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/recommendation.py"
click node_soil_api "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/soil.py"
click node_weather_api "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/weather.py"
click node_market_api "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/market.py"
click node_outcomes_api "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/outcomes.py"
click node_evaluation_api "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/evaluation.py"
click node_farms "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/repositories/farms.py"
click node_farmers "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/repositories/farmers.py"
click node_db "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/core/db.py"
click node_security "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/core/crypto.py"
click node_soil "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/services/soil.py"
click node_suitability "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/services/suitability.py"
click node_crops "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/services/crops.py"
click node_recommendation "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/services/recommendation.py"
click node_practices "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/services/community.py"
click node_weather "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/providers/weather.py"
click node_market "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/providers/market.py"
click node_http "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/providers/http.py"
click node_prices "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/services/price.py"
click node_outcomes "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/outcomes.py"
click node_heldout "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/evaluation/heldout.py"
click node_evidence "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/evaluation/factor_evidence.py"
click node_promotion "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/evaluation/promotion.py"
click node_retention "https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/core/retention.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,node_auth,node_farm_api,node_recommend_api,node_soil_api,node_weather_api,node_market_api,node_outcomes_api,node_evaluation_api toneBlue
class node_soil,node_suitability,node_crops,node_recommendation,node_practices,node_prices toneAmber
class node_weather,node_market,node_http toneMint
class node_outcomes,node_heldout,node_evidence,node_promotion toneRose
class node_farms,node_farmers,node_db,node_security,node_retention,node_farmer,node_agmarknet,node_openmeteo toneIndigo
```

## Components

### API and identity

- [HTTP application](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/main.py): `sampada-ai/backend/app/main.py`
- [Authentication](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/auth.py): `sampada-ai/backend/app/api/auth.py`
- [Farm management](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/farmer.py): `sampada-ai/backend/app/api/farmer.py`
- [Recommendation API](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/recommendation.py): `sampada-ai/backend/app/api/recommendation.py`
- [Soil API](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/soil.py): `sampada-ai/backend/app/api/soil.py`
- [Weather API](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/weather.py): `sampada-ai/backend/app/api/weather.py`
- [Market API](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/market.py): `sampada-ai/backend/app/api/market.py`
- [Outcomes API](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/outcomes.py): `sampada-ai/backend/app/api/outcomes.py`
- [Evaluation API](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/evaluation.py): `sampada-ai/backend/app/api/evaluation.py`

### Farm decision support

- [Soil estimation](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/services/soil.py): `sampada-ai/backend/app/services/soil.py`
- [Crop suitability](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/services/suitability.py): `sampada-ai/backend/app/services/suitability.py`
- [Crop knowledge](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/services/crops.py): `sampada-ai/backend/app/services/crops.py`
- [Recommendation scoring](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/services/recommendation.py): `sampada-ai/backend/app/services/recommendation.py`
- [Practices and localization](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/services/community.py): `sampada-ai/backend/app/services/community.py`
- [Price analysis](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/services/price.py): `sampada-ai/backend/app/services/price.py`

### External data

- [Weather provider](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/providers/weather.py): `sampada-ai/backend/app/providers/weather.py`
- [Market provider](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/providers/market.py): `sampada-ai/backend/app/providers/market.py`
- [HTTP cache and retry](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/providers/http.py): `sampada-ai/backend/app/providers/http.py`

### Outcomes and evaluation

- [Harvest outcomes](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/api/outcomes.py): `sampada-ai/backend/app/api/outcomes.py`
- [Held-out evaluation](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/evaluation/heldout.py): `sampada-ai/backend/app/evaluation/heldout.py`
- [Factor evidence](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/evaluation/factor_evidence.py): `sampada-ai/backend/app/evaluation/factor_evidence.py`
- [Promotion gates](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/evaluation/promotion.py): `sampada-ai/backend/app/evaluation/promotion.py`

### Persistence and safeguards

- [Farm records](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/repositories/farms.py): `sampada-ai/backend/app/repositories/farms.py`
- [Farmer accounts](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/repositories/farmers.py): `sampada-ai/backend/app/repositories/farmers.py`
- [SQLite persistence](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/core/db.py): `sampada-ai/backend/app/core/db.py`
- [Encryption and config](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/core/crypto.py): `sampada-ai/backend/app/core/crypto.py`
- [Retention policy](https://github.com/darshantribhuwan/cep-project/blob/main/sampada-ai/backend/app/core/retention.py): `sampada-ai/backend/app/core/retention.py`

### Other components

- **Farmer**
- **data.gov.in**
- **Open-Meteo**

## Connections

- Farmer → HTTP application: uses (evidence: `README.md`)
- HTTP application → Authentication: routes (evidence: `sampada-ai/backend/app/main.py`)
- HTTP application → Farm management: routes (evidence: `sampada-ai/backend/app/main.py`)
- HTTP application → Recommendation API: routes (evidence: `sampada-ai/backend/app/main.py`)
- HTTP application → Soil API: routes (evidence: `sampada-ai/backend/app/main.py`)
- HTTP application → Weather API: routes (evidence: `sampada-ai/backend/app/main.py`)
- HTTP application → Market API: routes (evidence: `sampada-ai/backend/app/main.py`)
- HTTP application → Outcomes API: routes (evidence: `sampada-ai/backend/app/main.py`)
- HTTP application → Evaluation API: routes (evidence: `sampada-ai/backend/app/main.py`)
- Authentication → Farmer accounts: authenticates (evidence: `sampada-ai/backend/app/api/auth.py`)
- Farm management → Farm records: manages (evidence: `sampada-ai/backend/app/api/farmer.py`)
- Farm records → SQLite persistence: persists (evidence: `sampada-ai/backend/app/repositories/farms.py`)
- Farm records → Encryption and config: encrypts locations (evidence: `sampada-ai/backend/app/repositories/farms.py`)
- Farmer accounts → SQLite persistence: persists (evidence: `sampada-ai/backend/app/repositories/farmers.py`)
- Farmer accounts → Encryption and config: protects identifiers (evidence: `sampada-ai/backend/app/repositories/farmers.py`)
- Soil API → Soil estimation: estimates
- Recommendation API → Recommendation scoring: requests scoring
- Recommendation scoring → Crop suitability: scores suitability (evidence: `sampada-ai/backend/app/services/recommendation.py`)
- Recommendation scoring → Crop knowledge: uses crop data (evidence: `sampada-ai/backend/app/services/recommendation.py`)
- Recommendation scoring → Soil estimation: uses soil estimate (evidence: `sampada-ai/backend/app/services/recommendation.py`)
- Recommendation scoring → Price analysis: uses price analysis (evidence: `sampada-ai/backend/app/services/recommendation.py`)
- Recommendation scoring → Farm records: reads farm (evidence: `sampada-ai/backend/app/services/recommendation.py`)
- Recommendation scoring → Practices and localization: uses guidance (evidence: `sampada-ai/backend/app/services/recommendation.py`)
- Crop suitability → Crop knowledge: uses crop data (evidence: `sampada-ai/backend/app/services/suitability.py`)
- Crop suitability → Weather provider: uses forecast (evidence: `sampada-ai/backend/app/services/suitability.py`)
- Weather API → Weather provider: requests forecast
- Market API → Market provider: requests prices
- Price analysis → Market provider: fetches prices (evidence: `sampada-ai/backend/app/services/price.py`)
- Market provider → data.gov.in: fetches feed (evidence: `sampada-ai/backend/app/providers/market.py`)
- Weather provider → Open-Meteo: fetches forecast (evidence: `README.md`)
- Market provider → HTTP cache and retry: fetches via (evidence: `sampada-ai/backend/app/providers/market.py`)
- Weather provider → HTTP cache and retry: fetches via (evidence: `sampada-ai/backend/app/providers/weather.py`)
- Outcomes API → Farm records: records harvest
- Evaluation API → Held-out evaluation: evaluates (evidence: `sampada-ai/backend/app/api/evaluation.py`)
- Evaluation API → Factor evidence: builds evidence (evidence: `sampada-ai/backend/app/api/evaluation.py`)
- Factor evidence → Held-out evaluation: supplies factors (evidence: `sampada-ai/backend/app/evaluation/factor_evidence.py`)
- Evaluation API → Promotion gates: checks promotion (evidence: `sampada-ai/backend/app/api/evaluation.py`)
- Promotion gates → Held-out evaluation: gates on evaluation (evidence: `sampada-ai/backend/app/evaluation/promotion.py`)
- Promotion gates → SQLite persistence: stores decisions (evidence: `sampada-ai/backend/app/evaluation/promotion.py`)
- Retention policy → SQLite persistence: purges configured data (evidence: `sampada-ai/backend/app/core/retention.py`)
