Skip to content

aman7554/agri

ย 
ย 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1,474 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐ŸŒฑ Fasal Saathi

NSoC 2026

๐Ÿš€ This project is a part of Nexus Spring of Code (NSoC) 2026


๐Ÿ“˜ Nexus Spring of Code 2026

This repository is officially participating in Nexus Spring of Code 2026 (NSoC'26).

We welcome contributors from the NSoC program to collaborate and improve this project.

๐Ÿง‘โ€๐Ÿ’ป For Contributors

  • Pick an issue labeled with level1, level2, or level3 or raise an issue
  • Ask to be assigned before starting work
  • Submit a Pull Request with NSoC'26 in the title
  • Follow proper contribution guidelines

๐Ÿ“Œ Contribution Rules (NSoC Specific)

  • โœ… PR must include NSoC'26 tag
  • โœ… Issue must be assigned before PR
  • โŒ PR without assignment will be closed
  • โŒ Inactive contributors (7 days) may be unassigned

๐Ÿท๏ธ Issue Labels

  • level1 โ€” Beginner (level 1)
  • level2 โ€” Intermediate (level 2)
  • level3 โ€” Advanced (level 3)

โš ๏ธ Note

This project follows all rules and guidelines defined under the Nexus Spring of Code 2026 program.

Any misuse, spam, or low-quality contributions will not be accepted.


๐ŸŒพ Fasal Saathi

Fasal Saathi is a smart agriculture assistance platform built with React (frontend), Python (backend) and Firebase (database/auth). The app delivers crop recommendations, weather-based alerts, soil health analysis, and fertilizer guidance to help farmers make informed decisions.


๐Ÿš€ Features

  • ๐ŸŒฑ Crop recommendation based on soil profile and regional climate
  • โ˜๏ธ Real-time weather updates and custom farming alerts
  • ๐Ÿงช Soil health analysis & nutrient suggestions
  • ๐Ÿชด AI-based crop disease detection from uploaded images
  • ๐ŸŒพ Fertilizer and pesticide guidance
  • ๐Ÿงช A/B testing runner with traffic split, metrics pipeline, and auto-promotion
  • ๐Ÿ“Š Responsive and user-friendly dashboard (React)
  • ๐Ÿ” Authentication & user profiles (Firebase)
  • ๐ŸŒ Multi-language support (planned / optional)

๐Ÿ› ๏ธ Tech Stack

  • Frontend: React.js (Vite)
  • Backend: Python (FastAPI)
  • Database: Firebase (Firestore / Realtime DB)
  • Auth: Firebase Authentication
  • External APIs: Weather API (e.g., OpenWeatherMap), Soil/Agro data APIs
  • Deployment: Vercel (frontend), Render (backend - in process)

๐Ÿ“ Project Structure

agri/
โ”œโ”€โ”€ frontend/                 # React frontend application
โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”œโ”€โ”€ services/
โ”‚   โ”œโ”€โ”€ hooks/
โ”‚   โ”œโ”€โ”€ utils/
โ”‚   โ”œโ”€โ”€ stores/
โ”‚   โ”œโ”€โ”€ locales/
โ”‚   โ”œโ”€โ”€ weather/
โ”‚   โ””โ”€โ”€ public/
โ”‚
โ”œโ”€โ”€ backend/                  # Backend APIs and routers
โ”‚   โ”œโ”€โ”€ routers/
โ”‚   โ””โ”€โ”€ schemas/
โ”‚
โ”œโ”€โ”€ ml/                       # Machine learning pipelines and models
โ”‚   โ”œโ”€โ”€ adapters/
โ”‚   โ””โ”€โ”€ governance/
โ”‚
โ”œโ”€โ”€ rag/                      # Retrieval-Augmented Generation modules
โ”‚
โ”œโ”€โ”€ tests/                    # Backend test suite
โ”œโ”€โ”€ scripts/                  # Automation and utility scripts
โ”œโ”€โ”€ docs/                     # Project documentation
โ”œโ”€โ”€ persistence/              # Database and migration logic
โ”œโ”€โ”€ feature_flags/            # Feature flag and A/B testing system
โ”œโ”€โ”€ routers/                  # Additional ML routers
โ”œโ”€โ”€ inference/                # ONNX inference runtime
โ”œโ”€โ”€ benchmarks/               # Benchmarking scripts
โ”œโ”€โ”€ configs/                  # Configuration files
โ”œโ”€โ”€ runs/                     # ML run manifests
โ”œโ”€โ”€ runs_test/                # Test run manifests
โ”œโ”€โ”€ .github/                  # GitHub workflows and templates
โ”‚
โ”œโ”€โ”€ main.py
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ package.json
โ”œโ”€โ”€ README.md
โ””โ”€โ”€ CONTRIBUTING.md

1. Clone Repository

git clone https://github.com/Eshajha19/agri.git

```bash
cd frontend

Install Dependencies

npm install

Start Dev Server

npm run dev

Build for Production

npm run build

Preview Production Build

npm run preview

3. Backend (Python โ€” FastAPI)

cd ..

Create Virtual Environment (Optional)

python -m venv venv
# Windows:
venv\Scripts\activate
# Linux/Mac:
source venv/bin/activate

Install Dependencies

pip install -r requirements.txt

Run FastAPI Server

python -m uvicorn main:app --reload --port 8000

4. Firebase Setup

  1. Create a Firebase project at Firebase Console
  2. Enable Firestore (or Realtime DB) and Firebase Auth (Email/Phone)
  3. Add Firebase config to frontend .env file (see .env.example)
  4. (Optional) Deploy security rules found in firebase/

๐Ÿ” Environment Variables (.env.example)

Backend

WEATHER_API_KEY=your_weather_api_key
SOIL_API_KEY=your_soil_api_key
FIREBASE_ADMIN_CRED=/path/to/serviceAccountKey.json
BACKEND_PORT=5000

Frontend

REACT_APP_FIREBASE_API_KEY=xxxxxxxxxxxx
REACT_APP_FIREBASE_AUTH_DOMAIN=your-app.firebaseapp.com
REACT_APP_FIREBASE_PROJECT_ID=your-app
VITE_API_BASE_URL=https://your-backend.onrender.com
# Alternative: VITE_BACKEND_URL is also supported as a fallback

For Vercel deployments, set `VITE_API_BASE_URL` to the live backend origin in the project environment variables. Without it, browser requests stay on the static frontend host and marketplace API calls will fail.

For certified/bank report generation, the backend also needs a signing key source. In production, configure either Google Cloud Secret Manager (`GOOGLE_CLOUD_PROJECT` + `REPORT_SIGNING_SECRET_NAME`) or `REPORT_SIGNING_PRIVATE_KEY_PEM` with a PEM-encoded Ed25519 private key.

---

## ๐Ÿงฉ API Endpoints (Examples)

### Backend (FastAPI)

- `GET /api/weather?lat={lat}&lon={lon}` โ€” Returns current weather + forecast
- `POST /api/soil/analyze` โ€” Send soil params (pH, NPK) to get recommendations
- `POST /api/crop/recommend` โ€” Returns recommended crops for given soil & climate
- `POST /api/crop-disease/analyze-image` โ€” Analyze an uploaded crop image and return the likely disease, confidence, and treatment guidance
- `POST /api/experiments/{exp_id}/traffic-split` โ€” Update experiment traffic split for A/B testing
- `POST /api/experiments/{exp_id}/evaluate` โ€” Evaluate experiment metrics and auto-promote a winner when the lift is clear
- `POST /api/experiments/assign` โ€” Assign a user to a variant and emit an impression event

(Document exact request/response schemas in docs/ or OpenAPI spec.)

---

## ๐Ÿš€ Render Deployment Guide

This project can be deployed easily on [Render](https://render.com) for production hosting.

### 1๏ธโƒฃ Create a Render Service
- Log in to [Render Dashboard](https://render.com).
- Click **New + โ†’ Web Service**.
- Connect your GitHub repository.
- Select the branch you want to deploy (usually `main`).
- Choose environment: **Python 3.11** (or your projectโ€™s version).

---

### 2๏ธโƒฃ Build Command
Render will run this to install dependencies and build the frontend:

```bash
pip install -r requirements.txt
npm install --prefix frontend && npm run build --prefix frontend

---

### 3๏ธโƒฃ Start Command
Render will run this to start the backend service:

bash
uvicorn main:app --host 0.0.0.0 --port $PORT

### 4๏ธโƒฃ Required Environment Variables
Set these in Render โ†’ Settings โ†’ Environment Variables:

Backend
env
WEATHER_API_KEY=your_weather_api_key
SOIL_API_KEY=your_soil_api_key
FIREBASE_ADMIN_CRED=/path/to/serviceAccountKey.json
BACKEND_PORT=5000

Frontend
env
VITE_FIREBASE_API_KEY=xxxxxxxxxxxx
VITE_FIREBASE_AUTH_DOMAIN=your-app.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=your-app
VITE_FIREBASE_STORAGE_BUCKET=your-app.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=123456789
VITE_FIREBASE_APP_ID=1:123456789:web:abcdef
VITE_BACKEND_URL=https://your-render-service.onrender.com

## ๐Ÿงช Testing

- Frontend: use Vitest / React Testing Library
- Backend: pytest / unittest
- Add CI with GitHub Actions for linting + tests + deploy

## ๐Ÿ”’ Security CI

The repository now includes a dedicated security gate for secret scanning, dependency SCA, and policy enforcement.

Local policy check:

```bash
python scripts/security_ci.py policy --root . --policy .github/security-policy.json

The GitHub Actions workflow at .github/workflows/security-ci.yml runs:

  • secret scanning and repository policy enforcement via scripts/security_ci.py
  • dependency SCA via pip-audit and safety

Test fixtures are excluded from the secret scan so synthetic examples in the test suite do not fail the gate.

๐Ÿ”’ Differential Privacy (DP-SGD) Proof of Concept

Yield model training now supports an optional differential privacy mode.

What is included

  • training_mode=dp_sgd in train_model.py using optional torch + opacus
  • Configurable privacy targets via epsilon and delta
  • Privacy accounting logs during training (target epsilon, spent epsilon, noise multiplier)
  • Manifest/registry metadata now include privacy fields when DP mode is used
  • A reproducible comparison script to evaluate baseline vs DP utility

DP config example

{
	"dataset": "Train.csv",
	"seed": 42,
	"training_mode": "dp_sgd",
	"epsilon": 3.0,
	"delta": 0.00001,
	"dp_epochs": 8,
	"dp_batch_size": 64,
	"dp_learning_rate": 0.05,
	"dp_max_grad_norm": 1.0,
	"output_model": "yield_model_dp.pt"
}

Baseline config example

{
	"dataset": "Train.csv",
	"seed": 42,
	"training_mode": "baseline",
	"output_model": "yield_model.joblib"
}

Run reproducible utility comparison

python scripts/compare_dp_utility.py --dataset Train.csv --epsilon 3.0 --delta 1e-5 --seed 42 --output dp_utility_comparison.json

Optional dependencies for DP mode

DP mode is optional and requires extra packages:

pip install torch opacus

๐Ÿ” ONNX conversion, GPU inference path, and benchmarking

We provide utilities to convert models to ONNX, run inference preferring GPU (if available) with CPU fallback, and run inference benchmarks.

Conversion script:

python scripts/convert_model_to_onnx.py --model path/to/model.joblib --n-features 39 --out model.onnx

Run ONNX inference benchmark (example):

python benchmarks/benchmark_inference.py --model model.onnx --input-shape 1,39 --iterations 200 --warmup 20 --output bench.json

The inference wrapper inference/onnx_runtime.py selects CUDAExecutionProvider when available, otherwise falls back to CPUExecutionProvider.

๐Ÿงช A/B Testing Runner

The feature-flag A/B testing stack now includes a runner that handles deterministic traffic splits, metric ingestion, and automatic winner promotion.

What it does

  • Assigns users to variants using the configured traffic split.
  • Logs impression and conversion events into the experiment metrics pipeline.
  • Evaluates conversion-rate lift and promotes the winning variant automatically when the threshold is met.
  • After promotion, the winner receives 100% traffic and future assignments route to the promoted variant.

Key endpoints

POST /api/experiments/{exp_id}/traffic-split
POST /api/experiments/{exp_id}/evaluate
POST /api/experiments/assign

Example traffic split payload

{
	"variants": [
		{"id": "control", "weight": 40},
		{"id": "treatment", "weight": 60}
	]
}

Tradeoffs

  • Better privacy guarantees usually require stronger noise (lower utility).
  • Lower epsilon means stronger privacy but can increase RMSE.
  • DP training is typically slower than baseline training.
  • This implementation is a research proof-of-concept and should be calibrated before production use.

๐ŸŽฏ Objective

Provide farmers with a lightweight, region-aware digital assistant that reduces risk, improves yields, and encourages sustainable decisions through actionable insights.


๐Ÿ”ฎ Future Scope & Ideas

  • On-device offline support / PWA for low-connectivity regions
  • Integrate satellite / remote sensing for crop stress detection
  • SMS / WhatsApp alerts for farmers without smartphones
  • Integrate local market price data for crop sale recommendations
  • Train ML models using local farm historical data for precision recommendations

๐Ÿšจ New Feature: Farming Mistakes Awareness System

This in-app guide highlights common farming mistakes and practical steps to avoid them. Examples include:

  • Over-fertilization โ€” how to test soil and dose correctly.
  • Wrong irrigation timing โ€” when and how to irrigate for best results.
  • Poor seed selection โ€” choosing certified, climate-appropriate varieties.

How to access: Open the Advisor page and choose the "Farming Mistakes Awareness" card to open the modal with examples, images, and prevention tips.

Acceptance criteria:

  • Common mistakes are listed with an explanation of the problem.
  • Each mistake includes clear, actionable prevention steps.
  • Image examples for visual recognition.
  • Responsive UI and no console errors in Advisor view.

๐Ÿ–ผ๏ธ New Feature: Crop Growth Stage Visual Guide

A responsive in-app visual guide that walks farmers through the crop lifecycle: Seed โ†’ Sprout โ†’ Growth โ†’ Harvest. The guide includes stage-wise care instructions, image-based examples for visual learning, and a lightweight lightbox for inspecting images.

How to access: Open the app and go to the Advisor page โ€” the "Crop Growth Stage Visual Guide" card opens the modal with the visual walkthrough and learning images.

Acceptance criteria:

  • Seed โ†’ Sprout โ†’ Growth โ†’ Harvest stages represented visually.
  • Stage-wise care instructions are shown for each stage.
  • Image-based learning gallery with thumbnails and enlargements.
  • Responsive UI and no console errors when used in the Advisor view.

๐ŸŒฆ๏ธ New Feature: Seasonal Farming Strategy Guide

A responsive in-app strategy guide that explains how farming priorities change across the Indian crop seasons: Kharif, Rabi, and Zaid. The guide highlights season-specific crop focus, irrigation posture, key field priorities, and common risks so farmers can adapt their plan throughout the year.

How to access: Open the Advisor page and choose the "Seasonal Farming Strategy Guide" card to open the modal with the season-by-season playbook.

Acceptance criteria:

  • Kharif, Rabi, and Zaid strategies are shown clearly in one guided view.
  • Each season includes field priorities, irrigation guidance, and risks to watch.
  • The UI stays responsive across desktop and mobile layouts.
  • The guide opens cleanly in the Advisor view with no console errors.

Alternatives considered:

  • Linking externally to a knowledge article or PDF (rejected โ€” offline and discoverability concerns).
  • A full LMS course module with video lessons (more content-heavy; deferred to Agri-LMS integration).

About

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages

  • Python 42.9%
  • JavaScript 40.6%
  • CSS 16.4%
  • Other 0.1%