Skip to content

Subham2005x/Kavach

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

40 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ›ก๏ธ Kavach - Disaster Alert & Risk Assessment System

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.


๐Ÿ“‹ Table of Contents


๐ŸŒŸ Overview

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

๐ŸŽฏ Problem Statement

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

โœจ Features

๐Ÿ—บ๏ธ Interactive Risk Map

  • Real-time visualization of disaster-prone areas
  • Heat map overlays for landslide and flood risks
  • Live weather data integration
  • Location-based risk assessment

๐Ÿค– ML-Powered Risk Prediction

  • 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

๐Ÿšจ Smart Alert System

  • 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

๐Ÿง  AI Disaster Assistant

  • Google Gemini-powered chatbot
  • Context-aware disaster guidance
  • Evacuation planning assistance
  • Real-time disaster news integration
  • Emergency contact information

๐Ÿ“ฐ Live News Feed

  • GNews API integration for disaster updates
  • Filtered by disaster keywords and location
  • Real-time alerts and emergency notifications

๐Ÿฅ Safe Zones & Resources

  • Emergency shelter locations
  • Hospital and medical facility finder
  • Police station and emergency services
  • Community support centers

๐Ÿ‘ค User Management

  • Firebase Authentication (Email/Password)
  • Secure user profiles
  • Persistent alert settings across devices
  • Cloud-based data synchronization

๐Ÿ› ๏ธ Tech Stack

Frontend

  • 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

Backend

  • FastAPI - Python web framework
  • Python 3.13 - Programming language
  • scikit-learn - Machine learning models
  • NumPy - Numerical computations
  • joblib - Model serialization

APIs & Services

  • Google Gemini AI - Conversational AI
  • Resend - Email delivery service
  • Twilio - SMS notifications
  • Open-Meteo - Weather data
  • GNews API - News aggregation
  • Firebase - Authentication & Firestore database

Development Tools

  • Git & GitHub - Version control
  • VS Code - Code editor
  • Postman - API testing

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                    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     โ”‚
                             โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿš€ Getting Started

Prerequisites

  • 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

Installation

1. Clone the Repository

git clone https://github.com/yourusername/kavach.git
cd kavach

2. Backend Setup

# 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

3. Frontend Setup

# Navigate to frontend directory
cd ../frontend

# Install dependencies
npm install

Configuration

Backend .env File

Create 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=+1234567890

How to Get API Keys:

  1. Gemini AI: https://makersuite.google.com/app/apikey
  2. GNews: https://gnews.io/
  3. Resend: https://resend.com/api-keys
  4. Twilio: https://www.twilio.com/console

Frontend .env File

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:8000

Firebase Setup:

  1. Go to https://console.firebase.google.com/
  2. Create a new project
  3. Enable Authentication (Email/Password)
  4. Create a Firestore Database
  5. Copy configuration from Project Settings

๐Ÿ’ป Usage

Running Locally

1. Start Backend Server

cd backend
myenv\Scripts\activate  # Windows
# source myenv/bin/activate  # macOS/Linux

uvicorn main:app --reload

Backend will run at: http://localhost:8000

2. Start Frontend Development Server

cd frontend
npm run dev

Frontend will run at: http://localhost:5173

3. Access the Application

Open your browser and navigate to http://localhost:5173

First Time Setup

  1. Create Account: Click "Sign Up" and register
  2. 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
  3. Test Alert System:
    • Click "Test Alert" button
    • Watch for spinner and loading state
    • Check your email (and spam folder)
  4. Explore Features:
    • View risk map
    • Try disaster simulations
    • Chat with AI assistant
    • Find safe zones

๐Ÿ“ก API Documentation

Base URL

  • Local: http://localhost:8000

Key Endpoints

Disaster Simulation

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": {...}
}

Alert Management

# 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/debug

AI Chat

POST /chat
Content-Type: application/json

{
  "message": "What should I do during a flood?",
  "history": []
}

News Feed

GET /news?disaster_type=flood&location=india&max_results=10

API Testing

# 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/

๐Ÿ”ง Troubleshooting

Email Alerts Not Working

Symptoms: Test email script works, but dashboard alerts don't send

Debug Steps:

  1. Open browser console (F12) - check logs for:
    • User ID being used
    • Email enabled status
    • "Email actually sent?" result
  2. Check backend terminal for:
    • "EMAIL SENT SUCCESSFULLY" message
    • Any error logs
  3. Visit http://localhost:8000/alert/debug to verify settings are saved
  4. 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.

SMS Not Working

Error: "The number +XXX is unverified"

Solution:

CORS Errors

Problem: Frontend can't reach backend

Solutions:

  • Verify VITE_API_URL matches your backend URL
  • Check backend CORS settings allow your frontend origin
  • Ensure both servers are running

Backend Connection Issues

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/Linux

Firebase Authentication Issues

Solutions:

  1. Enable Email/Password auth in Firebase Console
  2. Check Firestore rules allow authenticated access
  3. Verify Firebase config in .env

๐Ÿ“Š Project Structure

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

๐Ÿค Contributing

We welcome contributions! Here's how you can help:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Development Guidelines

  • Follow existing code style
  • Add comments for complex logic
  • Test thoroughly before submitting
  • Update documentation as needed
  • Use conventional commit messages

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ‘ฅ Team


๐Ÿ™ Acknowledgments

  • 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

๐Ÿ“ž Support

For issues, questions, or suggestions:

  • GitHub Issues: Create an issue on the repository
  • Email: nabiksubham2005@gmail.com
  • Documentation: Check the /docs folder for detailed guides

๐Ÿ”ฎ Future Enhancements

  • 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

๐Ÿ“ˆ Performance Metrics

  • 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+

๐Ÿ” Security

  • 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!

Report Bug ยท Request Feature ยท Documentation

Releases

Contributors

Languages