Skip to content

MUKARRAM-ONE/azure-disaster-response

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

37 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Azure Disaster Response Platform v2.0 🚨

A comprehensive full-stack disaster alert management system built with React 18 (Vite), Azure Functions (Python 3.12), Cosmos DB, and Azure Static Web Apps.

πŸ“‹ Project Overview

This platform enables:

  • πŸ‘₯ User Registration & Authentication with JWT and bcrypt hashing
  • πŸ“’ Disaster Alert Submission with real-time validation
  • πŸ“Š Admin Dashboard for alert verification and user management
  • πŸ” Security Features including rate limiting and input sanitization
  • ☁️ Full Azure Deployment with CI/CD automation

βœ… Production Ready - Live on Azure Static Web Apps!

🌐 Live Application: https://blue-sand-0ebf47300.1.azurestaticapps.net/

⭐ Core Features

  • βœ… Custom JWT Authentication - Email/password login with bcrypt hashing
  • βœ… Admin Dashboard - Verify/block/delete users and alerts
  • βœ… Real-time Filtering - Filter alerts by type, severity, location
  • βœ… Role-Based Access - Admin and user roles with permissions
  • βœ… Security Hardening - Rate limiting, input validation, sanitization
  • βœ… Cosmos DB - Globally distributed NoSQL database
  • βœ… Responsive React UI - Modern Vite-powered frontend
  • βœ… GitHub Actions CI/CD - Automated testing and deployment
  • βœ… Comprehensive Documentation - Complete deployment guides

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  React 18 (Vite)         β”‚  Frontend UI
β”‚  β€’ Auth Context          β”‚  β€’ Login/Register
β”‚  β€’ Dashboard             β”‚  β€’ Alert submission
β”‚  β€’ Admin Panel           β”‚  β€’ Real-time filtering
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚ JWT Bearer Token
             β”‚ HTTPS/CORS
             ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Azure Functions (Python)β”‚  Backend API
β”‚  β€’ AuthRegister          β”‚  β€’ User registration
β”‚  β€’ AuthLogin             β”‚  β€’ JWT token issuance
β”‚  β€’ SubmitAlert           β”‚  β€’ Alert creation
β”‚  β€’ GetAlerts             β”‚  β€’ Data retrieval
β”‚  β€’ Admin endpoints       β”‚  β€’ User/alert management
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
             β”‚ SDK Connection
             β”‚ Partition-based queries
             ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Cosmos DB (NoSQL)       β”‚  Database
β”‚  β€’ Users container       β”‚  β€’ Email & password hashes
β”‚  β€’ Alerts container      β”‚  β€’ Disaster alerts
β”‚  β€’ Global distribution   β”‚  β€’ Multi-region support
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Tech Stack Details

  • Frontend: React 18, Vite, Bootstrap 5, Axios
  • Backend: Azure Functions (Python 3.12), JWT, bcrypt
  • Database: Azure Cosmos DB (serverless)
  • Hosting: Azure Static Web Apps (frontend), Azure Functions (API)
  • CI/CD: GitHub Actions workflow
  • Infrastructure: Bicep templates for IaC

πŸ“ Project Structure

azure-disaster-response/
β”œβ”€β”€ frontend/                          # React Vite application
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ auth/
β”‚   β”‚   β”‚   └── AuthContext.jsx       # JWT token management
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ LoginPage.jsx         # Registration & login
β”‚   β”‚   β”‚   β”œβ”€β”€ AdminDashboard.jsx    # Admin panel
β”‚   β”‚   β”‚   β”œβ”€β”€ AlertsDashboard.jsx   # Alert list with filters
β”‚   β”‚   β”‚   β”œβ”€β”€ SubmitAlertForm.jsx   # Alert submission
β”‚   β”‚   β”‚   └── Navbar.jsx            # Navigation
β”‚   β”‚   β”œβ”€β”€ App.jsx
β”‚   β”‚   └── main.jsx
β”‚   β”œβ”€β”€ .env.production               # Production API URL
β”‚   └── vite.config.js
β”œβ”€β”€ AuthLogin/                         # Login function
β”œβ”€β”€ AuthRegister/                      # Registration function
β”œβ”€β”€ AuthMe/                            # Get current user
β”œβ”€β”€ SubmitAlert/                       # Submit disaster alert
β”œβ”€β”€ GetAlerts/                         # Retrieve all alerts
β”œβ”€β”€ GetAlert/                          # Get single alert
β”œβ”€β”€ VerifyAlert/                       # Admin: verify alert
β”œβ”€β”€ DeleteAlert/                       # Admin: delete alert
β”œβ”€β”€ VerifyUser/                        # Admin: verify user
β”œβ”€β”€ BlockUser/                         # Admin: block user
β”œβ”€β”€ DeleteUser/                        # Admin: delete user
β”œβ”€β”€ GetAllUsers/                       # Admin: list users
β”œβ”€β”€ auth_utils.py                      # JWT & hashing utilities
β”œβ”€β”€ security_utils.py                  # Rate limiting & validation
β”œβ”€β”€ requirements.txt                   # Python dependencies
β”œβ”€β”€ main.bicep                         # Full infrastructure template
β”œβ”€β”€ main-simple.bicep                  # Simplified template
β”œβ”€β”€ main-backend-only.bicep            # Backend-only template
β”œβ”€β”€ deploy-production.sh               # One-command deployment
β”œβ”€β”€ deploy-backend.sh                  # Backend deployment only
β”œβ”€β”€ .github/workflows/
β”‚   └── deploy-azure.yml              # CI/CD automation
β”œβ”€β”€ history/prompts/                   # Development session logs
└── README.md                          # This file

πŸš€ Quick Start (Local Development)

Prerequisites

  • Node.js 20+ (for frontend)
  • Python 3.12+ (for backend)
  • Azure Functions Core Tools v4
  • Git installed

Setup & Run Locally

1. Install Backend Dependencies

pip install -r requirements.txt

2. Install Frontend Dependencies

cd frontend
npm install
cd ..

3. Create Environment Files

Backend: local.settings.json

{
  "IsEncrypted": false,
  "Values": {
    "AzureWebJobsStorage": "UseDevelopmentStorage=true",
    "FUNCTIONS_WORKER_RUNTIME": "python",
    "COSMOS_ENDPOINT": "https://your-cosmos.documents.azure.com:443/",
    "COSMOS_KEY": "your-cosmos-key",
    "COSMOS_DATABASE_NAME": "DisasterResponseDB",
    "JWT_SECRET": "your-jwt-secret-min-32-chars",
    "JWT_EXPIRES_MINUTES": "10080"
  }
}

Frontend: frontend/.env.local

VITE_API_URL=http://localhost:7071/api

4. Start Backend

# Terminal 1
func start --python

5. Start Frontend

# Terminal 2
cd frontend
npm run dev

Access the Application

Test User Accounts

Email: [email protected]
Password: Admin@DisasterResponse123
Role: admin

(Or create new account via registration)

πŸ§ͺ Testing the APIs

Register a New User

curl -X POST http://localhost:7071/api/auth/register \
  -H "Content-Type: application/json" \
  -d '{
    "name": "John Doe",
    "email": "[email protected]",
    "password": "SecurePass123"
  }'

Login & Get Token

curl -X POST http://localhost:7071/api/auth/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "[email protected]",
    "password": "Admin@DisasterResponse123"
  }'

# Response includes JWT token
# Use: Authorization: Bearer <token>

Submit a Disaster Alert

curl -X POST http://localhost:7071/api/SubmitAlert \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN" \
  -d '{
    "type": "Flood",
    "location": "Downtown Seattle, WA",
    "severity": "Critical",
    "message": "Heavy rainfall causing flash floods in downtown area"
  }'

Get All Alerts

curl -X GET "http://localhost:7071/api/GetAlerts?limit=10" \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Admin: Verify an Alert

curl -X POST http://localhost:7071/api/admin/verify-alert \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer ADMIN_TOKEN" \
  -d '{
    "alertId": "alert-uuid",
    "verified": true
  }'

☁️ Azure Deployment

One-Command Deployment

# Ensure you have Azure CLI installed and logged in
az login

# Run the automated deployment script
./deploy-production.sh

# Follow the prompts to confirm deployment

This script will:

  • βœ… Create resource group
  • βœ… Deploy infrastructure via Bicep
  • βœ… Configure Function App settings
  • βœ… Deploy Python functions
  • βœ… Build and deploy React frontend
  • βœ… Output all URLs and connection info

Manual Deployment

See DEPLOYMENT_GUIDE.md for step-by-step instructions.

GitHub Actions CI/CD

Push to main branch - automatic deployment via .github/workflows/deploy-azure.yml:

git add .
git commit -m "Your message"
git push origin main

The workflow will:

  1. Run tests
  2. Build frontend and backend
  3. Deploy infrastructure
  4. Deploy functions
  5. Deploy frontend to Static Web Apps

Deployment Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  GitHub Actions Workflow (CI/CD)        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  1. Test & Build                        β”‚
β”‚  2. Deploy Infrastructure (Bicep)       β”‚
β”‚  3. Deploy Azure Functions (Python)     β”‚
β”‚  4. Deploy Frontend (Static Web Apps)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         ↓
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Azure Resources                        β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  β€’ Function App (Python 3.12)           β”‚
β”‚  β€’ Cosmos DB (Serverless)               β”‚
β”‚  β€’ Static Web App (React)               β”‚
β”‚  β€’ Application Insights (Monitoring)    β”‚
β”‚  β€’ Storage Account (Function storage)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“Š Data Schema (Cosmos DB)

Users Collection

{
  "id": "550e8400-e29b-41d4-a716-446655440000",
  "type": "user",
  "email": "[email protected]",
  "name": "User Name",
  "passwordHash": "bcrypt_hash_...",
  "role": "user",              // "user" or "admin"
  "verified": false,           // Admin verification status
  "blocked": false,            // Account blocked status
  "createdAt": "2026-01-11T12:00:00Z"
}

Alerts Collection

{
  "id": "alert-550e8400-e29b-41d4-a716-446655440001",
  "type": "Flood",             // Disaster type
  "severity": "High",          // Low | Medium | High | Critical
  "location": "Downtown Seattle, WA",
  "message": "Alert description and details...",
  "verified": false,           // Admin verification
  "verifiedAt": "2026-01-11T12:05:00Z",
  "verifiedBy": {
    "id": "admin-id",
    "email": "[email protected]",
    "name": "Admin Name"
  },
  "createdBy": {
    "id": "user-id",
    "email": "[email protected]",
    "name": "User Name"
  },
  "timestamp": "2026-01-11T12:00:00Z"
}

Partition Key

All documents use /type as partition key for optimal distribution.

οΏ½ Security Features

Authentication

  • JWT Tokens - HS256 with 7-day expiration
  • Bcrypt Hashing - 12-round password hashing
  • Bearer Token - Standard Authorization header
  • Session Persistence - localStorage token caching

Rate Limiting

  • Register: 5 requests per 5 minutes
  • Login: 10 requests per 5 minutes
  • Submit Alert: 20 requests per 5 minutes

Input Validation

  • Email: RFC format validation, max 254 chars
  • Password: Min 8 chars, letters + numbers required
  • Location: Alphanumeric, 3-200 chars
  • Message: 20-2000 character range
  • Type: Whitelist validation (Flood, Fire, Earthquake, etc.)
  • Severity: Whitelist validation (Low, Medium, High, Critical)

Data Sanitization

  • Removes control characters and null bytes
  • Truncates to safe length limits
  • Escapes dangerous input patterns

Security Headers

  • X-Content-Type-Options: nosniff
  • X-Frame-Options: DENY
  • X-XSS-Protection: 1; mode=block
  • Strict-Transport-Security: max-age=31536000
  • Content-Security-Policy: default-src 'self'

CORS Configuration

  • Configured for production domain
  • Allow credentials in production
  • Restrict to specific origins

πŸ› οΈ Technologies Used

Backend

  • Azure Functions v4 - Serverless compute runtime
  • Python 3.12 - Runtime environment
  • azure-functions - Azure Functions SDK
  • azure-cosmos - Cosmos DB SDK
  • pyjwt - JWT token encoding/decoding
  • bcrypt - Password hashing
  • pydantic - Data validation

Frontend

  • React 18 - UI framework
  • Vite 5.4 - Build tool and dev server
  • Bootstrap 5 - CSS framework
  • Axios - HTTP client
  • React Context API - State management

Infrastructure & DevOps

  • Azure Bicep - Infrastructure as Code
  • GitHub Actions - CI/CD pipeline
  • Azure Static Web Apps - Frontend hosting
  • Azure Cosmos DB - Serverless database
  • Azure Functions - Backend hosting
  • Application Insights - Monitoring and logging

οΏ½ API Endpoints

Authentication Endpoints

  • POST /api/auth/register - Create new account
  • POST /api/auth/login - Login and get JWT token
  • GET /api/auth/me - Get current user profile

Alert Endpoints (Requires Auth)

  • POST /api/SubmitAlert - Submit disaster alert
  • GET /api/GetAlerts - List all alerts (paginated)
  • GET /api/GetAlert/{id} - Get single alert details

Admin Endpoints (Requires Admin Role)

  • POST /api/admin/verify-alert - Verify an alert
  • POST /api/admin/delete-alert - Delete an alert
  • POST /api/admin/verify-user - Verify a user
  • POST /api/admin/block-user - Block a user
  • POST /api/admin/delete-user - Delete a user
  • GET /api/admin/users - List all users

Rate Limits by Endpoint

  • Auth endpoints: Per-client IP rate limiting
  • Alert endpoints: 20 req/5min per user
  • Admin endpoints: Admin-only access control

βœ… Project Completion Checklist

Core Features

  • βœ… User registration with email/password
  • βœ… Secure login with JWT tokens
  • βœ… Disaster alert submission with validation
  • βœ… Real-time alert filtering and search
  • βœ… Alert verification (admin feature)
  • βœ… User verification (admin feature)
  • βœ… User blocking/deletion (admin feature)
  • βœ… Alert deletion (admin feature)

Security

  • βœ… Bcrypt password hashing (12 rounds)
  • βœ… JWT authentication (HS256)
  • βœ… Rate limiting on auth endpoints
  • βœ… Input validation and sanitization
  • βœ… Security headers configured
  • βœ… CORS properly configured
  • βœ… Admin role-based access control

Frontend

  • βœ… React 18 with Vite
  • βœ… Responsive Bootstrap 5 UI
  • βœ… Auth context state management
  • βœ… Admin dashboard
  • βœ… Alert dashboard with filters
  • βœ… Login and registration forms
  • βœ… Real-time form validation

Backend

  • βœ… 11 Azure Functions (Python 3.12)
  • βœ… Cosmos DB integration
  • βœ… JWT token management
  • βœ… Admin endpoints
  • βœ… Error handling and logging
  • βœ… CORS middleware
  • βœ… Rate limiting decorator

DevOps & Infrastructure

  • βœ… Bicep infrastructure templates
  • βœ… Automated deployment scripts
  • βœ… GitHub Actions CI/CD pipeline
  • βœ… Azure Static Web Apps integration
  • βœ… Cosmos DB serverless setup
  • βœ… Application Insights monitoring
  • βœ… Environment variable management

Documentation

  • βœ… Comprehensive README
  • βœ… Deployment guide
  • βœ… Admin guide
  • βœ… API documentation
  • βœ… Setup instructions
  • βœ… Troubleshooting guide
  • βœ… Architecture diagrams

πŸ› Troubleshooting

Issue: "Failed to verify alert: Request failed with status code 404"

Solution:

  1. Ensure backend has been deployed with latest routes
  2. Run func start --python locally or redeploy to Azure
  3. Check that admin token is valid
  4. Verify function route is correct in admin endpoints

Issue: "CORS error in browser"

Solution:

  1. Ensure functions have CORS configured in host.json
  2. Check allowedOrigins includes your frontend URL
  3. For local dev, allowedOrigins: ["*"] is fine

Issue: "Unauthorized" error on admin endpoints

Solution:

  1. Verify you're logged in as admin user
  2. Check JWT token is valid (not expired)
  3. Confirm Bearer token is in Authorization header
  4. Check user has role: "admin" in Cosmos DB

Issue: "Cannot connect to Cosmos DB"

Solution:

  1. Verify COSMOS_ENDPOINT and COSMOS_KEY in local.settings.json
  2. Ensure Cosmos DB account is accessible
  3. Check network/firewall rules
  4. Verify connection string format

Issue: "Module not found - 'auth_utils' or 'security_utils'"

Solution:

  1. Ensure files are in project root: auth_utils.py, security_utils.py
  2. Run pip install -r requirements.txt
  3. Check function.json has correct scriptFile

Issue: "Rate limit exceeded" - 429 error

Solution:

  1. This is normal - wait before retrying
  2. Rate limits: Register 5/5min, Login 10/5min, Submit 20/5min
  3. Reset in 5 minutes or wait for time window to pass

πŸ“š Additional Resources

πŸ“„ License

This project is provided as-is for educational and commercial use.

πŸ‘€ Contributors

Azure Disaster Response Platform v2.0 Built with: React, Python, Azure, Cosmos DB


πŸ“– Documentation Files

πŸš€ Get Started

# Local development
func start --python    # Terminal 1: Backend
cd frontend && npm run dev  # Terminal 2: Frontend

# Production deployment
./deploy-production.sh

✨ Key Features

  • πŸ‘€ JWT Authentication with bcrypt hashing
  • πŸŽ›οΈ Admin Dashboard for content moderation
  • πŸ“Š Real-time alert filtering and search
  • πŸ”’ Security hardening with rate limiting
  • ☁️ Serverless Cosmos DB backend
  • πŸš€ GitHub Actions CI/CD automation

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors