An AI-powered full-stack web application that predicts the best crop to cultivate based on soil parameters (N, P, K, pH) and climate conditions. The system features a microservices architecture with a Python-based Machine Learning service and a Node.js API Gateway, all connected to a responsive frontend.
- Dual Prediction Modes:
- 📍 Location Based: Auto-loads state-specific soil data (N, P, K) for Indian states; users only provide current climate info.
- ⚙️ Manual Mode: Allows detailed input of all parameters including Nitrogen, Phosphorus, Potassium, Temperature, Humidity, pH, and Rainfall.
- 🧠 Machine Learning: Uses a Random Forest Classifier trained on agricultural data to predict optimal crops with high confidence.
- 📊 Analytics Dashboard: Tracks total predictions, top recommended crops, and usage statistics.
- ⚡ Microservices Architecture: Separates the ML inference engine (Flask) from the application logic and database management (Node.js).
├── flask_api/ # Python Flask Service
│ └── app.py # ML Inference API
├── frontend/ # User Interface
│ ├── index.html # Main dashboard
│ ├── script.js # Frontend logic & API calls
│ └── style.css # Styling
├── ml_backend/ # Model Training & Data
│ ├── model_train.py # Script to train Random Forest model
│ ├── test_model.py # Script to test model accuracy
│ └── crop_recommendation.csv # Dataset (Required)
└── node_api/ # API Gateway & Database
└── server.js # Express server & MongoDB connectionThis service loads the trained model and handles prediction requests from the Node.js server.
# Navigate to the Flask API directory
cd ../flask_api
# Install dependencies
pip install flask flask-cors numpy
# Start the Flask Server
python app.py
Status: The Flask server will run on http://localhost:5000.This is the main API gateway that communicates with the frontend, database, and Flask service.
# Navigate to the Node API directory
cd ../node_api
# Install Node.js dependencies
npm install express mongoose cors axios dotenv
# Start the Node Server
node server.jsStatus: The Node API will run on http://localhost:3000. Database: Ensure your MongoDB is running on mongodb://localhost:27017/crop_recommendation or update the connection string in server.js.
The frontend is a static web application that connects to the Node.js API.
Navigate to the frontend/ folder.
Open index.html in your web browser.
Recommended: Use a local development server (like VS Code's Live Server extension) to open index.html. This avoids CORS issues that can occur when opening HTML files directly from the file system.
The system uses Node.js (Port 3000) as the primary entry point for the frontend.
Method Endpoint
POST /api/predictManual
POST /api/predict-by-location
GET /api/states
GET /api/stats