Skip to content

FarmWise is a mobile-first agricultural advisory web app that helps farmers access crop guidance, pest management, and seasonal advice in multiple languages (English, Hindi, Kannada). Features include crop-specific guidance for 9+ crops, problem diagnosis, seasonal calendar, and real-time search with offline support.

Notifications You must be signed in to change notification settings

sakalesha/FarmWise

Repository files navigation

FarmWise - Agricultural Advisory Mobile Application

FarmWise Logo

🌱 Your Agricultural Advisory Assistant

Expert farming guidance for better yields in multiple languages

Live Demo License Node.js React


📖 Table of Contents


🌾 Overview

FarmWise is a comprehensive mobile-first agricultural advisory web application designed to help farmers access crop-specific guidance, seasonal farming advice, and agricultural best practices. The application supports multiple languages (English, Hindi, Kannada) and provides expert farming knowledge in a farmer-friendly interface.

🎯 Mission

Empowering farmers with accessible, multilingual agricultural guidance to improve crop yields and farming practices through modern web technology.

👥 Target Users

  • Small and medium-scale farmers
  • Agricultural extension workers
  • Farming communities in India
  • Agricultural students and researchers

✨ Features

🌱 Core Functionality

  • Multi-language Support: English, Hindi (हिंदी), Kannada (ಕನ್ನಡ)
  • Crop-specific Guidance: Detailed advice for 9+ major crops
  • Problem Diagnosis: Solutions for pests, diseases, water stress, and more
  • Seasonal Calendar: Month-wise farming activities and alerts
  • Smart Search: Full-text search across crops, problems, and advice
  • Mobile-first Design: Optimized for smartphones and tablets

📱 User Experience

  • PWA Capabilities: Installable on mobile devices, offline support
  • Touch-friendly Interface: Large buttons, swipe gestures, voice search ready
  • High Contrast Design: Readable in bright sunlight conditions
  • Farmer-friendly Language: Simple explanations with actionable steps
  • Visual Guidance: Icons, emojis, and color-coded severity indicators

🔧 Technical Features

  • RESTful API: Scalable backend with MongoDB database
  • Real-time Search: Instant results with relevance scoring
  • Responsive Design: Works on all device sizes
  • Security: Rate limiting, CORS, input validation, JWT authentication
  • Performance: Optimized queries, caching, compression

🛠 Tech Stack

Frontend

  • Framework: React 18+ with TypeScript
  • Styling: Tailwind CSS for responsive design
  • Icons: Lucide React for consistent iconography
  • Routing: React Router DOM for navigation
  • State Management: React Hooks (useState, useContext)
  • Build Tool: Vite for fast development and building

Backend

  • Runtime: Node.js 18+
  • Framework: Express.js for RESTful API
  • Database: MongoDB with Mongoose ODM
  • Security: Helmet, CORS, Rate Limiting, JWT
  • Validation: Joi for input validation
  • Logging: Morgan for request logging

DevOps & Deployment

  • Hosting: Bolt Hosting (Frontend), MongoDB Atlas (Database)
  • PWA: Service Worker for offline capabilities
  • Environment: Docker-ready configuration
  • Monitoring: Health checks and error logging

📁 Project Structure

FarmWise/
├── 📁 src/                          # Frontend React application
│   ├── 📁 components/
│   │   ├── 📁 common/               # Reusable UI components
│   │   │   ├── Header.jsx
│   │   │   ├── Navigation.jsx
│   │   │   └── SearchBar.jsx
│   │   ├── 📁 cards/                # Data display cards
│   │   │   ├── CropCard.jsx
│   │   │   ├── AdviceCard.jsx
│   │   │   ├── ProblemCard.jsx
│   │   │   └── SeasonalCard.jsx
│   │   └── 📁 screens/              # Main application screens
│   │       ├── WelcomeScreen.jsx
│   │       ├── HomeScreen.jsx
│   │       ├── CropsScreen.jsx
│   │       ├── ProblemsScreen.jsx
│   │       ├── AdviceScreen.jsx
│   │       ├── CalendarScreen.jsx
│   │       └── SearchScreen.jsx
│   ├── 📁 hooks/                    # Custom React hooks
│   │   ├── useLanguage.js           # Multi-language support
│   │   └── useSearch.js             # Search functionality
│   ├── 📁 utils/                    # Utility functions and data
│   │   ├── translations.js          # Language translations
│   │   └── knowledgeBase.js         # Agricultural data
│   ├── App.tsx                      # Main application component
│   ├── main.tsx                     # Application entry point
│   └── index.css                    # Global styles
├── 📁 server/                       # Backend API application
│   ├── 📁 config/
│   │   └── database.js              # MongoDB connection
│   ├── 📁 models/                   # Database schemas
│   │   ├── Crop.js
│   │   ├── Topic.js
│   │   ├── Advice.js
│   │   ├── Calendar.js
│   │   └── User.js
│   ├── 📁 routes/                   # API endpoints
│   │   ├── crops.js
│   │   ├── advice.js
│   │   ├── topics.js
│   │   ├── search.js
│   │   ├── calendar.js
│   │   └── users.js
│   ├── 📁 middleware/               # Express middleware
│   │   ├── auth.js
│   │   ├── validation.js
│   │   └── errorHandler.js
│   ├── 📁 scripts/
│   │   └── seedDatabase.js          # Sample data seeding
│   ├── server.js                    # Express server setup
│   └── package.json
├── 📁 public/                       # Static assets
│   ├── manifest.json                # PWA configuration
│   ├── sw.js                        # Service worker
│   └── index.html                   # HTML template
├── package.json                     # Frontend dependencies
├── tailwind.config.js               # Tailwind CSS configuration
├── vite.config.ts                   # Vite build configuration
└── README.md                        # This file

🚀 Quick Start

Prerequisites

  • Node.js 18+ installed
  • MongoDB running locally or MongoDB Atlas account
  • Git for version control

1. Clone Repository

git clone https://github.com/your-username/farmwise-app.git
cd farmwise-app

2. Install Dependencies

# Install frontend dependencies
npm install

# Install backend dependencies
cd server
npm install
cd ..

3. Environment Setup

# Backend environment
cp server/.env.example server/.env
# Edit server/.env with your MongoDB URI and JWT secret

4. Start Development Servers

# Terminal 1: Start backend API (port 5000)
cd server
npm run dev

# Terminal 2: Start frontend (port 5173)
npm run dev

5. Access Application


🎨 Frontend Setup

🧭 Recent fixes & developer notes

  • HomeScreen was restored after being corrupted (invalid JSON accidentally present). If you previously saw a build error like

    "Expected ";" but found ':'" referencing src/components/screens/HomeScreen.jsx, that file was replaced with a proper React component.

  • Navigation/back behavior: the app now maintains a small internal navigation stack in src/App.tsx. The header back button restores the previous screen (e.g., Home → Crops → Advice → Back → Crops). If you prefer native browser back/forward behavior, consider converting screens to routes with react-router-dom.

  • Popular crops click: onCropSelect is now passed from App.tsx into HomeScreen so clicking a crop opens the advice view.

  • ESLint / TypeScript note: you may see a lint warning from @typescript-eslint about unsupported TypeScript versions. Options:

    • Pin TypeScript to a supported version (e.g., 5.5.3) in package.json and reinstall: npm install typescript@5.5.3 --save-dev.
    • Or upgrade @typescript-eslint/* packages to versions that support your TypeScript.

Quick sanity test (dev):

npm install
npm run dev
# In the app: Welcome → Get started → Home → Crops → click a crop → should open Advice; header Back should return to Crops

Development

# Install dependencies
npm install

# Start development server
npm run dev

# Build for production
npm run build

# Preview production build
npm run preview

Key Frontend Features

  • Responsive Design: Mobile-first approach with Tailwind CSS
  • Component Architecture: Modular, reusable React components
  • State Management: Context API for language and search state
  • PWA Support: Installable with offline capabilities
  • Performance: Optimized with Vite bundler

Environment Variables

# Frontend (.env)
VITE_API_BASE_URL=http://localhost:5000/api
VITE_APP_NAME=FarmWise

🔧 Backend Setup

Development

cd server

# Install dependencies
npm install

# Start development server with auto-reload
npm run dev

# Start production server
npm start

# Seed database with sample data
npm run seed

Environment Configuration

# Backend (server/.env)
PORT=5000
NODE_ENV=development
MONGODB_URI=mongodb://localhost:27017/farmwise
JWT_SECRET=your-super-secret-jwt-key-change-in-production
JWT_EXPIRE=7d
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:5173
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=100

Database Setup

# Local MongoDB
mongod

# Or use MongoDB Atlas (cloud)
# Update MONGODB_URI in .env file

# Seed database (optional)
npm run seed

📚 API Documentation

Base URL

Development: http://localhost:5000/api
Production: https://your-api-domain.com/api

Core Endpoints

Crops

GET /api/crops                     # List all crops with pagination
GET /api/crops/categories          # Get crop categories with counts  
GET /api/crops/:cropId             # Get detailed crop information
GET /api/crops/:cropId/advice      # Get all advice for specific crop

Advisory Content

GET /api/advice/:cropId/:topicId   # Get detailed crop-topic advice
GET /api/advice/:adviceId          # Get advice by ID
GET /api/advice/seasonal/:month    # Get seasonal advice for month
POST /api/advice/:adviceId/rate    # Rate an advice entry

Topics/Problems

GET /api/topics                    # List all problem categories
GET /api/topics/:topicId           # Get detailed topic information
GET /api/topics/:topicId/crops     # Get crops affected by topic

Search

GET /api/search?q={query}&language={lang}&category={cat}
GET /api/search/suggestions?q={query}

Seasonal Calendar

GET /api/calendar                  # Get 12-month agricultural calendar
GET /api/calendar/:month           # Get detailed month guidance
GET /api/calendar/current/guidance # Get current month's guidance

Query Parameters

  • language: Response language (english, hindi, kannada)
  • page: Page number for pagination (default: 1)
  • limit: Items per page (default: 10, max: 50)
  • sort: Sort field (name, created_at, view_count, rating)
  • order: Sort order (asc, desc)

Response Format

{
  "success": true,
  "data": {...},
  "pagination": {
    "current_page": 1,
    "total_pages": 5,
    "total_items": 50,
    "items_per_page": 10
  }
}

🗄 Database Schema

Collections Overview

Crops Collection

{
  id: "tomato",
  name: {
    english: "Tomato",
    hindi: "टमाटर", 
    kannada: "ಟೊಮೆಟೊ"
  },
  emoji: "🍅",
  category: "vegetables",
  description: { english: "...", hindi: "...", kannada: "..." },
  growing_seasons: ["kharif", "rabi"],
  topics: 12,
  view_count: 1250,
  featured: true
}

Advice Collection

{
  id: "tomato_water_stress",
  crop: "Tomato",
  crop_id: "tomato",
  problem: "Water Stress",
  topic_id: "water_stress",
  severity: "high",
  category: "water_management",
  effect: { english: "...", hindi: "...", kannada: "..." },
  advice: { english: "...", hindi: "...", kannada: "..." },
  action_steps: { english: [...], hindi: [...], kannada: [...] },
  prevention_tips: { english: [...], hindi: [...], kannada: [...] },
  scientific_explanation: "...",
  seasonal_relevance: ["march", "april", "may"],
  related_topics: ["tomato_heat_stress"]
}

Indexes for Performance

  • Text indexes for full-text search
  • Compound indexes for crop_id + topic_id queries
  • Single field indexes for common filters

🚀 Deployment

Frontend Deployment (Bolt Hosting)

# Build production version
npm run build

# Deploy to Bolt Hosting (automatic)
# Visit: https://farmwise-agricultura-20r1.bolt.host

Backend Deployment Options

Option 1: Heroku

# Install Heroku CLI
heroku create farmwise-api
heroku config:set NODE_ENV=production
heroku config:set MONGODB_URI=your-mongodb-atlas-uri
heroku config:set JWT_SECRET=your-production-secret
git push heroku main

Option 2: Docker

# Dockerfile (server/)
FROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm ci --only=production
COPY . .
EXPOSE 5000
CMD ["npm", "start"]

Option 3: DigitalOcean/AWS

# PM2 for production process management
npm install -g pm2
pm2 start server.js --name farmwise-api
pm2 startup
pm2 save

Environment Variables for Production

NODE_ENV=production
PORT=5000
MONGODB_URI=mongodb+srv://user:pass@cluster.mongodb.net/farmwise
JWT_SECRET=super-secure-production-secret-key
ALLOWED_ORIGINS=https://farmwise-agricultura-20r1.bolt.host

🤝 Contributing

We welcome contributions from the agricultural and developer communities!

How to Contribute

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

Contribution Areas

  • 🌾 Agricultural Content: Add crops, problems, seasonal guidance
  • 🌍 Translations: Improve Hindi/Kannada translations or add new languages
  • 🎨 UI/UX: Enhance farmer-friendly interface design
  • 🔧 Backend: API optimizations, new features, security improvements
  • 📱 Mobile: PWA enhancements, offline capabilities
  • 📚 Documentation: Improve guides, add tutorials

Development Guidelines

  • Follow existing code structure and naming conventions
  • Add proper validation for new endpoints
  • Include multi-language support for user-facing content
  • Write clear commit messages
  • Test thoroughly before submitting

Adding New Crops/Advice

// Add to server/scripts/seedDatabase.js
const newCrop = {
  id: 'mango',
  name: { 
    english: 'Mango', 
    hindi: 'आम', 
    kannada: 'ಮಾವಿನ ಹಣ್ಣು' 
  },
  emoji: '🥭',
  category: 'fruits',
  // ... additional fields
};

📄 License

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

MIT License

Copyright (c) 2025 FarmWise Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

🙏 Acknowledgments

  • Farmers: For inspiring this project and providing real-world insights
  • Agricultural Experts: For validating farming practices and advice
  • Open Source Community: For the amazing tools and libraries used
  • Translators: For Hindi and Kannada language support
  • Contributors: Everyone who helps improve FarmWise

📞 Support & Contact


Made with ❤️ for farmers worldwide

🌱 Growing better futures through technology 🌱

About

FarmWise is a mobile-first agricultural advisory web app that helps farmers access crop guidance, pest management, and seasonal advice in multiple languages (English, Hindi, Kannada). Features include crop-specific guidance for 9+ crops, problem diagnosis, seasonal calendar, and real-time search with offline support.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published