DEV Community

Deep Manna
Deep Manna

Posted on

MandiMitra โ€” Live Mandi Price Intelligence for Farmers

Hacktoberfest Open-Source AI Challenge Week 1: Touch Grass Submission ๐ŸŒฟ

MandiMitra โ€” Live Mandi Price Intelligence for Farmers ๐ŸŒพ

This is a submission for the Hacktoberfest Open-Source AI Challenge Week 1: Touch Grass


What I Built

MandiMitra ("Mandi Friend" in Hindi/Bengali) is a mobile-first agricultural market intelligence platform built specifically for Indian farmers.

Tagline: "Know the Price. Choose the Market. Earn Better."

The Real Problem It Solves

Every day, millions of small-scale farmers in India load their produce onto a cart, spend money on transport, and travel to the nearest mandi (agricultural market) โ€” often not knowing that a market 20 km away is offering โ‚น300โ€“โ‚น500 more per quintal for the same crop. That difference can mean โ‚น30,000โ€“โ‚น50,000 more income per harvest.

MandiMitra gets farmers off the screen and into the right market by answering one simple question before they leave home:

"Which mandi near me is paying the best price for my potato today โ€” and is it worth the trip?"

Who It's For

  • Small and marginal farmers in rural India with basic smartphone access
  • Primary focus: West Bengal (potato, rice, jute, onion, tomato, brinjal)
  • Designed for users with limited technical literacy โ€” everything is in plain language, with Hindi and Bengali support

How It Gets People "Off the Screen"

The entire UX is built around a single actionable decision โ€” not data dashboards, not endless charts. A farmer opens the app for 60 seconds, sees "Go to Bankura Mandi โ€” earn โ‚น34,000 more today", and heads out the door. The platform is a decision tool, not a content platform. It pushes people into the physical world.

Key Features

Feature Description
๐Ÿท๏ธ Live Market Prices Today's modal/min/max prices across 8+ West Bengal mandis
๐Ÿ“Š Market Comparison Side-by-side price table across all markets for any crop
๐Ÿงฎ Best Market Calculator Profit/loss calc that factors in transport cost, distance, and freight
๐Ÿ—บ๏ธ Nearby Markets Map OpenStreetMap-powered interactive map of mandis with GPS detection
๐Ÿ“ˆ Price Trends 7-day historical trend charts powered by Recharts
๐Ÿ”” Price Alerts Set a target price; get notified when the market hits it
๐Ÿค– MandiMitra AI Saathi Gemini-powered agricultural advisor with voice input in Hindi or Bengali
๐Ÿ›ก๏ธ Admin Dashboard Admins can post price updates and manage mandi data
๐ŸŒ Multilingual English, เคนเคฟเค‚เคฆเฅ€, เฆฌเฆพเฆ‚เฆฒเฆพ UI via i18n translations system

Demo

Local Development:

git clone https://github.com/deepmanna2007/Mandimitra.git
cd Mandimitra
npm install
npm run dev

App runs at http://localhost:3000 | API at http://localhost:5000

Walkthrough

Farmer Dashboard โ€” Clean, distraction-free entry point showing crop cards, today's highlights, and the "Best Market For Me" feature card.

Best Market Calculator โ€” Enter your crop, quantity (in quintals), and your location. MandiMitra calculates:

  • Transport cost using calibrated per-km freight rates (โ‚น8,000 base + โ‚น30/km)
  • Net profit/loss of travelling to each market vs. selling locally
  • Presents a clear winner: "Go to Bankura Mandi โ€” extra profit โ‚น34,200"

MandiMitra AI Saathi โ€” Voice-enabled Gemini AI chat that understands:

  • "เค†เคฒเฅ‚ เค•เคพ เคญเคพเคต เค•เฅเคฏเคพ เคนเฅˆ เค†เคœ?" (What's the potato price today?)
  • "My tomato harvest is 20 quintals. Which market should I go to?"
  • "เฆธเฆพเฆฐ เฆ•เฆคเฆŸเฆพ เฆฆเง‡เฆฌ เฆเฆ‡ เฆฎเฆพเฆŸเฆฟเฆคเง‡?" (How much fertilizer for this soil?)

Code

GitHub Repository: https://github.com/deepmanna2007/Mandimitra

Project Structure

Mandimitra/
โ”œโ”€โ”€ server/
โ”‚   โ”œโ”€โ”€ server.js                    # Express REST API (12+ endpoints)
โ”‚   โ””โ”€โ”€ services/
โ”‚       โ”œโ”€โ”€ database.js              # JSON-store with seed mandi data (West Bengal)
โ”‚       โ”œโ”€โ”€ marketPriceService.js    # Haversine distance + profit calculator engine
โ”‚       โ””โ”€โ”€ geminiService.js         # Gemini AI integration (advisor + voice parsing)
โ”‚
โ””โ”€โ”€ client/
    โ””โ”€โ”€ src/
        โ”œโ”€โ”€ context/MandiContext.tsx # Central state + API layer (React Context)
        โ”œโ”€โ”€ i18n/translations.ts    # EN / HI / BN string translations
        โ”œโ”€โ”€ pages/
        โ”‚   โ”œโ”€โ”€ LandingPage.tsx
        โ”‚   โ”œโ”€โ”€ FarmerDashboard.tsx
        โ”‚   โ”œโ”€โ”€ MarketPricesPage.tsx
        โ”‚   โ”œโ”€โ”€ CompareMarketsPage.tsx
        โ”‚   โ”œโ”€โ”€ BestMarketCalculatorPage.tsx
        โ”‚   โ”œโ”€โ”€ NearbyMarketsMapPage.tsx
        โ”‚   โ”œโ”€โ”€ PriceTrendsPage.tsx
        โ”‚   โ”œโ”€โ”€ PriceAlertsPage.tsx
        โ”‚   โ”œโ”€โ”€ AiSaathiPage.tsx
        โ”‚   โ””โ”€โ”€ AdminDashboardPage.tsx
        โ””โ”€โ”€ components/
            โ”œโ”€โ”€ Navbar.tsx / MobileNav.tsx
            โ”œโ”€โ”€ LocationModal.tsx
            โ”œโ”€โ”€ AuthModal.tsx
            โ””โ”€โ”€ ToastContainer.tsx
Enter fullscreen mode Exit fullscreen mode

Core Tech Stack

Layer Technology
Frontend React 18 + TypeScript, Vite 8
Styling Vanilla CSS with a custom agricultural design system
Charts Recharts
Maps Leaflet.js + OpenStreetMap (fully open-source)
Backend Node.js + Express 5
AI Google Gemini API (gemini-3.5-flash-lite)
Data JSON flat-file store (Agmarknet-ready adapter pattern)
Icons Lucide React

How I Built It

The AI Layer โ€” Gemini as a "Farmer's Advisor"

The heart of MandiMitra's AI feature is the "AI Saathi" (AI companion). It's built on Google Gemini (gemini-3.5-flash-lite / gemini-3.8-flash with automatic fallback) via the Generative Language REST API.

// server/services/geminiService.js (simplified)
async callGemini(prompt, systemInstruction) {
  for (const model of ['gemini-3.5-flash-lite', 'gemini-3.8-flash']) {
    const response = await fetch(
      `https://generativelanguage.googleapis.com/v1beta/models/${model}:generateContent?key=${apiKey}`,
      { method: 'POST', body: JSON.stringify({ contents: [{ role: 'user', parts: [{ text: prompt }] }] }) }
    );
    if (response.ok) return response.json();
  }
}
Enter fullscreen mode Exit fullscreen mode

The system instruction is carefully crafted to keep the AI grounded in agricultural context โ€” it knows about the mandis in the database, refuses to give financial advice beyond its data, and speaks in the farmer's preferred language.

Voice Input is handled by the Web Speech API (SpeechRecognition). Voice queries are transcribed and sent to Gemini for intent parsing โ€” extracting structured fields like cropName, quantity, and marketName from spoken Hindi/Bengali sentences.

The Distance-Profit Engine

The "Best Market Calculator" uses the Haversine formula to compute real great-circle distances between a farmer's GPS location and every mandi:

// Calibrated freight cost model
const transportCost = Math.round(8000 + (distanceKm * 30));
const netProfit = (pricePerQ - basePrice) * quantity - transportCost;
Enter fullscreen mode Exit fullscreen mode

This gives farmers a concrete rupee figure for "is the trip worth it?" โ€” not just a price comparison.

Architecture Decision: Open Adapter Pattern

The marketPriceService.js is built with a pluggable adapter pattern. In demo mode it serves realistic West Bengal benchmark prices. When switched to live mode, it's ready to consume the Agmarknet / Data.gov.in government open data API โ€” no code changes needed, just a config flag:

// database.js โ€” toggle this one field
{ mode: 'demo' }   // โ† current state (benchmark data)
{ mode: 'live' }   // โ† production with real Agmarknet feeds
Enter fullscreen mode Exit fullscreen mode

Why Does Open Innovation Matter?

MandiMitra could not exist without open-source and open-data infrastructure. Here's what it depends on โ€” and why closed alternatives wouldn't work:

1. OpenStreetMap + Leaflet.js โ€” The Mandi Map

Google Maps API costs money at scale and has proprietary terms. The farmer-facing mandi map uses Leaflet.js (open-source) + OpenStreetMap tiles (community-maintained, free forever). This means a farmer in rural West Bengal can view a map of nearby mandis with zero API cost to the operator โ€” making the tool sustainable without VC funding.

2. Agmarknet / Data.gov.in โ€” The Real Price Data

India's National Informatics Centre and Directorate of Marketing & Inspection publish agricultural market prices as open data under the Government Open Data License (GODL). MandiMitra is built around this open data layer. A closed API (like a private price aggregator) would charge per-query fees that make a free farmer tool economically impossible.

3. Open-Weight AI Philosophy

The geminiService.js is abstracted behind a single getAdvice(prompt) call specifically to enable a future swap to a locally-run open-weight model (Llama, Mistral via Ollama) โ€” critical for rural users who may distrust cloud AI with their farm data. Open-source AI makes data sovereignty possible.

4. Open-Source Makes It Auditable

When an AI tells a farmer "sell at Bankura Mandi", that farmer needs to trust the recommendation. Open-source code means any agricultural NGO, journalist, or government official can audit exactly how the recommendation was generated. A black-box closed SaaS simply cannot offer that trust to a vulnerable population.

Open innovation didn't just make this easier to build โ€” it made it possible to build responsibly, affordably, and sustainably for the farmers who need it most.


My Agent Session

Built end-to-end using Google Antigravity (AGY) โ€” an AI coding agent โ€” in a single extended pair-programming session. The agent:

  • Designed the entire system architecture from the brief
  • Scaffolded the Express backend, React/TypeScript frontend, and all service layers
  • Implemented the Haversine distance engine and profit calculator
  • Integrated Gemini AI with automatic model fallback
  • Built 10 full-featured pages with responsive mobile-first CSS
  • Debugged Vite ESM module errors in real time
  • Wrote this submission

Prize Categories

  • โœ… General Hacktoberfest โ€” Open-source project with real-world impact
  • โœ… Google Gemini โ€” Built around Gemini AI for agricultural advice and voice query parsing
  • โœ… Farming / AgriTech โ€” Direct application for smallholder farmers in India
  • โœ… Social Good / Accessibility โ€” Multilingual (EN/HI/BN), designed for low-literacy users

MandiMitra is open source and free to use. Contributions, especially real Agmarknet data integrations and regional language additions, are very welcome!

Top comments (0)