A modern MERN stack application for precision farming, featuring real-time sensor monitoring, automated irrigation control, and weather integration.
SmartFarm is a comprehensive farm management platform that enables farmers to monitor soil conditions, manage multiple fields, track sensor readings in real-time, and make data-driven decisions for optimal crop yields.
- Multi-Field Management: Monitor and manage multiple farm fields from a single dashboard
- Real-Time Sensor Monitoring: Track soil moisture, temperature, pH levels, and more
- Automated Irrigation Control: Smart irrigation system based on soil moisture thresholds
- Weather Integration: Live weather data for informed decision-making
- Interactive Data Visualization: Charts and graphs powered by Recharts
- Geospatial Mapping: Location-based field visualization using Leaflet maps
- Alert System: Automated alerts for critical sensor readings
- Modern UI/UX: Clean, responsive design with custom theme system
- Secure Authentication: JWT-based login and registration
- Real-Time Updates: Live sensor data with automatic refresh
- Mobile Responsive: Works seamlessly across devices
- Node.js & Express: RESTful API server
- MongoDB Atlas: Cloud database for scalable data storage
- Mongoose: ODM for MongoDB
- JWT: Secure authentication
- Node-Cron: Automated task scheduling
- OpenWeatherMap API: Weather data integration
- React 19: Modern UI framework
- Vite: Fast build tool and dev server
- React Router: Client-side routing
- Axios: HTTP client
- Recharts: Data visualization
- Leaflet: Interactive maps
- CSS Variables: Custom theme system
SmartFarm/
βββ backend/
β βββ config/
β β βββ db.js # MongoDB Atlas connection
β βββ models/
β β βββ User.js # User schema
β β βββ Field.js # Field/Farm schema
β β βββ Sensor.js # Sensor schema
β β βββ Reading.js # Sensor reading schema
β β βββ Alert.js # Alert schema
β βββ routes/
β β βββ authRoutes.js # Authentication endpoints
β β βββ fieldRoutes.js # Field management
β β βββ sensorRoutes.js # Sensor operations
β β βββ readingRoutes.js # Sensor data retrieval
β β βββ alertRoutes.js # Alert management
β β βββ weatherRoutes.js # Weather API integration
β βββ utils/
β β βββ cronJobs.js # Automated irrigation logic
β β βββ sensorSimulator.js # Development data simulation
β βββ seedDatabase.js # Database seeding script
β βββ server.js # Express server entry point
β βββ package.json
β
βββ frontend/
β βββ src/
β β βββ api/
β β β βββ axios.js # Axios configuration
β β βββ components/
β β β βββ Navbar.jsx # Navigation component
β β β βββ AlertBanner.jsx # Alert notifications
β β β βββ SensorChart.jsx # Data visualization
β β β βββ SensorMap.jsx # Leaflet map component
β β β βββ WeatherCard.jsx # Weather display
β β βββ pages/
β β β βββ Home.jsx # Landing page
β β β βββ Login.jsx # Login page
β β β βββ Signup.jsx # Registration page
β β β βββ Dashboard.jsx # Main dashboard
β β β βββ FieldDetails.jsx # Field detail view
β β βββ themes/
β β β βββ theme.css # Custom theme variables
β β βββ App.jsx # Main app component
β β βββ main.jsx # React entry point
β βββ package.json
β βββ vite.config.js
β
βββ start.sh # Startup script
βββ stop.sh # Cleanup script
βββ package.json # Root package configuration
- Node.js (v14 or higher)
- npm or yarn
- MongoDB Atlas account (or local MongoDB)
- Clone the repository
git clone <repository-url>
cd SmartFarm- Install dependencies
npm installThis will install dependencies for both backend and frontend.
- Configure environment variables
Create a .env file in the backend/ directory:
PORT=5001
MONGO_URI=your_mongodb_atlas_connection_string
JWT_SECRET=your_jwt_secret_key
WEATHER_API_KEY=your_openweathermap_api_key- Seed the database (Optional)
cd backend
node seedDatabase.js
cd ..This creates sample farms, sensors, and initial data.
- Start the application
npm startThis runs both backend (port 5001) and frontend (port 5173) concurrently.
- Email: admin@smartfarm.com
- Password: admin123
- Email, password (hashed), name, role
- JWT authentication
- Farm ID, name, location, area
- Moisture thresholds for irrigation
- Sensor associations
- Type (moisture, temperature, pH, etc.)
- Field assignment
- Status and calibration data
- Sensor ID, timestamp, value, unit
- Historical data tracking
- Sensor triggers, severity levels
- Automatic notifications
POST /api/auth/register- User registrationPOST /api/auth/login- User login
GET /api/fields- Get all fieldsPOST /api/fields- Create new fieldGET /api/fields/:id- Get field detailsPUT /api/fields/:id- Update fieldDELETE /api/fields/:id- Delete field
GET /api/sensors- Get all sensorsPOST /api/sensors- Create sensorGET /api/sensors/field/:fieldId- Get field sensors
GET /api/readings/sensor/:sensorId- Get sensor readingsPOST /api/readings- Add new reading
GET /api/weather/:location- Get weather data
The application uses CSS variables for consistent theming:
--primary-green: #2d5016
--accent-green: #4a7c2c
--bg-white: #ffffff
--text-dark: #2c3e50All colors, spacing, shadows, and transitions are centralized in /frontend/src/themes/theme.css.
- Monitors soil moisture every minute
- Triggers irrigation when below threshold
- Automatic system deactivation at safe levels
- Generates realistic sensor data during development
- Simulates moisture, temperature, and pH variations
The application features:
- Responsive landing page with hero section
- Interactive dashboard with farm cards
- Detailed field view with sensor charts
- Real-time alerts and notifications
- Weather integration panel
Backend:
cd backend
npm run devFrontend:
cd frontend
npm run devcd frontend
npm run buildThis is an educational project. Feel free to fork and enhance!
This project is created for educational purposes.
Developed as a college project demonstrating full-stack MERN development skills.
- OpenWeatherMap for weather API
- MongoDB Atlas for cloud database
- React and Vite communities
- Leaflet for mapping capabilities
Note: This application demonstrates modern web development practices including RESTful API design, responsive UI, real-time data handling, and cloud database integration.