Skip to content
Satyam087Public

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

KisanMind

A five-node LangGraph advisor for farmers with Hindi and Marathi voice, built in 24 hours at HackWarts (Alta School of Technology, April 2026), top 2 of about 40 teams. Team AlgoRise: Satyam Kumar Singh (the AI service and the frontend wiring), Ved Kumar Singh, Nimit Jain, Parth Kshirsagar (backend, frontend, data).

Live: https://altahackathon.vercel.app (free tiers, cold starts) · case study with the pipeline diagram: https://satyamkumarsingh.com/work/kisanmind

What is real and what is not

  • The pipeline is real: weather → crop → market → financial → insights, a SharedState passed node to node in LangGraph, with rules-first filtering (water, season, soil, budget) before a Gemini rerank, and a rule-based fallback if the model call fails. Voice is Sarvam (Saaras STT, Bulbul TTS) with Groq Whisper and ElevenLabs as fallbacks.
  • 152 test functions across 9 files, 60 of them for the voice and language layer, written during the hackathon.
  • Mandi prices come from CEDA, weather from Open-Meteo; scheme eligibility (PM-KISAN, PMFBY, KCC, PM-Kusum) is rule-matched, not fetched live.
  • Not yet measured: recommendation quality. There is no agreement rate against an agronomy reference and no Hindi word-error-rate figure. "150 million smallholder farmers" below is the addressable market, not users.

The original hackathon README follows.


🌾 KisanMind — Digital Farmer Empowerment Platform

Multi-Agent AI Decision Support System for Indian Smallholder Farmers

🌐 Live Demo  ·  🤖 Agents  ·  🛠️ Stack  ·  🚀 Setup

Next.js Node.js FastAPI MongoDB LangGraph Gemini TypeScript License: MIT


🎯 Problem Statement

India's 150+ million smallholder farmers make critical decisions — what to plant, when to sell, which schemes to apply for — without access to real-time data. They rely on middlemen, generational guesswork, and word-of-mouth, resulting in:

Pain Point Impact
🏪 Mandi Price Opacity Farmers sell up to 30% below fair market value
🌱 Poor Crop Selection Crops planted based on tradition, not soil/climate analysis
🏛️ Missed Govt. Schemes Thousands of rupees in subsidies unclaimed every season
🌧️ No Weather Intelligence Irrigation, pest control, and harvest timing are reactive

KisanMind gives every Indian farmer a personal AI agronomist — combining real-time mandi data, soil intelligence, weather forecasting, and government scheme matching into one unified decision support system.


🤖 The Multi-Agent System

KisanMind is powered by a 4-agent LangGraph orchestration pipeline. Each agent is a specialised reasoning module that processes a farmer's profile and returns structured, actionable intelligence.

                        ┌────────────────────────────────────┐
                        │       FARMER PROFILE INPUT         │
                        │  Location · Soil · Land · Budget   │
                        └──────────────┬─────────────────────┘
                                       │
                        ┌──────────────▼──────────────┐
                        │    🌤️  Weather Service       │
                        │  IMD Forecast · Geo Lookup   │
                        └──────────────┬──────────────┘
                                       │
              ┌────────────────────────┬┴───────────────────────┐
              │                        │                        │
    ┌─────────▼─────────┐   ┌─────────▼─────────┐   ┌─────────▼─────────┐
    │  🌱 Crop Agent     │   │  📈 Market Agent   │   │  🏛️ Finance Agent │
    │  Soil × Climate    │──▶│  Mandi × MSP       │   │  Schemes × Credit │
    │  Yield Prediction  │   │  Price Trends       │   │  Subsidy Matching │
    └─────────┬─────────┘   └─────────┬─────────┘   └─────────┬─────────┘
              │                        │                        │
              └────────────────────────┼────────────────────────┘
                                       │
                        ┌──────────────▼──────────────┐
                        │  💡 Insights Agent           │
                        │  Cross-agent synthesis       │
                        │  Risk summary + Action plan  │
                        └──────────────┬──────────────┘
                                       │
                        ┌──────────────▼──────────────┐
                        │   📊 DASHBOARD OUTPUT        │
                        │  Crop · Market · Risk ·      │
                        │  Schemes · Field Report      │
                        └─────────────────────────────┘

Agent 1 — Crop Agent 🌱

Recommends the optimal crop based on soil type, climate data, water availability, and historical yield patterns.

Input Processing Output
Soil type, farm size, district, irrigation Rule-based elimination → weighted scoring → LLM re-ranking via Gemini 2.0 Flash Top 3 crops with confidence %, water needs, risk level, profitability, and reasoning chain

Example: Black Cotton Soil, Wardha, Maharashtra → Wheat (97.8% confidence, Low Risk, Medium Water)

Agent 2 — Market Agent 📈

Scans regional mandi prices and forecasts optimal selling windows with MSP comparison.

Input Processing Output
District, recommended crop Live APMC mandi data, MSP lookup, price trend analysis Price per quintal, % change, price trend (rising/falling), selling window, best buyer channel

Example: Wheat at ₹2,275/q — MSP: ₹2,275 — Trend: Stable → Sell in March via APMC Mandi

Agent 3 — Finance Agent 🏛️

Matches the farmer's profile against active government schemes, credit facilities, and subsidies.

Input Processing Output
Farm profile (land, income, crops, Aadhaar) Cross-references PM-KISAN, PMFBY, KCC, PM-Kusum eligibility Budget fit assessment, estimated input cost, credit needs, eligible schemes with action items

Example: 2-acre farm, ₹1.8L income → PM-KISAN ✅ (₹6,000/yr) + PMFBY ✅ + KCC ⚠️ (check eligibility)

Agent 4 — Insights Agent 💡

Synthesises outputs from all agents into a unified risk summary and actionable plan.

Input Processing Output
All agent outputs Cross-agent correlation, contradiction detection, priority ranking Combined insights, risk summary, numbered action plan, overall confidence score

🏗️ Architecture

KisanMind follows a 3-tier microservice architecture:

┌─────────────────────────────────────────────────────────────────────────┐
│                           FRONTEND (Vercel)                            │
│                    Next.js 15 · TypeScript · Zustand                   │
│             altahackathon.vercel.app                                   │
│                                                                        │
│  Landing → Register → OTP → Onboarding → Analysing → Dashboard        │
│  ┌──────────┬──────────┬──────────┬──────────┬──────────┬────────────┐ │
│  │  Crop    │  Market  │  Alerts  │ Insights │ Schemes  │   Report   │ │
│  └──────────┴──────────┴──────────┴──────────┴──────────┴────────────┘ │
│                    + Floating Agent Chatbot (Voice + Text)              │
└───────────────────────────────┬─────────────────────────────────────────┘
                                │  REST + Bearer JWT
                                ▼
┌─────────────────────────────────────────────────────────────────────────┐
│                        BACKEND (Render)                                 │
│               Node.js · Express 5 · MongoDB · JWT Auth                 │
│                                                                        │
│  /api/auth/*     → signup, verify-otp, login (JWT in response body)    │
│  /api/farmer/*   → GET/PUT profile (protected)                         │
│  /api/ai/*       → proxy to AI service (protected)                     │
└───────────────────────────────┬─────────────────────────────────────────┘
                                │  Internal HTTP
                                ▼
┌─────────────────────────────────────────────────────────────────────────┐
│                    AI SERVICE (FastAPI / Python)                        │
│         LangGraph · Gemini 2.0 Flash · Groq Whisper · Sarvam TTS      │
│                                                                        │
│  /orchestrate       → Full 4-agent pipeline                            │
│  /crop/recommend    → Standalone crop analysis                         │
│  /market/analyze    → Standalone market analysis                       │
│  /financial/analyze → Standalone financial analysis                    │
│  /chat/follow-up    → Conversational Q&A (text)                        │
│  /chat/voice        → Voice input → transcribe → chat → TTS response  │
└─────────────────────────────────────────────────────────────────────────┘

Authentication Flow

Register → Email OTP (Brevo) → Verify → JWT Token → Bearer Auth
                                          │
                                          ├── Stored in Zustand (localStorage)
                                          └── Sent as Authorization: Bearer <token>

Cross-domain cookies don't work between Vercel (.vercel.app) and Render (.onrender.com), so the JWT is returned in the response body and stored client-side. The backend's protect middleware accepts both cookie and Bearer header authentication.


🛠️ Tech Stack

Frontend

Technology Version Purpose
Next.js 15 (App Router) React framework with file-based routing
TypeScript 5 End-to-end type safety
Tailwind CSS 4 Utility-first styling with custom design tokens
Framer Motion 12 Page transitions, agent animations, micro-interactions
Recharts 3 Bar charts (mandi prices), radial charts (confidence)
Zustand 5 Persistent global state (auth, profile, AI outputs)
Lucide React — Consistent icon system across all views

Backend (Node.js)

Technology Version Purpose
Express 5 REST API framework
MongoDB Atlas (Mongoose 9) Farmer profile storage, auth records
JWT jsonwebtoken Stateless authentication tokens
Bcrypt bcryptjs 3 Password hashing (10 salt rounds)
Helmet 8 Security headers (relaxed for cross-origin)
Brevo @getbrevo/brevo 5 Transactional OTP emails
Cookie Parser — Cookie-based auth fallback (localhost)

AI Service (Python)

Technology Version Purpose
FastAPI Latest Async Python API with auto-docs
LangGraph Latest Agent orchestration DAG (directed acyclic graph)
LangChain Core ≥ 0.3.52 LLM abstraction, prompt chains, tool calling
Google Gemini 2.0 Flash Primary LLM for agent reasoning
Groq Whisper — Speech-to-text transcription (multilingual)
Sarvam AI — Text-to-speech synthesis (Hindi, Marathi)
langdetect — Automatic language detection for voice input
httpx — Async HTTP client for weather/market APIs

Infrastructure

Service Purpose
Vercel Frontend hosting + CDN
Render Backend API hosting
MongoDB Atlas Cloud database
GitHub Source control + CI/CD triggers

📁 Project Structure

KisanMind/
├── frontend/                          # Next.js 15 App Router
│   └── src/
│       ├── app/
│       │   ├── page.tsx              # Landing page (marketing)
│       │   ├── register/             # Email + password signup
│       │   ├── otp/                  # 6-digit OTP verification
│       │   ├── login/                # Returning user login
│       │   ├── language/             # Language selection (6 languages)
│       │   ├── onboarding/           # 4-step farm data ingestion
│       │   ├── analysing/            # Agent processing animation
│       │   ├── dashboard/            # Command center overview
│       │   ├── crop/                 # Crop recommendation deep-dive
│       │   ├── market/               # Mandi price intelligence
│       │   ├── alerts/               # Risk monitoring dashboard
│       │   ├── insights/             # Cross-agent AI synthesis
│       │   ├── schemes/              # Government scheme eligibility
│       │   ├── report/               # Full AI field report
│       │   ├── chat/                 # Voice + text chatbot page
│       │   └── profile/              # Farmer profile management
│       ├── components/
│       │   ├── DashboardLayout.tsx    # Sidebar + TopBar + MobileNav
│       │   ├── AgentChatbot.tsx       # Floating 4-agent Q&A panel
│       │   ├── AuthProvider.tsx       # Route protection + session verification
│       │   ├── VoiceRecorder.tsx      # Audio capture component
│       │   └── ui/                   # Shared UI primitives
│       └── lib/
│           ├── store.ts              # Zustand state (auth, profile, AI outputs)
│           ├── backendClient.ts      # Typed API client (Bearer auth)
│           ├── aiClient.ts           # AI service client (direct)
│           ├── mockData.ts           # Fallback data for offline display
│           └── useVoiceChat.ts       # Voice recording + processing hook
│
├── backend/                           # Node.js + Express 5
│   ├── server.js                     # App entry point + middleware
│   └── src/
│       ├── config/
│       │   └── db.js                 # MongoDB Atlas connection
│       ├── controllers/
│       │   ├── auth.controller.js    # signup, verify-otp, login
│       │   ├── user.controller.js    # GET/PUT farmer profile
│       │   └── ai.controller.js      # AI proxy + profile→payload mapper
│       ├── middleware/
│       │   └── auth.js               # JWT verification (cookie + Bearer)
│       ├── models/
│       │   └── User.model.js         # Mongoose schema (30+ fields)
│       ├── routes/
│       │   ├── auth.routes.js        # /api/auth/*
│       │   ├── user.routes.js        # /api/farmer/*
│       │   └── ai.routes.js          # /api/ai/* (protected)
│       └── services/
│           ├── aiService.js          # HTTP client → Python AI service
│           └── emailService.js       # Brevo transactional email
│
├── ai/                                # Python FastAPI AI Microservice
│   ├── app/
│   │   ├── main.py                   # FastAPI app + all endpoints
│   │   └── config.py                 # Settings (env-based)
│   ├── agents/
│   │   ├── crop/                     # Crop recommendation agent
│   │   ├── market/                   # Market analysis agent
│   │   ├── financial/                # Financial analysis agent
│   │   ├── insights/                 # Cross-agent synthesis agent
│   │   └── chat/                     # Conversational handler
│   ├── orchestrator/
│   │   ├── graph.py                  # LangGraph DAG definition
│   │   ├── state.py                  # SharedState type definitions
│   │   └── nodes/                    # Graph node implementations
│   ├── services/
│   │   ├── weather_service.py        # IMD weather data fetching
│   │   ├── llm_service.py            # LLM provider abstraction
│   │   ├── session_store.py          # In-memory conversation sessions
│   │   ├── speech_service.py         # Groq Whisper + Sarvam TTS
│   │   └── language_service.py       # Language detection
│   ├── tests/                        # 8 test suites (pytest)
│   └── requirements.txt
│
└── README.md                          # This file

🌐 Live Demo

🔗 https://altahackathon.vercel.app/

Demo Flow

  1. Register with email → receive OTP → verify
  2. Onboard — enter farm details (location, soil, land size, crops)
  3. Analyse — watch the 4-agent pipeline process your data
  4. Explore — dashboard, crop recommendations, market prices, risk alerts, schemes, full report
  5. Chat — ask the AI chatbot questions in English or Hindi (voice supported)

🚀 Getting Started

Prerequisites

  • Node.js 20+ (via nvm)
  • Python 3.11+
  • MongoDB instance (local or Atlas)

1. Clone the Repository

git clone https://github.com/Satyam087/AltaHack.git
cd AltaHack

2. Backend (Node.js)

cd backend
npm install

# Create .env
cp .env.example .env
# Edit .env with your MongoDB URI, JWT secret, and Brevo API key

npm run dev
# → http://localhost:3000

Required .env variables:

PORT=3000
MONGODB_URI=mongodb+srv://...
JWT_SECRET=your_secret_key
NODE_ENV=development
BREVO_API_KEY=your_brevo_key
BREVO_SENDER_EMAIL=your@email.com
BREVO_SENDER_NAME=KisanMind
AI_SERVICE_URL=http://localhost:8000
FRONTEND_URL=http://localhost:3001

3. AI Service (Python)

cd ai

# Create virtual environment
python3 -m venv venv
source venv/bin/activate        # Windows: venv\Scripts\activate

pip install -r requirements.txt

# Create .env
cp .env.example .env
# Edit .env with your Gemini API key

python3 app/main.py
# → http://localhost:8000
# → Swagger docs at http://localhost:8000/docs

Required .env variables:

GEMINI_API_KEY=your_gemini_key
LLM_PROVIDER=gemini
AI_SERVICE_PORT=8000

4. Frontend (Next.js)

cd frontend
npm install

# Create .env.local
echo "NEXT_PUBLIC_BACKEND_URL=http://localhost:3000" > .env.local

npm run dev
# → http://localhost:3001

🔌 API Reference

Auth Endpoints (/api/auth)

Method Endpoint Auth Description
POST /api/auth/signup Public Register with name, phone, email, password
POST /api/auth/verify-otp Public Verify email OTP → returns JWT token
POST /api/auth/login Public Login → returns JWT token + farmer profile

Farmer Endpoints (/api/farmer)

Method Endpoint Auth Description
GET /api/farmer/profile 🔒 JWT Fetch authenticated farmer's full profile
PUT /api/farmer/profile 🔒 JWT Update farm details (triggers isProfileComplete)

AI Endpoints (/api/ai)

Method Endpoint Auth Description
GET /api/ai/health Public Check AI service status
POST /api/ai/orchestrate 🔒 JWT Full 4-agent pipeline
POST /api/ai/crop/recommend 🔒 JWT Standalone crop recommendation
POST /api/ai/market/analyze 🔒 JWT Standalone market analysis
POST /api/ai/financial/analyze 🔒 JWT Standalone financial analysis
POST /api/ai/chat 🔒 JWT Conversational Q&A

AI Direct Endpoints (Python FastAPI)

Method Endpoint Description
GET /health Service health + LLM status
POST /orchestrate Full LangGraph pipeline
POST /crop/recommend Crop agent
POST /market/analyze Market agent
POST /financial/analyze Finance agent
POST /chat/follow-up Text chat with context
POST /chat/voice Voice → transcribe → chat → TTS

🧪 Testing

AI Service Tests

cd ai
source venv/bin/activate
pytest tests/ -v

Test suites:

  • test_crop_agent.py — crop recommendation pipeline
  • test_market_agent.py — market analysis + MSP comparison
  • test_financial_agent.py — financial analysis + scheme matching
  • test_graph.py — full LangGraph orchestration
  • test_follow_up.py — conversational chat handler
  • test_voice_and_lang.py — voice transcription + language detection
  • test_weather_service.py — weather data fetching
  • test_market_api_e2e.py — end-to-end market API flow

🗺️ Features

Feature Status Description
🌐 Landing Page ✅ Marketing page with agent showcase
🔐 Auth (Register/OTP/Login) ✅ Email OTP via Brevo, JWT Bearer auth
📋 4-Step Onboarding ✅ Location, soil, crops, financial profile
🤖 4-Agent AI Pipeline ✅ LangGraph orchestration with Gemini 2.0
📊 Dashboard ✅ Command center with AI-powered insights
🌱 Crop Analysis ✅ Top 3 recommendations with reasoning
📈 Market Intelligence ✅ Mandi prices, trends, sell signals
⚠️ Risk Alerts ✅ Weather, pest, price, scheme alerts
💡 AI Insights ✅ Cross-agent synthesis + action plan
🏛️ Scheme Eligibility ✅ PM-KISAN, PMFBY, KCC, PM-Kusum
📄 Field Report ✅ Complete AI analysis summary
💬 Agent Chatbot ✅ Context-aware Q&A across all agents
🎙️ Voice Input ✅ Groq Whisper (Hindi, Marathi, English)
🔊 Voice Response ✅ Sarvam AI TTS
🌐 Multilingual ✅ Hindi, Marathi, Punjabi, Telugu, Bengali
📱 Responsive ✅ Mobile-first with bottom nav
🚀 Deployment ✅ Vercel (FE) + Render (BE)

🧑‍🤝‍🧑 Team

Name Role
Ved Kumar Singh AI Agent Architecture & LangGraph Pipeline
Satyam Kumar Singh Backend Engineering & Database Design
Nimit Jain Frontend Development & UI/UX
Parth Kshirsagar Full-Stack Integration & Deployment

Built for AltaHack — a multi-agent AI prototype demonstrating the future of data-driven agriculture in India.


📄 License

MIT — see LICENSE

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages