Skip to content

Latest commit

Β 

History

31 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

KisanQueue Logo

🌾 KisanQueue

Real-Time Mandi Visibility, Queue Admission & DBT Payout Verification Layer

SIH 2026 FastAPI React Tests Build License


"e-Uparjan tells a farmer that they have a slot β€” KisanQueue tells them whether today is actually a good day to travel."

Live Demo β€’ Key Features β€’ Mathematical ETA Engine β€’ Architecture β€’ Deployment β€’ Quickstart


🎯 The Core Problem & Our Solution

Every harvest season, over 140 million Indian farmers face grueling mandi bottlenecks:

  • 🚨 Blind 40km Journeys: Farmers travel to procurement centres with zero warning of 6-hour truck lifting delays, broken weighbridges, or 30-tractor backlogs.
  • 🚨 Double-Booking & Queue Jumping: Lack of cryptographic token verification creates chaos at APMC entry gates.
  • 🚨 Payment Uncertainty: Complex grading deductions and manual entry errors delay Direct Benefit Transfer (DBT) payouts.

The KisanQueue Advantage

  1. Zero Form Fatigue: One-time phone OTP onboarding. Returning farmers generate passes in under 15 seconds.
  2. Deterministic, Explainable ETA Engine: Mathematical queuing model that reacts live to operational status changes (e.g., FCI truck delays reduce throughput; ETAs jump instantly).
  3. Cryptographically Signed Offline QR Passes: HMAC-SHA256 authenticated passes that work even when mandi cellular connectivity drops.
  4. 2-Tap Officer Console: APMC officers report conditions (Normal, Busy, Delayed, Paused) in 2 taps; all farmer screens update in <2 seconds via WebSockets.
  5. Accurate MSP DBT Payouts: Automated calculation with statutory government minimum support prices.

🎨 Official Brand Design System

Built with a curated agritech palette engineered for high sunlight outdoor visibility and bilingual clarity:

Swatch Color Name HEX Code Purpose
🌰 Almond #D6BD98 Warm wheat accent, highlight borders, pass badges, active button accents
🍡 Matcha Brew #677D6A Organic sage green, secondary buttons, status badges, subtle borders
🌲 Forest Roast #40534C Deep earthy slate green, card headers, secondary surfaces, active tabs
πŸŒ‘ Eclipse #1A3636 Rich obsidian forest canvas, primary brand anchor, dark mode surface

✨ Key Features

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                            KISANQUEUE ECOSYSTEM                             β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ 🚜 Farmer Web & Mobile App   β”‚ πŸ›‘οΈ Mandi Officer Console    β”‚ πŸ’¬ Assistant  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β€’ 1-Tap Pass Gen (KQ-1047)   β”‚ β€’ 2-Tap Capacity Engine      β”‚ β€’ Multi-turn  β”‚
β”‚ β€’ Live Queue & ETA Sync      β”‚ β€’ QR & Token Gate Check-in   β”‚   Onboarding  β”‚
β”‚ β€’ Offline-Saved QR Passes    β”‚ β€’ Weighbridge & Grade Issue  β”‚ β€’ Live Mandi  β”‚
β”‚ β€’ Full Hindi/English UI      β”‚ β€’ DBT Payout Verification    β”‚   Status/ETA  β”‚
β”‚ β€’ Self-Service Cancellation  β”‚ β€’ Zero IDOR / Opaque 404s    β”‚ β€’ Pass Cancel β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“ Deterministic ETA Engine

KisanQueue rejects opaque "black-box" AI for a deterministic, explainable, and legally defensible mathematical formula:

$$\text{ETA (minutes)} = \left\lceil \frac{N \times T_{\text{base}}}{C \times F} \right\rceil$$

Where:

  • $N$ = Live count of farmers waiting ahead in queue
  • $T_{\text{base}}$ = Historical baseline processing time (e.g. 25 minutes per tractor)
  • $C$ = Active operational weighbridge counters reported by mandi officer
  • $F$ = Capacity factor ($1.00$ for Normal, $0.80$ for Busy, $0.60$ for Lifting Delayed, $0.00$ for Paused)

Real-Time Delay Scenario:

  • Normal Operations: $N = 14, T_{\text{base}} = 25, C = 2, F = 1.00 \implies \mathbf{\text{ETA} = 175\text{ min}}$ (~2h 55m, High confidence)
  • FCI Truck Delay Reported: Officer taps Lifting Delay ($C = 1, F = 0.60$) $\implies \mathbf{\text{ETA} = 584\text{ min}}$ (~9h 44m, Low confidence)
  • All waiting farmers' screens update in < 2 seconds via WebSocket event push.

πŸ—οΈ System Architecture

graph TD
    subgraph Clients["Client Layer"]
        FWA["πŸ’¬ WhatsApp Assistant (Simulator)"]
        FApp["πŸ“± Farmer Mobile Web (React/Vite)"]
        OApp["πŸ’» Mandi Officer Console"]
    end

    subgraph Gateway["FastAPI Monolith Gateway"]
        Auth["πŸ”‘ Auth (JWT + OTP)"]
        Queue["πŸ“‹ Queue State Machine"]
        ETA["⏱️ Deterministic ETA Engine"]
        QR["πŸ›‘οΈ HMAC-SHA256 QR Service"]
        WS["⚑ ConnectionManager (WebSockets)"]
    end

    subgraph Data["Persistence & Storage"]
        DB[("🐘 PostgreSQL (Supabase)")]
        Cache[("⚑ PgBouncer Pooler")]
    end

    FWA -->|REST| Auth
    FApp -->|REST + wss://| WS
    OApp -->|REST + wss://| WS
    Auth --> Queue
    Queue --> ETA
    Queue --> QR
    Queue --> DB
    WS --> Cache
Loading

Concurrency & Security Hardening

  • Anti-Double Booking: SELECT ... FOR UPDATE row locking on centre records + PostgreSQL partial unique index uq_queue_entry_active_per_farmer_centre.
  • Anti-Tampering QR: HMAC-SHA256 signature payload (KQ:<base64-payload>.<signature>) verified in constant time (hmac.compare_digest).
  • Financial Privacy: Private payment events (FARMER_PAYMENT_READY) are dispatched exclusively to the farmer's direct connection, keeping public centre broadcasts strictly non-financial.

πŸš€ Quick Start

Prerequisites

  • Node.js: v18+
  • Python: v3.11+
  • PostgreSQL: (e.g., Supabase or local instance)

1. Backend Setup

cd backend
python -m venv venv

# Windows
venv\Scripts\activate
# macOS/Linux
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Generate cryptographically secure keys
python generate_secrets.py

# Create .env from template and paste your DATABASE_URL and generated secrets
cp .env.example .env

# Run database migrations & seed initial mandis/officers
alembic upgrade head
python seed.py

# Start FastAPI server
uvicorn main:app --reload --port 8000

API runs at http://localhost:8000 β€’ Interactive Swagger Docs at http://localhost:8000/docs

2. Frontend Setup

cd frontend
npm install

# Start Vite development server
npm run dev

App runs at http://localhost:5173


πŸ§ͺ Testing & Verification

The repository includes a comprehensive 12-test suite covering math edge cases, WhatsApp dialog state machines, security guards, and end-to-end procurement lifecycles:

cd backend
pytest -v tests/

Verified Test Suite

tests/test_eta.py::test_base_formula_example_1 PASSED
tests/test_eta.py::test_capacity_reduction_example_2 PASSED
tests/test_eta.py::test_zero_counters_or_paused PASSED
tests/test_eta.py::test_first_in_line PASSED
tests/test_eta.py::test_zero_in_line PASSED
tests/test_eta.py::test_freshness_degradation PASSED
tests/test_eta.py::test_anomalous_capacity_factor PASSED
tests/test_whatsapp.py::test_whatsapp_simulator_onboarding PASSED
tests/test_integration.py::test_auth_and_pass_generation_flow PASSED
tests/test_integration.py::test_officer_login_flow PASSED
tests/test_integration_e2e.py::test_full_procurement_lifecycle_and_payout_calculation PASSED
tests/test_integration_e2e.py::test_pass_cancellation_flow PASSED

======================= 12 passed in 14.33s =======================

☁️ Cloud Deployment (Vercel + Render)

1. Deploy Backend on Render

The repo contains a pre-configured render.yaml blueprint:

  • Build Command: pip install -r requirements.txt
  • Start Command: uvicorn main:app --host 0.0.0.0 --port $PORT --workers 2
  • Environment Variables:
    • DATABASE_URL: postgresql+psycopg://postgres:[PASSWORD]@[HOST]:6543/postgres
    • JWT_SECRET_KEY: (Generated via generate_secrets.py)
    • QR_HMAC_SECRET: (Generated via generate_secrets.py)
    • CORS_ORIGINS: http://localhost:5173,https://<your-vercel-app>.vercel.app
    • OTP_MOCK_ENABLED: true (Enables evaluator quick OTP 1234)

2. Deploy Frontend on Vercel

Pre-configured with frontend/vercel.json for client-side SPA routing:

  • Root Directory: frontend
  • Framework Preset: Vite
  • Build Command: npm run build
  • Output Directory: dist
  • Environment Variables:
    • VITE_API_BASE_URL: https://<your-render-backend>.onrender.com

🎬 3-Minute Demo Walkthrough

Step Action What to Observe
1 Farmer Login (+919876543210 / 1234) Instant login as Ramesh Kumar (Biaora, Rajgarh).
2 Select Mandi & Quantity Select Rajgarh Centre, choose Wheat, enter 40 Quintals βž” Pass KQ-1047 issued with signed QR code.
3 Open Live Queue Tracker Watch live queue position (#1), estimated wait time (~25 min), and operational status (Normal).
4 Officer Console (officer_rajgarh / Demo@1234) Officer logs in in another window, taps Lifting Delay (60% capacity).
5 Real-Time Sync Without refreshing, the farmer's screen immediately alerts Lifting Delay and ETA jumps to ~42 min.
6 Gate Check-in & Completion Officer scans token 47, records actual weight, issues Grade A receipt with full β‚Ή91,000 DBT Payout.

πŸ“ Complete Documentation Suite

All 30 blueprint specifications are available in /docs:


πŸ“„ License

Distributed under the MIT License. See LICENSE for details.

Made with ❀️ for Indian Farmers β€’ Smart India Hackathon 2026

About

🌾 Farmer-first visibility, queue & admission layer for government MSP procurement centres | SIH 2026 PS 26032

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages