A complete, production-ready Machine Learning application for groundwater level prediction, featuring a stunning glassmorphism React UI with advanced analytics and a robust FastAPI ML backend.
HydroTech is an enterprise-grade, full-stack groundwater prediction system that combines cutting-edge machine learning with modern web technologies to deliver accurate, real-time groundwater level predictions. Live at: hydro-tech-mu.vercel.app
- π¨ Stunning UI: Dark mode glassmorphism design with animated backgrounds, smooth transitions, and professional data visualization
- π§ Advanced ML: Random Forest model with 91.1% RΒ² score, featuring uncertainty quantification and feature importance analysis
- π Rich Analytics: Interactive Chart.js visualizations, confidence intervals, seasonal trend analysis, and feature contribution breakdowns
- π Production-Ready: Deployed on Vercel (frontend) + Render.com (backend) with MongoDB Atlas database
- π Authentication: Google OAuth 2.0 integration for user management
- πΎ Database: MongoDB Atlas for prediction history and user profiles
- β‘ Real-Time: WebSocket support for live prediction updates
- π Weather Integration: OpenWeather API for automatic data population
- πΊοΈ Geospatial Intelligence: 4 distinct aquifer zones with unique physical properties
β¨ Frontend (React + TypeScript):
- π Dark mode glassmorphism design with backdrop blur effects
- π« Animated water ripple background using Framer Motion
- π Interactive charts (Bar & Doughnut) with Chart.js
- π― Real-time backend health monitoring
- οΏ½ Google OAuth authentication
- π Prediction history dashboard
- οΏ½π± Fully responsive design (desktop, tablet, mobile)
- β‘ Quick zone selection with preset locations
- π Smooth loading states and animations
- β Real-time form validation with error messages
- οΏ½οΈ Weather widget with live data
- π Time-series forecasting visualization
π§ Backend (Python + FastAPI):
- π€ Random Forest Regressor with 91.1% RΒ² score
- π 9,840 training samples across 4 zones
- πΊοΈ 4 aquifer zones: Urban, Agricultural, Coastal, Arid
- π§οΈ Advanced feature engineering (12 features including lag variables)
- π Uncertainty quantification with 95% confidence intervals
- π Feature importance and contribution analysis
- π‘οΈ Seasonal trend detection and analysis
- π‘ RESTful API with 20+ comprehensive endpoints
- πΎ MongoDB integration for data persistence
- β‘ WebSocket server for real-time updates
- π OpenWeather API integration
- π Time-series forecasting engine
- π Auto-generated Swagger documentation at
/docs
π Visit: https://hydro-tech-mu.vercel.app
- β Frontend hosted on Vercel (global CDN)
- β Backend hosted on Render.com (FREE tier)
- β Database hosted on MongoDB Atlas (M0 cluster)
- β 100% FREE deployment ($0/month)
- Node.js 18+ and npm
- Python 3.9+ and pip
- MongoDB Atlas account (FREE tier)
- Google Cloud project for OAuth (optional for local dev)
- OpenWeather API key (FREE tier)
# Install dependencies
npm install
# Start development server
npm run devFrontend will be available at: http://localhost:3000
# Navigate to backend
cd backend
# Install Python dependencies
pip install -r requirements.txt
# Generate dataset (9,840 samples across 4 zones)
python generate_dataset.py
# Train Random Forest model
python train_model.py
# Set environment variables (create .env file)
echo "MONGODB_URI=your-mongodb-connection-string" > .env
echo "OPENWEATHER_API_KEY=your-openweather-api-key" >> .env
# Start FastAPI server
python main.pyBackend will be available at: http://localhost:8000
API Docs (Swagger): http://localhost:8000/docs
Alternative Docs (ReDoc): http://localhost:8000/redoc
AI/
βββ src/ # Frontend Source
β βββ App.tsx # Main React component (800+ lines)
β β # - Glassmorphism UI components
β β # - Chart.js visualizations
β β # - Framer Motion animations
β β # - API integration
β βββ main.tsx # React entry point
β βββ index.css # TailwindCSS global styles
β
βββ backend/ # Backend ML System
β βββ generate_dataset.py # Dataset generation script
β β # - Creates 9,840 samples
β β # - 4 aquifer zones
β β # - Realistic correlations
β β
β βββ train_model.py # ML model training
β β # - Random Forest Regressor
β β # - 250 estimators, max_depth=25
β β # - 91.1% RΒ² score
β β # - Saves .joblib & metadata
β β
β βββ main.py # FastAPI server (500+ lines)
β β # - 20+ RESTful API endpoints
β β # - ML predictions
β β # - MongoDB integration
β β # - WebSocket support
β β # - Weather API integration
β β
β βββ database.py # MongoDB async operations
β β # - User management
β β # - Prediction history
β β # - Motor async driver
β β
β βββ forecasting.py # Time-series forecasting
β β # - Linear regression trends
β β # - 6-month predictions
β β
β βββ weather_service.py # OpenWeather integration
β β # - Current weather
β β # - 5-day forecast
β β # - Async aiohttp client
β β
β βββ websocket_manager.py # WebSocket connection manager
β β # - Real-time broadcasts
β β # - Connection handling
β β
β βββ zone_config.json # Zone configurations
β βββ groundwater_data.csv # Generated dataset (9,840 rows)
β βββ groundwater_model.joblib # Trained model (2.8 MB)
β βββ model_metadata.json # Model performance metrics
β
βββ Configuration Files
β βββ package.json # Node.js dependencies
β βββ requirements.txt # Python dependencies
β βββ vercel.json # Vercel deployment config
β β # - API rewrites to Render
β β # - COOP/COEP headers
β βββ tsconfig.json # TypeScript configuration
β βββ vite.config.ts # Vite build config
β βββ tailwind.config.js # TailwindCSS customization
β βββ postcss.config.js # PostCSS setup
β βββ index.html # HTML entry point
β
βββ Documentation
βββ README.md # This file
βββ PROJECT_REPORT.md
Architecture: Split Deployment (Frontend + Backend Separated)
graph LR
A[GitHub Repository] -->|Auto Deploy| B[Vercel - Frontend]
A -->|Auto Deploy| C[Render.com - Backend]
B -->|API Calls| C
C -->|Database| D[MongoDB Atlas]
C -->|Weather Data| E[OpenWeather API]
style B fill:#000,stroke:#fff,color:#fff
style C fill:#46e3b7,stroke:#000
style D fill:#00ed64,stroke:#000
style E fill:#f96854,stroke:#fff,color:#fff
Live URLs:
- Frontend: https://hydro-tech-mu.vercel.app
- Backend API: https://hydrotech.onrender.com
- API Docs: https://hydrotech.onrender.com/docs
# Create account at mongodb.com/cloud/atlas
# Create FREE M0 cluster
# Get connection string: mongodb+srv://username:password@cluster.mongodb.net/
# Add to environment variables# Push backend to GitHub
git push origin main
# On Render.com:
# 1. New Web Service
# 2. Connect GitHub repo
# 3. Root Directory: backend
# 4. Build Command: pip install -r requirements.txt
# 5. Start Command: python main.py
# 6. Add Environment Variables:
# - MONGODB_URI
# - OPENWEATHER_API_KEY# Vercel auto-detects Vite config
# Environment Variables:
VITE_API_BASE_URL=https://hydrotech.onrender.com
VITE_GOOGLE_CLIENT_ID=your-google-oauth-client-idAutomatic CI/CD:
git push origin main
# β Vercel rebuilds frontend (2-3 min)
# β Render rebuilds backend (5-7 min)
# β Both automatically deployed| Service | Tier | Cost | Limits |
|---|---|---|---|
| Vercel | Hobby | FREE | 100GB bandwidth, unlimited requests |
| Render.com | Free | FREE | 750 hours/month, 512MB RAM |
| MongoDB Atlas | M0 | FREE | 512MB storage, shared CPU |
| OpenWeather API | Free | FREE | 60 calls/min, 1M calls/month |
| Total | - | $0 | Suitable for 100+ concurrent users |
π See PROJECT_REPORT_PART3.md for detailed deployment walkthrough.
- React 18.3: Modern hooks (useState, useEffect, useCallback)
- TypeScript 5.5: Full type safety
- Vite 5.3: Lightning-fast HMR
- TailwindCSS 3.4: Utility-first styling
- Framer Motion 10.18: Smooth animations
- Chart.js 4.5: Data visualization
- Axios 1.13: HTTP client
- @react-oauth/google 0.12: Google OAuth integration
- React Leaflet 4.2: Map visualization (optional)
Color Scheme:
- Background:
bg-slate-900(very dark blue-gray) - Panels:
bg-gray-800/50(50% opacity) - Backdrop:
backdrop-blur-lg(frosted glass effect) - Borders:
border-gray-700/50(subtle) - Accent:
text-blue-400,text-cyan-400(bright, clear blue) - Text:
text-white,text-gray-200,text-gray-300
Animation Features:
- π Animated water ripple background (3 floating orbs)
- π« Smooth page transitions (Framer Motion)
- β‘ Loading spinners and skeleton states
- π― Hover effects on all interactive elements
- π Chart animations on data load
- AnimatedBackground: Floating gradient orbs
- GlassPanel: Reusable glass-effect container
- Header: Logo, title, status indicators
- StatusIndicator: Real-time backend health check
- Auth Component: Google OAuth login/logout
- PredictionForm: Input form with validation
- ResultsDisplay: Charts and prediction visualization
- StatisticsPanel: Model performance metrics
- HistoryDashboard: User prediction history
- WeatherWidget: Real-time weather display
- ForecastingPanel: Time-series forecast charts
- MapVisualization: Interactive Leaflet map (optional)
- FastAPI 0.115.5: Modern async web framework
- Uvicorn 0.32.1: ASGI server
- scikit-learn 1.3.2: ML pipeline & Random Forest
- Pandas 2.0.3 & NumPy 1.24.4: Data manipulation
- Motor 3.6.0: MongoDB async driver
- Pydantic 2.10.3: Data validation
- Aiohttp 3.10.11: Async HTTP client (weather API)
- WebSockets 13.1: Real-time communication
- Python-multipart 0.0.20: Form data parsing
- Python-dotenv 1.0.1: Environment variables
- Joblib: Model serialization
- 9,840 samples across 4 aquifer zones (82 months)
- 12 features including rainfall lag and rolling averages
- Realistic correlations:
- Rainfall β β Groundwater level β (+0.65 correlation)
- Temperature β β Evaporation β β Level β (-0.42 correlation)
- Monsoon months (June-Sep) β Higher levels (+3m boost)
- Zone-specific base levels and sensitivities
- Lag effects (1-2 month recharge delay)
Aquifer Zones:
| Zone | Name | Location | Avg Level | Characteristics |
|---|---|---|---|---|
| A | Urban | Delhi | 11.8m | High extraction, clay-sand soil |
| B | Agricultural | Lucknow | 26.6m | Best recharge, sandy-loam soil |
| C | Coastal | Chennai | 6.9m | Low level, sandy soil |
| D | Arid | Jaipur | 8.8m | Low rainfall, rocky soil |
- Algorithm: Random Forest Regressor (250 estimators, max_depth=25)
- Features: 12 engineered features
- Geospatial: latitude, longitude, aquifer_zone (one-hot encoded)
- Temporal: month, seasonal_index
- Meteorological: rainfall_mm, avg_temp_c
- Derived: rainfall_lag_1m, rainfall_lag_2m, rainfall_rolling_3m, rainfall_std_3m, temp_rainfall_interaction
- Preprocessing: One-hot encoding for categorical, standard scaling for numerical
- Performance:
- Test RΒ² = 0.9114 (91.14% variance explained)
- RMSE = 2.81 meters
- MAE = 2.13 meters
- 5-fold Cross-Validation RΒ² = 0.9124 Β± 0.0048
Key Features:
- 20+ RESTful endpoints (predictions, users, weather, forecasting, zones, statistics)
- MongoDB async operations (Motor driver)
- WebSocket server for real-time updates (
/ws/predictions) - OpenWeather API integration (current weather + 5-day forecast)
- Time-series forecasting (linear regression trends)
- Automatic zone detection from coordinates
- Historical rainfall lookup from zone config
- Multi-factor confidence score calculation:
- Zone reliability (based on feature importance)
- Seasonal data availability (monsoon vs dry season)
- Prediction reasonableness (typical range check)
- Data quality indicators (realistic input values)
- Uncertainty quantification (95% confidence intervals)
- Feature contribution analysis (SHAP-like attribution)
- CORS middleware for production deployment
- Comprehensive error handling and validation
GET /
{
"status": "healthy",
"model_loaded": true,
"version": "2.0.0",
"timestamp": "2025-10-28T..."
}POST /api/predict
Request:
{
"rainfall": 200.5,
"temperature": 28.3,
"latitude": 28.7,
"longitude": 77.2,
"month": "7"
}Response:
{
"predicted_level_meters": 15.67,
"confidence_score": 0.89
}POST /api/predict/detailed
Response:
{
"predicted_level_meters": 26.5,
"confidence_score": 0.89,
"prediction_interval": {
"lower": 21.0,
"upper": 32.0
},
"aquifer_zone": "B",
"zone_name": "Agricultural",
"feature_contributions": {
"rainfall_impact": 8.77,
"temperature_impact": -1.25,
"location_baseline": 15.96,
"seasonal_effect": 3.0
},
"seasonal_trend": "Monsoon Season - Rising water levels expected"
}POST /api/user/login
Request:
{
"id": "google-oauth-id",
"name": "Vikrant Kumar",
"email": "vikrantkrd@gmail.com",
"picture": "https://..."
}POST /api/predictions/save
Request:
{
"userId": "google-oauth-id",
"userName": "Vikrant Kumar",
"userEmail": "vikrantkrd@gmail.com",
"timestamp": "2025-10-28T10:30:00.000Z",
"input": {...},
"result": {...}
}GET /api/predictions/user/{userId}?limit=50
Returns array of user's prediction history.
GET /api/predictions/user/{userId}/zone/{zone}
Returns predictions for specific zone (A, B, C, or D).
GET /api/weather/current/{lat}/{lon}
Returns current weather from OpenWeather API (temp, rainfall, humidity, wind).
GET /api/weather/forecast/{lat}/{lon}?days=5
Returns 5-day weather forecast with 3-hour intervals.
POST /api/forecast/zone/{zone}
Request:
{
"months_ahead": 6,
"user_id": "optional-user-id"
}Returns 6-month groundwater level forecast based on historical trends.
GET /api/zones
Returns all 4 aquifer zones with configurations, lat/lon ranges, average rainfall by month, and physical properties.
GET /api/statistics
Returns comprehensive model performance metrics, dataset statistics, and feature importance.
GET /api/zones/{zone_code}/historical?month=7
Returns historical statistics for a specific zone (A, B, C, or D), optionally filtered by month.
WS /ws/predictions
Bidirectional WebSocket for real-time updates. Supports:
ping/pongheartbeatprediction_updatebroadcastsweather_updateeventsforecast_updatenotifications
Location: Agricultural Zone (Lucknow)
Rainfall: 300 mm
Temperature: 27Β°C
Latitude: 26.5
Longitude: 80.4
Month: August
Expected Result: ~28-32m (high groundwater level)
Location: Arid Zone (Jaipur)
Rainfall: 15 mm
Temperature: 42Β°C
Latitude: 26.9
Longitude: 75.8
Month: May
Expected Result: ~6-9m (low groundwater level)
Location: Chennai
Rainfall: 250 mm
Temperature: 30Β°C
Latitude: 13.0
Longitude: 80.2
Month: September
Expected Result: ~8-11m (moderate level)
Location: Delhi
Rainfall: 200 mm
Temperature: 28Β°C
Latitude: 28.7
Longitude: 77.2
Month: July
Expected Result: ~13-16m (moderate-high level)
- β¨ Geospatial Intelligence: 4 distinct aquifer zones with unique physical properties
- π§οΈ Temporal Dependencies: Rainfall lag features (1-2 months) capture recharge delay
- π Feature Engineering: 12 carefully crafted features including:
- Rolling averages (3-month rainfall)
- Standard deviation (rainfall variability)
- Temperature-rainfall interaction
- Seasonal indices
- π Uncertainty Quantification: 95% confidence intervals for predictions
- π― Feature Attribution: Real-time contribution analysis
- β Type Safety: TypeScript on frontend, Pydantic on backend
- β Error Handling: Comprehensive try-catch blocks and validation
- β CORS Enabled: Ready for production deployment
- β
API Documentation: Auto-generated Swagger docs at
/docs - β Modular Design: Reusable components and clean separation of concerns
- β Performance: Optimized React rendering with proper state management
- β Responsive: Mobile-first design with TailwindCSS
- β Animations: 60fps smooth animations with GPU acceleration
- β Loading States: User-friendly feedback for all async operations
- β Form Validation: Real-time validation with helpful error messages
- Reverse Geocoding: Automatically detect aquifer zone from lat/lon
- Historical Integration: Zone-specific rainfall averages by month
- Confidence Scoring: Multi-factor confidence calculation
- Seasonal Awareness: Different model behavior for monsoon vs dry seasons
- Visual Excellence: Professional glassmorphism design that impresses
Solution:
- Ensure backend is running:
cd backend && python main.py - Check backend is on port 8000: Look for "http://0.0.0.0:8000" in terminal
- Verify no firewall blocking localhost:8000
Solution:
cd backend
python train_model.py # This creates groundwater_model.joblib
python main.py # Now start serverSolution:
cd backend
python generate_dataset.py # Creates groundwater_data.csv
python train_model.py # Now train modelSolution:
rm -rf node_modules package-lock.json
npm install
npm run devPossible causes:
- Invalid input values (check ranges: rainfall 0-500, temp -10 to 50)
- Missing required fields
- Month should be string "1"-"12", not integer
- Check browser console for detailed error message
Solution:
- Ensure Chart.js is installed:
npm list chart.js - Clear browser cache (Cmd+Shift+R on Mac, Ctrl+Shift+R on Windows)
- Check browser console for errors
Possible causes:
- Backend not running locally (check API_BASE_URL in App.tsx)
- Large model file loading - normal on first request
- Subsequent requests should be fast (<100ms)
- Algorithm: Random Forest Regressor (250 estimators, max_depth=25)
- Test RΒ² Score: 0.9114 (91.14% variance explained) β
- Test RMSE: 2.81 meters
- Test MAE: 2.13 meters
- Cross-Validation: 5-fold CV, RΒ² = 0.9124 Β± 0.0048
- Out-of-Bag Score: 0.9117
- Training Time: ~3-5 seconds on standard laptop
- Prediction Time: <5ms per sample
- Model Size: 2.8 MB (.joblib file)
- Response Time: 50-100ms average
- Throughput: 100+ requests/second
- Startup Time: ~2-3 seconds
- Memory Usage: ~150-200MB
- Model Size: ~2-5MB (joblib file)
- First Contentful Paint: <1 second
- Time to Interactive: <2 seconds
- Animation FPS: Smooth 60fps
- Bundle Size: ~200-300KB (gzipped)
- Chart Rendering: <100ms
Total Documentation: ~15,000 words covering every aspect of the project including:
- Detailed technical explanations with diagrams (Mermaid)
- Common questions and answers for presentations
- System architecture deep-dive
- ML model selection rationale
- Demo scenarios and walkthroughs
- Novelty and innovation points
- Real-world impact analysis
This project demonstrates:
- Full-stack development (React + FastAPI)
- Machine learning pipeline (data β training β deployment)
- RESTful API design
- Modern UI/UX principles
- Type safety and validation
- Production-ready error handling
- Performance optimization
- Data visualization
- Production Deployment: Live at hydro-tech-mu.vercel.app with 100% uptime
- Professional Design: Stunning glassmorphism UI that rivals commercial applications
- Complete ML Pipeline: Dataset generation β Training β Deployment in one seamless flow
- Full-Stack Integration: React + FastAPI + MongoDB + Real-time WebSocket
- 91.1% Model Accuracy: Highly competitive RΒ² score with uncertainty quantification
- Real-world Application: Addresses India's critical groundwater crisis
- Advanced Features: OAuth, database persistence, weather API, time-series forecasting
- $0 Deployment Cost: Fully FREE tier infrastructure supporting 100+ users
- Comprehensive Documentation: 15,000+ words covering every technical detail
- Production Quality: Type safety, validation, error handling, monitoring, testing
- Novel ML Approach: Lag features, multi-zone modeling, dynamic confidence scoring
- User Experience: Smooth animations (60fps), real-time feedback, intuitive interface
For detailed Q&A and technical deep-dive, see PROJECT_QA.md.
This document covers:
- Architecture decisions
- ML model selection rationale
- Common invigilator questions
- Demo walkthroughs
- Troubleshooting scenarios
MIT License - Free to use, modify, and distribute
HydroTech Development Team
# Complete Setup (first time)
npm install
cd backend
pip install -r requirements.txt
python generate_dataset.py
python train_model.py
cd ..
# Daily Development
# Terminal 1 - Backend
cd backend && python main.py
# Terminal 2 - Frontend
npm run dev
# Rebuild Model
cd backend && python train_model.py
# Production Build
npm run build
# Deployment (Automatic via Git)
git add .
git commit -m "Update: Your changes"
git push origin main
# β Vercel rebuilds frontend (2-3 min)
# β Render rebuilds backend (5-7 min)
# Check Deployment Status
# Frontend: https://hydro-tech-mu.vercel.app
# Backend: https://hydrotech.onrender.com
# API Docs: https://hydrotech.onrender.com/docs- π Live Application: https://hydro-tech-mu.vercel.app
- π‘ Backend API: https://hydrotech.onrender.com
- π API Documentation: https://hydrotech.onrender.com/docs
- π GitHub Repository: github.com/vikrantwiz02/HydroTech
π HydroTech - Predicting the Future of Groundwater π§
Built with β€οΈ using React, TypeScript, FastAPI, Random Forest ML, and MongoDB
Tech Stack: React 18 β’ TypeScript 5 β’ Vite 5 β’ TailwindCSS 3 β’ Framer Motion 10 β’ Chart.js 4 β’ FastAPI 0.115 β’ scikit-learn 1.3 β’ MongoDB Atlas β’ Vercel β’ Render.com