🧠 Detect crop and livestock diseases using AI-powered image & symptom analysis. Farmers upload an image or describe symptoms → AI predicts disease → backend provides recommendations & alerts veterinarians.
Architecture Flow
Farmer WebApp (React) → FastAPI Backend → AI Model (TensorFlow/PyTorch) → MongoDB Database → Notification Service (Email / SMS via Twilio)
Key Features
- 🖼️ Upload crop/livestock images
- 💬 Text-based symptom input
- 🤖 AI model for disease classification
- 🩺 Vet alert for critical cases
- 📊 Admin dashboard for analytics
| Component | Technology |
|---|---|
| Frontend | React + Tailwind CSS |
| Backend | FastAPI (Python) |
| AI Model | TensorFlow / PyTorch |
| Database | MongoDB (Atlas or Local) |
| Notifications | Twilio / EmailJS |
disease-detection/
│
├── backend/ # FastAPI Backend
│ ├── main.py # Application entry point
│ ├── config.py # Configuration & settings
│ ├── database.py # MongoDB connection
│ ├── requirements.txt # Python dependencies
│ ├── .env.example # Environment template
│ ├── models/ # Data models
│ │ ├── user.py
│ │ ├── disease_report.py
│ │ └── veterinarian.py
│ ├── routes/ # API endpoints
│ │ ├── auth.py # Authentication
│ │ ├── diagnosis.py # Disease detection
│ │ ├── admin.py # Admin dashboard
│ │ └── veterinarians.py # Vet management
│ ├── services/ # Business logic
│ │ ├── auth.py # JWT & authentication
│ │ └── notification.py # Email/SMS alerts
│ └── uploads/ # Uploaded images
│
├── frontend/ # React Frontend
│ ├── src/
│ │ ├── App.jsx # Main component
│ │ ├── main.jsx # Entry point
│ │ ├── pages/ # Page components
│ │ │ ├── Home.jsx
│ │ │ ├── Login.jsx
│ │ │ ├── Register.jsx
│ │ │ ├── Upload.jsx
│ │ │ ├── Results.jsx
│ │ │ ├── Dashboard.jsx
│ │ │ └── AdminDashboard.jsx
│ │ ├── components/ # Reusable UI
│ │ │ └── Navbar.jsx
│ │ ├── context/ # State management
│ │ │ └── AuthContext.jsx
│ │ └── api/ # API client
│ │ └── api.js
│ ├── package.json
│ ├── vite.config.js # Vite config
│ └── tailwind.config.js # Tailwind CSS
│
├── ai_model/ # AI/ML Module
│ ├── inference.py # Disease detection (hardcoded)
│ ├── sample_images/ # Sample disease images
│ └── README.md # Model documentation
│
├── SETUP_GUIDE.md # Detailed setup instructions
├── TESTING_GUIDE.md # Testing documentation
└── README.md # This file
- Python 3.8+
- Node.js 16+
- MongoDB (Atlas or Local)
-
Clone the repository
cd /workspaces/disease-detection -
Backend Setup
cd backend python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt cp .env.example .env # Edit .env with your MongoDB URL and other settings python main.py
Backend runs on: http://localhost:8000
-
Frontend Setup (New Terminal)
cd frontend npm install npm run devFrontend runs on: http://localhost:3000
-
MongoDB Setup
- Create free account at MongoDB Atlas
- Create cluster and get connection string
- Add connection string to
backend/.env
- Complete Setup Guide - Step-by-step installation with troubleshooting
- Testing Guide - How to test all features and verify functionality
- Register at http://localhost:3000/register
- Login and go to Upload
- Select "tomato" as type
- Upload image (name it
tomato_blight.jpgfor testing) - Add symptoms: "brown spots, wilting"
- View diagnosis results!
| Layer | Platform | Purpose |
|---|---|---|
| Backend | Render | Auto deploy FastAPI server |
| Database | MongoDB Atlas | Cloud database |
| Frontend | Vercel | Deploy React web app |
- Farmer opens the web app and uploads an image.
- The backend receives it and sends it to the AI model.
- The model predicts the disease.
- The backend stores the report and sends recommendations.
- A notification is sent to the nearest veterinarian if needed.
- Admins can view disease trends and reports through the dashboard.
✅ User Authentication - Register, Login, JWT-based auth
✅ Image Upload - Multi-part form data handling
✅ Disease Detection - 15 hardcoded diseases with pattern matching
✅ Symptom Analysis - Text-based disease prediction
✅ Confidence Scoring - AI confidence levels
✅ Vet Notifications - Automatic alerts for critical cases
✅ User Dashboard - View all diagnosis reports
✅ Admin Dashboard - Analytics with charts & graphs
✅ Responsive UI - Mobile-friendly design
✅ MongoDB Integration - Cloud or local database
✅ API Documentation - Interactive Swagger UI at /docs
This version uses a hardcoded disease database instead of a trained ML model for quick testing:
-
15 Diseases Covered:
- 8 Crop Diseases (Tomato Blight, Wheat Rust, Rice Blast, etc.)
- 7 Livestock Diseases (FMD, Newcastle, Mastitis, etc.)
-
Detection Method:
- Image filename pattern matching
- Symptom keyword matching
- Hash-based consistent assignment
-
For Production:
- Replace
ai_model/inference.pywith actual TensorFlow/PyTorch model - Train on real disease image datasets
- Implement proper image preprocessing
- Replace
POST /api/auth/register- Register new userPOST /api/auth/login- Login and get JWT tokenGET /api/auth/me- Get current user
POST /api/diagnosis/detect- Upload image and detect diseaseGET /api/diagnosis/reports- Get user's reportsGET /api/diagnosis/reports/{id}- Get specific report
GET /api/admin/dashboard- Dashboard statisticsGET /api/admin/reports- All reportsGET /api/admin/analytics- Analytics data
POST /api/veterinarians/- Create veterinarianGET /api/veterinarians/- List veterinariansGET /api/veterinarians/{id}- Get vet details
Interactive API Docs: http://localhost:8000/docs
- Password hashing with bcrypt
- JWT token authentication
- Role-based access control (Farmer, Vet, Admin)
- CORS configuration
- Input validation with Pydantic
- Replace hardcoded detection with trained CNN model
- Integration with weather-based disease prediction
- Multilingual support (Marathi, Hindi, English)
- Offline functionality using PWA
- GIS heatmaps to identify outbreak zones
- Mobile app (React Native)
- Real-time chat with veterinarians
- Blockchain for disease report verification
Backend won't start:
- Check MongoDB connection string in
.env - Ensure virtual environment is activated
- Verify Python 3.8+ is installed
Frontend won't start:
- Delete
node_modulesand runnpm installagain - Check Node.js version (16+ required)
- Ensure backend is running on port 8000
Disease detection not working:
- Name images with disease keywords (e.g.,
tomato_blight.jpg) - Add relevant symptoms
- Check backend logs for errors
See SETUP_GUIDE.md for detailed troubleshooting.
- 📖 Complete Setup Guide
- 🧪 Testing Guide
- � API Documentation (when running)
- 💾 Database Schema
This project is for educational purposes. Feel free to use and modify as needed.
- FastAPI for the amazing Python web framework
- React + Vite for the frontend
- MongoDB for the database
- Tailwind CSS for styling
- Recharts for data visualization
Made with ❤️ for farmers and agriculture professionals