Your intelligent farming companion β powered by Gemini 2.5 Flash
FarmSense AI is a full-stack precision agriculture assistant that gives small and mid-size farmers access to expert-level crop disease diagnosis, irrigation scheduling, soil health advice, financial tracking, and proactive weather-aware alerts β all in a conversational interface.
| Feature | FarmSense AI | Generic AI Chatbot |
|---|---|---|
| Location-aware by default | β Auto-detects GPS, injects region into every prompt | β User must describe location every time |
| Real-time weather in responses | β Open-Meteo API injected into irrigation prompts | β No live data |
| Proactive alerts | β AI scans sessions + 7-day forecast, pushes warnings | β Reactive only |
| Finance loop | β AI recommends β "Log to Tracker" chip β expense logged | β Advice stays in chat |
| Streaming responses | β Token-by-token SSE stream | β Full response wait |
| Multi-module memory | β Persistent sessions per module per user | β Stateless |
| Image diagnosis | β Upload crop photo for disease ID | β Text only |
- Upload a photo or describe symptoms to diagnose plant diseases
- Confidence-rated diagnosis with severity levels (Mild / Moderate / Severe)
- Organic treatments recommended first; chemicals only as last resort
- Region-specific pest and disease advice based on detected location
- Calculates water requirements in liters per acre
- Suggests optimal watering schedules with time-of-day recommendations
- Real-time weather data (temperature, humidity, precipitation, wind) injected into every response
- Flags drought risk and overwatering risk automatically
- Assesses soil health from description or photo
- Recommends region-specific cover crops
- Composting strategies with timelines
- Designs 3-season crop rotation plans
- Region context injected via auto-detected GPS location
- Silent background geolocation on app load
- Reverse geocoding via Nominatim (OpenStreetMap) β no API key needed
- Location pill shown in chat header (
π Thane, Maharashtra) - Automatically injected into all AI prompts β user never has to type their location
- AI scans your 3 most recent sessions against a 7-day weather forecast
- Generates 2-3 actionable alerts per session (e.g. "Skip watering tomorrow β rain forecast Thursday")
- Alerts cached for 1 hour, generated in parallel to avoid timeouts
- Bell icon π in top-right with unread count badge
- Alert types:
info,warning,urgentwith color-coded cards - Dismissed alerts stored in localStorage β won't reappear
- After every AI response, a background Gemini call extracts any purchasing recommendations
- "β Log to Tracker" chip buttons appear below AI messages
- Click a chip β pre-filled confirmation modal (description, category, amount, date)
- Confirm β POST to tracker, expense logged instantly
- Categories: crops, fertilizers, electricity, labor, equipment, irrigation, other
- Dashboard finance snapshot: Revenue, Expenses, Net Profit, ROI
- Backend streams tokens via Server-Sent Events (SSE)
- Frontend renders text word-by-word as it arrives
- Thinking indicator (animated dots) shown until first token
- No more mid-response truncation
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BROWSER (Next.js 15) β
β β
β ββββββββββββββββ βββββββββββββββββ ββββββββββββββββββββββββ β
β β Auth Pages β β Chat Modules β β Finance Tracker β β
β β /login β β /crop-doctor β β /tracker β β
β β /register β β /irrigation β β + TransactionForm β β
β ββββββββββββββββ β /soil-health β ββββββββββββββββββββββββ β
β βββββββββββββββββ β
β β β
β βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββ β
β β Zustand Store β β
β β token Β· user Β· location Β· sessions Β· dismissedAlerts β β
β β (persisted to localStorage via zustand/persist) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β β
β βββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββ β
β β useAutoLocation (background) β β
β β navigator.geolocation β Nominatim reverse geocode β β
β β β setLocation({ lat, lon, city, region }) β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββ
β HTTP / SSE
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β EXPRESS BACKEND (:4000) β
β β
β POST /api/chat/:module βββββββββββββββββββββββββββββββββββ β
β 1. Get/create ChatSession (Prisma) β β
β 2. Persist user message β β
β 3. Fetch weather (irrigation) or region (others) β β
β 4. streamReplyFromMessages() β SSE token stream ββββββββββΌββΊ β stream to browser
β 5. Persist full AI reply β β
β β β
β POST /api/chat/extract-items β β
β Gemini fast model β extract purchase JSON β β
β (never persisted to DB) β β
β β β
β GET /api/alerts?lat=&lon= β β
β Parallel Gemini calls per session + weather forecast β β
β 1-hour cache per session β β
β β β
β GET/POST /api/tracker/transactions β β
β GET /api/tracker/summary β β
β POST/GET /api/auth/* β β
ββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββ΄ββββββββββββββββββββββββ
β β
βΌ βΌ
ββββββββββββββββ ββββββββββββββββββββββ
β PostgreSQL β β Gemini 2.5 Flash β
β (Prisma) β β (via LangChain) β
β β β β
β User β β β’ Chat replies β
β ChatSession β β β’ Alert generation β
β Message β β β’ Item extraction β
β Transaction β β β
ββββββββββββββββ βββββββββββββββββββββββ
β
βββββββββββ΄βββββββββββ
β β
βΌ βΌ
ββββββββββββββββ ββββββββββββββββββββ
β Open-Meteo β β Nominatim β
β Weather API β β Reverse Geocode β
β (free) β β (OpenStreetMap) β
ββββββββββββββββ ββββββββββββββββββββ
| Framework | Next.js 15 (App Router) + React 19 |
| State | Zustand 4.5 with persist middleware |
| Styling | Tailwind CSS + custom farm color palette |
| Charts | Recharts (Pie + Bar) |
| Markdown | react-markdown + remark-gfm |
| Icons | lucide-react |
| HTTP | Native fetch with SSE streaming |
| Runtime | Node.js + Express 4 |
| Language | TypeScript (strict) |
| Database | PostgreSQL via Prisma ORM |
| AI | Google Gemini 2.5 Flash via @langchain/google-genai |
| Streaming | Server-Sent Events (SSE) |
| Auth | JWT (jsonwebtoken + bcryptjs) |
| Weather | Open-Meteo API (free, no key needed) |
| Geocoding | Nominatim / OpenStreetMap (free, no key needed) |
| API | Used For |
|---|---|
| Google Gemini | Chat replies, alert generation, item extraction |
| Open-Meteo | Current weather + 7-day forecast |
| Nominatim (OSM) | Reverse geocoding (lat/lon β city, region) |
- Node.js 18+
- PostgreSQL database
- Google Gemini API key (free tier available at aistudio.google.com)
# Clone and install all dependencies
git clone <repo>
cd FarmSense-AI
npm run install:allCreate backend/.env:
DATABASE_URL=postgresql://user:password@localhost:5432/farmsense
GEMINI_API_KEY=your_gemini_api_key_here
# Optional: override AI models
GEMINI_MODEL=gemini-2.5-flash
GEMINI_FAST_MODEL=gemini-2.0-flashcd backend
npx prisma migrate dev# Terminal 1 β backend on :4000
npm run backend
# Terminal 2 β frontend on :3000
npm run frontendOpen http://localhost:3000, register an account, and start farming smarter.
- Register / Login β JWT token stored in localStorage
- Allow location β pill appears in chat header (
π Thane, Maharashtra) - Pick a module β Crop Doctor, Irrigation Advisor, or Soil Health
- Chat β AI streams responses token-by-token with region + weather context
- See "Log to Tracker" chips β click any expense recommendation to log it
- Check alerts bell π β weather-aware alerts auto-generated from your sessions
- Finance Tracker β view revenue, expenses, ROI, category breakdown
- Passwords hashed with bcrypt (10 rounds)
- All API routes protected by JWT middleware
- Sessions scoped to authenticated user β no cross-user data leakage
- Images stored as base64 in DB (never written to filesystem)
- Push notifications (Web Push API)
- Offline mode with service worker
- Multi-language support (Hindi, Marathi, Tamil)
- Soil test report PDF upload + OCR
- Government scheme recommendations by region
- WhatsApp integration for low-connectivity farmers
Built with β€οΈ for farmers who deserve better tools.