A comprehensive machine learning-powered web application that provides intelligent crop recommendations based on soil and environmental parameters. The system helps farmers and agricultural professionals make informed decisions about crop selection to optimize yield and sustainability.
- Features
- Technology Stack
- Architecture
- Prerequisites
- Quick Start with Docker
- Development Setup
- Usage
- API Documentation
- Project Structure
- Contributing
- License
To run docker containers first we need to pull the docker images
docker pull procoder588/crop_recommendation_frontend
docker pull procoder588/crop_recommendation_backend
To run the containers this is the command and be sure to update your backend and frontend urls
docker run -d --name CROPBackend -p 8000:8000 --network crop -e ALLOWED_URL=<your frontend url> procoder588/crop_recommendation_backend
docker run -d --name CROPFrontend -p 3000:3000 --network crop -e BACKEND_URL=<your backend url> procoder588/crop_recommendation_frontend
You could also run it directly using docker compose
docker compose up -d
- Smart Crop Recommendations: ML-powered predictions based on soil and environmental data
- Interactive Dataset Viewer: Browse and explore the training dataset
- Jupyter Notebook Integration: View the complete ML model development process
- Crop Gallery: Visual catalog of all supported crops with detailed information
- Real-time Predictions: Instant crop recommendations with confidence scores
- Responsive Design: Works seamlessly on desktop, tablet, and mobile devices
- Dark/Light Theme: Toggle between themes for better user experience
- Error Handling: Comprehensive error handling with user-friendly messages
- Health Monitoring: Built-in health checks for both frontend and backend
- Docker Support: Containerized deployment for easy scaling
- API-First Architecture: Clean separation between frontend and backend
- FastAPI: Modern, fast web framework for building APIs
- Python 3.11: Core programming language
- Scikit-learn: Machine learning library for model training and predictions
- XGBoost: Gradient boosting framework for enhanced model performance
- Pandas: Data manipulation and analysis
- NumPy: Numerical computing library
- Next.js 14: React framework with App Router
- TypeScript: Type-safe JavaScript development
- Tailwind CSS: Utility-first CSS framework
- Shadcn/ui: Modern UI component library
- Axios: HTTP client for API requests
- React Markdown: Markdown rendering for notebooks
- Docker: Containerization platform
- Docker Compose: Multi-container Docker applications
- Uvicorn: ASGI server for FastAPI
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β Frontend β β Backend β β ML Model β
β (Next.js) ββββββ (FastAPI) ββββββ (Scikit-learn)β
β Port: 3000 β β Port: 8000 β β (XGBoost) β
βββββββββββββββββββ βββββββββββββββββββ βββββββββββββββββββ
β β β
β βββββββββββββββββββ β
ββββββββββββββββ Docker ββββββββββββββββ
β Network β
βββββββββββββββββββ
The application follows a microservices architecture:
- Frontend: Next.js application serving the user interface
- Backend: FastAPI server handling ML predictions and data processing
- ML Model: Pre-trained models for crop recommendation
- Docker & Docker Compose: For containerized deployment
- Node.js 18+: For local frontend development
- Python 3.11+: For local backend development
- Git: For version control
The fastest way to get the application running:
# Clone the repository
git clone <repository-url>
cd crop-recommendation-system
# Start the application
docker-compose up -d
# View logs (optional)
docker-compose logs -f
The application will be available at:
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
cd backend
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Run the development server
python -m uvicorn app:app --reload --host 0.0.0.0 --port 8000
cd frontend
# Install dependencies
npm install
# Set up environment variables
cp .env.example .env.local
# Run the development server
npm run dev
-
Navigate to the Recommendation page
-
Enter the following parameters:
- Nitrogen (N): 0-300 kg/ha
- Phosphorous (P): 0-150 kg/ha
- Potassium (K): 0-300 kg/ha
- Temperature: -10 to 50Β°C
- Humidity: 0-100%
- pH Level: 0-14
- Rainfall: 0-1000mm
-
Click "Get Crop Recommendation"
-
View the recommended crop with confidence score and additional information
- Visit the Dataset page to browse the training data
- Use the "Load More" button to paginate through records
- Examine the relationship between input parameters and crop labels
- Navigate to the Notebook page
- Explore the complete machine learning pipeline
- View code cells, outputs, and visualizations
- Toggle between light and dark themes
- Development:
http://localhost:8000
- Production:
https://your-domain.com/api
GET /labels
Returns all available crop labels with associated images.
GET /data?page=1&size=100
Retrieve paginated dataset records.
POST /predict
Content-Type: application/json
{
"N": 90,
"P": 42,
"K": 43,
"temperature": 20.8,
"humidity": 82.0,
"ph": 6.5,
"rainfall": 202.9
}
GET /notebook
Retrieve the Jupyter notebook in JSON format.
GET /api/health
Returns service health status.
crop-recommendation-system/
βββ backend/
β βββ app.py # FastAPI application
β βββ requirements.txt # Python dependencies
β βββ Dockerfile # Backend container configuration
β βββ model/ # ML models
β βββ dataset/ # Training data
β βββ notebook/ # Jupyter notebooks
β βββ constants/ # Application constants
βββ frontend/
β βββ src/
β β βββ app/ # Next.js app router
β β βββ components/ # React components
β β βββ lib/ # Utility libraries
β β βββ types/ # TypeScript type definitions
β βββ package.json # Node.js dependencies
β βββ Dockerfile # Frontend container configuration
β βββ next.config.ts # Next.js configuration
βββ docker-compose.yml # Multi-container configuration
βββ README.md # This file
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Commit your changes:
git commit -m 'Add amazing feature'
- Push to the branch:
git push origin feature/amazing-feature
- Open a Pull Request
- Follow existing code style and conventions
- Add tests for new features
- Update documentation as needed
- Ensure Docker builds pass
- Test both frontend and backend changes
- Backend: Follow PEP 8 Python style guide
- Frontend: Use Prettier and ESLint configurations
- Commits: Use conventional commit messages
PYTHONPATH=/app
PYTHONUNBUFFERED=1
BACKEND_URL=http://localhost:8000
NEXT_PUBLIC_API_URL=http://localhost:3000
NODE_ENV=production
# Build and start all services
docker-compose up --build
# Start in detached mode
docker-compose up -d
# Stop all services
docker-compose down
# View logs
docker-compose logs -f [service-name]
# Rebuild a specific service
docker-compose build [service-name]
# Scale services
docker-compose up --scale backend=2
-
Port Already in Use
# Kill processes on specific ports sudo lsof -t -i:3000 | xargs kill -9 sudo lsof -t -i:8000 | xargs kill -9
-
Docker Build Fails
# Clean Docker cache docker system prune -a docker-compose build --no-cache
-
API Connection Issues
- Verify backend is running on port 8000
- Check CORS settings in FastAPI
- Ensure environment variables are set correctly
This project is licensed under the MIT License - see the LICENSE file for details.
- Development Team - Initial work and ongoing maintenance
- Scikit-learn community for excellent ML tools
- Next.js team for the amazing React framework
- FastAPI creators for the intuitive API framework
- Open source community for various libraries and tools
Happy Farming! ππΎ
For more information, please visit our documentation or contact our support team.