Skip to content

Latest commit

 

History

History
311 lines (232 loc) · 8.1 KB

File metadata and controls

311 lines (232 loc) · 8.1 KB

🌾 Krishi Sakhi

AI-powered agricultural companion empowering farmers with real-time insights, multilingual support, and offline-first accessibility.

Next.js React TypeScript PostgreSQL

🌐 Live Demo📖 Documentation🐛 Report BugRequest Feature


✨ Features

  • 🤖 AI-Powered Advisory - Intelligent crop recommendations and pest detection using advanced LLMs
  • 🌐 Offline-First PWA - Full functionality without internet connectivity
  • 🗣️ Multilingual Support - Available in English, Hindi, Malayalam, and Punjabi
  • 📊 Real-Time Weather - Hyperlocal forecasts and agricultural advisories
  • 📱 Mobile-Optimized - Installable progressive web app for seamless mobile experience
  • 🔒 Secure Authentication - OTP-based login with JWT token management
  • 📈 Admin Analytics - Comprehensive dashboards for agricultural insights

🏗️ Architecture

Tech Stack

Frontend

  • Next.js 14 (App Router) + React 18
  • Tailwind CSS for styling
  • Zustand for state management
  • next-pwa for offline capabilities
  • next-i18next for internationalization

Backend

  • Node.js + Express 4
  • Prisma ORM + PostgreSQL
  • JWT authentication
  • Pino logging, Helmet security, CORS protection

Integrations

  • Open-Meteo API (weather data)
  • Google Gemini AI (chat & pest detection)
  • Twilio (SMS/OTP - optional)
  • data.gov.in (location data - optional)

📸 Screenshots

Landing Light
Landing - Light Theme
Landing Dark
Landing - Dark Theme
Login
User Authentication
Dashboard
Admin Dashboard
Schemes
Scheme Management
Analytics
Geographic Analytics

🚀 Quick Start

Prerequisites

  • Node.js ≥ 18.17
  • Docker (for PostgreSQL)
  • npm or yarn

Installation

# Clone the repository
git clone https://github.com/yourusername/krishi-sakhi.git
cd krishi-sakhi

# Install dependencies
cd server && npm install
cd ../client && npm install

Database Setup

# Start PostgreSQL
docker compose up -d postgres

# Generate Prisma client
cd server
npm run prisma:generate
npm run prisma:migrate

Configuration

Create server/.env from server/.env.example:

NODE_ENV=development
PORT=4000
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/krishi_mitra?schema=public
JWT_SECRET=your-super-secret-key-change-in-production
JWT_EXPIRES_IN=7d
DEMO_MODE=true

# Optional: AI Features
GEMINI_API_KEY=your-gemini-api-key
GEN_AI_PROVIDER=gemini

# Optional: SMS
TWILIO_ACCOUNT_SID=your-twilio-sid
TWILIO_AUTH_TOKEN=your-twilio-token

Development

# Terminal 1 - Backend (http://localhost:4000)
cd server
npm run dev

# Terminal 2 - Frontend (http://localhost:3000)
cd client
npm run dev

📂 Project Structure

krishi-sakhi/
├── client/                      # Next.js PWA Frontend
│   ├── public/                  # Static assets, icons, locales
│   ├── src/
│   │   ├── app/                 # App Router pages
│   │   ├── components/          # Reusable UI components
│   │   ├── services/            # API client services
│   │   └── lib/                 # Utilities (i18n, TTS, theme)
│   └── next.config.js           # Next.js configuration
│
├── server/                      # Express API Backend
│   ├── src/
│   │   ├── api/
│   │   │   ├── routes/          # API route definitions
│   │   │   └── controllers/     # Request handlers
│   │   ├── services/            # Business logic layer
│   │   ├── middleware/          # Auth, rate limiting
│   │   ├── database/            # Prisma schema & migrations
│   │   └── config/              # Environment & configs
│   └── prisma/                  # Database schema
│
└── docker-compose.yml           # Local development services

🔌 API Reference

Authentication

  • POST /api/auth/signup - Register new user
  • POST /api/auth/otp - Request OTP
  • POST /api/auth/login - Login with OTP
  • POST /api/auth/login/password - Password login

Core Features

  • GET /api/weather - Weather forecasts
  • POST /api/predict - AI pest detection
  • POST /api/chat - AI agricultural advisor
  • GET /api/market - Market trends

Farm Management

  • GET /api/farms - List user farms
  • POST /api/farms - Create new farm
  • PUT /api/farms/:id - Update farm
  • DELETE /api/farms/:id - Delete farm

Admin

  • POST /api/admin/login - Admin authentication
  • GET /api/admin/analytics - Analytics dashboard
  • GET /api/admin/geo-analytics - Geographic insights
  • POST /api/admin/broadcast - Broadcast messages

🔒 Security Features

  • Helmet.js - HTTP security headers with CSP
  • CORS Protection - Configurable origin whitelist
  • Rate Limiting - Request throttling per endpoint
  • JWT Authentication - Secure token-based auth
  • Input Validation - Zod schema validation
  • Structured Logging - Pino for security audits

🌐 Internationalization

Supported languages:

  • 🇮🇳 English (en)
  • 🇮🇳 Hindi (hi)
  • 🇮🇳 Malayalam (ml)
  • 🇮🇳 Punjabi (pa)

Translations are located in client/public/locales/.


📱 PWA Capabilities

  • Offline Support - Service worker caching
  • Installable - Add to home screen
  • Push Notifications - Real-time alerts
  • Background Sync - Queue offline actions
  • Data Saver Mode - Bandwidth optimization

🧪 Testing

# Backend tests
cd server
npm test                    # Run all tests
npm run test:watch          # Watch mode
npm run test:coverage       # Coverage report

# Frontend tests
cd client
npm test                    # Run all tests
npm run test:watch          # Watch mode

🚢 Deployment

Backend

cd server
npm run build
NODE_ENV=production PORT=4000 node dist/index.js

Frontend

cd client
npm run build
npm start

Environment Variables

Production Checklist:

  • ✅ Set strong JWT_SECRET
  • ✅ Configure DATABASE_URL for production DB
  • ✅ Set CORS_ORIGIN to your domain
  • ✅ Add GEMINI_API_KEY for AI features
  • ✅ Configure TWILIO_* for SMS (optional)
  • ✅ Set NODE_ENV=production

🤝 Contributing

We welcome contributions! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.


🙏 Acknowledgments

  • Open-Meteo for weather data API
  • Google Gemini for AI capabilities
  • The farming community for valuable feedback

📞 Support


Made with ❤️ for farmers

Website