Kavach (Sanskrit: เคเคตเค, meaning "Shield" or "Armor") is an intelligent disaster risk assessment and alert system that helps communities prepare for and respond to natural disasters including floods, landslides, and extreme weather events.
- Overview
- Features
- Tech Stack
- Architecture
- Getting Started
- Usage
- API Documentation
- Troubleshooting
- Project Structure
- Contributing
- License
Kavach is a comprehensive disaster management platform that combines:
- Real-time Risk Assessment using Machine Learning models
- Interactive Mapping with live disaster visualization
- Smart Alert System with email and SMS notifications
- AI-Powered Insights using Google Gemini for disaster guidance
- News Aggregation for real-time disaster updates
- Safe Zone Identification and evacuation planning
Natural disasters cause significant loss of life and property. Early warning systems can save lives, but many communities lack access to sophisticated prediction and alert mechanisms. Kavach bridges this gap by providing:
- Accessible risk assessment for landslides and floods
- Personalized alert thresholds
- Real-time weather data integration
- AI-powered disaster preparedness guidance
- Real-time visualization of disaster-prone areas
- Heat map overlays for landslide and flood risks
- Live weather data integration
- Location-based risk assessment
- Landslide Risk Classifier: Random Forest model trained on terrain, rainfall, and soil data
- Flood Risk Regressor: Predicts flood depth based on rainfall intensity, duration, and drainage
- Live weather API integration for current conditions
- Customizable simulation parameters
- Customizable alert thresholds for different disaster types
- Multi-channel notifications (Email + SMS)
- Email alerts via Resend API (cloud-compatible)
- SMS alerts via Twilio API
- Alert history tracking
- Real-time testing with loading indicators
- Google Gemini-powered chatbot
- Context-aware disaster guidance
- Evacuation planning assistance
- Real-time disaster news integration
- Emergency contact information
- GNews API integration for disaster updates
- Filtered by disaster keywords and location
- Real-time alerts and emergency notifications
- Emergency shelter locations
- Hospital and medical facility finder
- Police station and emergency services
- Community support centers
- Firebase Authentication (Email/Password)
- Secure user profiles
- Persistent alert settings across devices
- Cloud-based data synchronization
- React 18 - UI framework
- Vite - Build tool and dev server
- Leaflet - Interactive mapping
- Chart.js - Data visualization
- Lucide React - Icon library
- Firebase SDK - Authentication & Firestore
- FastAPI - Python web framework
- Python 3.13 - Programming language
- scikit-learn - Machine learning models
- NumPy - Numerical computations
- joblib - Model serialization
- Google Gemini AI - Conversational AI
- Resend - Email delivery service
- Twilio - SMS notifications
- Open-Meteo - Weather data
- GNews API - News aggregation
- Firebase - Authentication & Firestore database
- Git & GitHub - Version control
- VS Code - Code editor
- Postman - API testing
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ KAVACH SYSTEM โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ FRONTEND โ โ BACKEND API โ
โ (React + Vite) โ โโโโโโบ โ (FastAPI) โ
โ โ โ โ
โ - Dashboard โ โ - ML Models โ
โ - Risk Map โ โ - Simulations โ
โ - Alerts UI โ โ - Alert Logic โ
โ - AI Chat โ โ - Weather API โ
โโโโโโโโโโฌโโโโโโโโโโ โโโโโโโโโโฌโโโโโโโโโโ
โ โ
โผ โผ
โโโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโโ
โ FIREBASE โ โ EXTERNAL APIs โ
โ โ โ โ
โ - Auth โ โ - Gemini AI โ
โ - Firestore โ โ - Resend Email โ
โ - Hosting โ โ - Twilio SMS โ
โโโโโโโโโโโโโโโโโโโโ โ - Open-Meteo โ
โ - GNews API โ
โโโโโโโโโโโโโโโโโโโโ
- Node.js 18+ and npm
- Python 3.10+
- Git
- Firebase Account (free tier)
- API Keys for:
- Google Gemini AI
- Resend (email)
- Twilio (SMS, optional)
- GNews API
git clone https://github.com/yourusername/kavach.git
cd kavach# Navigate to backend directory
cd backend
# Create virtual environment
python -m venv myenv
# Activate virtual environment
# Windows:
myenv\Scripts\activate
# macOS/Linux:
source myenv/bin/activate
# Install dependencies
pip install -r requirements.txt# Navigate to frontend directory
cd ../frontend
# Install dependencies
npm installCreate backend/.env:
# Gemini AI API Key
GEMINI_API_KEY=your_gemini_api_key_here
# GNews API Key
GNEWS_API_KEY=your_gnews_api_key_here
# Email Configuration (Resend)
RESEND_API_KEY=your_resend_api_key_here
SENDER_EMAIL=your_email@example.com
# SMS Configuration (Twilio - Optional)
TWILIO_ACCOUNT_SID=your_twilio_account_sid
TWILIO_AUTH_TOKEN=your_twilio_auth_token
TWILIO_PHONE_NUMBER=+1234567890How to Get API Keys:
- Gemini AI: https://makersuite.google.com/app/apikey
- GNews: https://gnews.io/
- Resend: https://resend.com/api-keys
- Twilio: https://www.twilio.com/console
Create frontend/.env:
# Firebase Configuration
VITE_FIREBASE_API_KEY=your_firebase_api_key
VITE_FIREBASE_AUTH_DOMAIN=your-project.firebaseapp.com
VITE_FIREBASE_PROJECT_ID=your-project-id
VITE_FIREBASE_STORAGE_BUCKET=your-project.appspot.com
VITE_FIREBASE_MESSAGING_SENDER_ID=123456789
VITE_FIREBASE_APP_ID=1:123456789:web:abcdef
VITE_FIREBASE_MEASUREMENT_ID=G-ABCDEFG
# Backend API URL
VITE_API_URL=http://localhost:8000Firebase Setup:
- Go to https://console.firebase.google.com/
- Create a new project
- Enable Authentication (Email/Password)
- Create a Firestore Database
- Copy configuration from Project Settings
cd backend
myenv\Scripts\activate # Windows
# source myenv/bin/activate # macOS/Linux
uvicorn main:app --reloadBackend will run at: http://localhost:8000
cd frontend
npm run devFrontend will run at: http://localhost:5173
Open your browser and navigate to http://localhost:5173
- Create Account: Click "Sign Up" and register
- Configure Alerts:
- Click the bell icon (Alert Settings)
- Enter your email address
- Set risk thresholds (lower for testing: 50, 50, 80)
- Enable email alerts
- Save settings
- Test Alert System:
- Click "Test Alert" button
- Watch for spinner and loading state
- Check your email (and spam folder)
- Explore Features:
- View risk map
- Try disaster simulations
- Chat with AI assistant
- Find safe zones
- Local:
http://localhost:8000
POST /simulate
Content-Type: application/json
{
"lat": 20.2961,
"lon": 85.8245,
"rainfall_intensity": 50.0,
"duration_hours": 24,
"soil_moisture": 0.5,
"use_live_weather": true
}
Response:
{
"landslide_risk": 75,
"flood_risk": 65,
"risk_level": "HIGH",
"weather_data": {...}
}# Save Settings
POST /alert/settings?user_id={user_id}
Content-Type: application/json
{
"email": "user@example.com",
"phone": "+1234567890",
"landslide_threshold": 70,
"flood_threshold": 60,
"enable_email": true
}
# Get Settings
GET /alert/settings?user_id={user_id}
# Test Alerts
POST /alert/check?user_id={user_id}
{
"landslide_risk": 85,
"flood_risk": 75,
"rainfall": 120,
"location": "Location Name"
}
# Debug Settings (Development)
GET /alert/debugPOST /chat
Content-Type: application/json
{
"message": "What should I do during a flood?",
"history": []
}GET /news?disaster_type=flood&location=india&max_results=10# Test email system
cd backend
python test_email_quick.py
# Check stored alert settings
curl http://localhost:8000/alert/debug
# Test API health
curl http://localhost:8000/Symptoms: Test email script works, but dashboard alerts don't send
Debug Steps:
- Open browser console (F12) - check logs for:
- User ID being used
- Email enabled status
- "Email actually sent?" result
- Check backend terminal for:
- "EMAIL SENT SUCCESSFULLY" message
- Any error logs
- Visit
http://localhost:8000/alert/debugto verify settings are saved - Ensure same user ID is used for saving and testing
Common Causes:
- Settings not saved (backend restarted)
- User ID mismatch
- Email toggle is OFF
- Not logged in (using 'default' instead of actual UID)
See EMAIL_DEBUG_GUIDE.md for detailed debugging.
Error: "The number +XXX is unverified"
Solution:
- Verify your phone at: https://www.twilio.com/console/phone-numbers/verified
- Or upgrade Twilio account to remove trial restrictions
Problem: Frontend can't reach backend
Solutions:
- Verify
VITE_API_URLmatches your backend URL - Check backend CORS settings allow your frontend origin
- Ensure both servers are running
Problem: "Network Error" or "Failed to fetch"
Solutions:
# Verify backend is running
curl http://localhost:8000/
# Check if port 8000 is in use
netstat -ano | findstr :8000 # Windows
lsof -i :8000 # macOS/LinuxSolutions:
- Enable Email/Password auth in Firebase Console
- Check Firestore rules allow authenticated access
- Verify Firebase config in
.env
kavach/
โโโ backend/
โ โโโ main.py # FastAPI application
โ โโโ requirements.txt # Python dependencies
โ โโโ .env # Environment variables
โ โโโ Dockerfile # Docker configuration (optional)
โ โโโ ml_models/ # Trained ML models
โ โ โโโ flood_regressor.joblib
โ โ โโโ landslide_classifier.joblib
โ โโโ static/ # Static frontend files
โ โโโ test_email_quick.py # Email testing script
โ โโโ myenv/ # Python virtual environment
โ
โโโ frontend/
โ โโโ src/
โ โ โโโ components/ # React components
โ โ โ โโโ charts/ # Chart components
โ โ โ โโโ controls/ # Control panels
โ โ โ โโโ map/ # Map components
โ โ โ โโโ panels/ # Side panels (Alerts, etc.)
โ โ โ โโโ ui/ # Reusable UI components
โ โ โโโ pages/ # Page components
โ โ โ โโโ Dashboard/ # Main dashboard
โ โ โ โโโ Home/ # Landing page
โ โ โ โโโ Login/ # Authentication pages
โ โ โโโ config/ # Configuration
โ โ โ โโโ firebase.js # Firebase config
โ โ โ โโโ index.js
โ โ โโโ services/ # API services
โ โ โ โโโ api.service.js # Backend API calls
โ โ โ โโโ auth.service.js # Auth services
โ โ โโโ context/ # React contexts
โ โ โ โโโ Authcontext/ # Authentication context
โ โ โโโ hooks/ # Custom React hooks
โ โ โโโ utils/ # Utility functions
โ โ โโโ styles/ # Global styles
โ โโโ public/ # Public assets
โ โโโ package.json # Node dependencies
โ โโโ vite.config.js # Vite configuration
โ โโโ firebase.json # Firebase config
โ โโโ firestore.rules # Firestore security rules
โ โโโ .env # Environment variables
โ
โโโ README.md # This file
โโโ ALERT_SYSTEM_FLOW.md # Alert system documentation
โโโ ALERT_SYSTEM_FIXED.md # Alert fixes documentation
โโโ EMAIL_DEBUG_GUIDE.md # Email debugging guide
We welcome contributions! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
- Follow existing code style
- Add comments for complex logic
- Test thoroughly before submitting
- Update documentation as needed
- Use conventional commit messages
This project is licensed under the MIT License - see the LICENSE file for details.
- Developer: Subham Nabik
- Email: nabiksubham2005@gmail.com
- Institution: [Your Institution Name]
- Google Gemini AI for intelligent disaster guidance
- Resend for reliable email delivery
- Twilio for SMS services
- Open-Meteo for weather data
- Firebase for authentication and database
- scikit-learn community for ML tools
- React and FastAPI communities
For issues, questions, or suggestions:
- GitHub Issues: Create an issue on the repository
- Email: nabiksubham2005@gmail.com
- Documentation: Check the
/docsfolder for detailed guides
- Mobile app (React Native)
- Real-time earthquake monitoring
- Drone integration for disaster assessment
- Community reporting system
- Offline mode for emergency situations
- Multi-language support (Hindi, regional languages)
- Integration with government emergency services
- Advanced ML models (Deep Learning, LSTM for time-series)
- Historical disaster data analysis
- Predictive analytics dashboard
- WebSocket support for real-time updates
- Push notifications for mobile
- Backend Response Time: < 500ms (average)
- ML Model Inference: < 200ms
- Email Delivery: 5-30 seconds
- SMS Delivery: 10-60 seconds
- Frontend Load Time: < 2s
- Supported Concurrent Users: 100+
- Firebase Authentication with secure token management
- Environment variables for sensitive data
- HTTPS/SSL for all production deployments
- CORS configuration for authorized origins only
- Firestore security rules for data protection
- Input validation and sanitization
- Rate limiting on API endpoints
Made with โค๏ธ for Disaster Preparedness
Save Lives โข Protect Communities โข Build Resilience
โญ Star this repository if you found it helpful!