AI-powered Air Quality Monitoring, Forecasting & Personalized Early Warning System for Ho Chi Minh City
Ensemble AI Β· Real-time Anomaly Detection Β· Personalized Activity Scheduling Β· WHO Dose Budget
React + TypeScript Β· ASP.NET Core 8 Β· FastAPI Β· PostgreSQL Β· Docker
π Explore the Dashboard Β» Β |Β πΉ Demo Script Β |Β π Report Bug Β |Β π Request Feature Β |Β π¬ Support
WEBSITE & AI INNOVATION
Objective: Build an AI-powered platform that monitors, forecasts, and delivers personalized air quality warnings for citizens of Ho Chi Minh City β especially vulnerable groups including children, the elderly, pregnant women, and people with respiratory conditions.
Core Innovation Highlights:
- β Ensemble Forecasting β Random Forest + ARIMA + XGBoost with dynamic inverse-MAE weighting
- β Real-time Anomaly Detection β XAI-powered spike detection with feature-level explanation
- β Personalized Activity Scheduling β AI-optimized schedule with WHO Dose Budget tracker
- β Compound Risk Scoring β PM2.5 Γ Temperature Γ Humidity Γ UV Index Γ Wind
- β District-level Heatmap β 22 quαΊn/huyα»n real-time AQI visualization
- β Safety Gamification β Streak system + 11 health achievement badges
AI Dashboard
|
Activity Planner
|
District Heatmap
|
Anomaly Detection
|
PM2.5 Guide
|
AI Assistant
|
Most air quality apps only show current readings β you see the danger after it's already there.
AirSafeNet moves from reactive observation β proactive early warning:
| Problem | AirSafeNet Solution |
|---|---|
| Static AQI numbers | 7-day hourly PM2.5 forecast with confidence scoring |
| One-size-fits-all alerts | 5 user groups with personalized risk multipliers |
| No activity guidance | Smart Schedule Optimizer + Golden Hour Picker |
| Ignores weather factors | Compound Risk = PM2.5 Γ Temp Γ Humidity Γ UV Γ Wind |
| No health quantification | WHO Dose Budget (225 Β΅g/day) with real-time tracking |
| Reactive anomaly alerts | Real-time XAI spike detection with interrupt alerts |
- Ensemble Model β 3-model weighted average with dynamic evaluation every compute cycle
- 7-day hourly forecast β iterative multi-step prediction with delta clamping
- Confidence bands β per-step uncertainty (Β±Β΅g/mΒ³, 95% CI approximation)
- APScheduler β auto-recompute every 60 minutes, cached CSVs served to all clients
- Model versioning β see MODEL_VERSIONING.md
- Spike detection β SPIKE_THRESHOLD=20 Β΅g/mΒ³, LOOKBACK=6h, COOLDOWN=2h
- XAI explanation β feature importance Γ delta β top contributing factors
- AQI Spike Interrupt β real-time overlay alert when spike occurs during active activity
- Telegram + Email β push notifications with group-specific advice
- Smart Schedule Optimizer β AI proposes top-3 time slots based on 24h forecast
- Golden Hour Picker β interactive 24h AQI heatmap bar chart
- Weekly Planner β 7Γ24 drag-and-drop grid with AQI background heatmap
- Weekly Risk Matrix β activity vs. day-of-week risk comparison (30-day history)
- Pattern Insight β detects recurring bad-day / bad-hour patterns from history
- Exposure Log β 30-day PM2.5 intake log (bar chart + table)
- 5 user groups: Normal / Child / Elderly / Respiratory / Pregnant
- Borg CR-10 Scale β predicted exertion level per activity
- Mask Recommendation β None / Surgical / KF94 / N95 / N99 by AQI + group
- Max Outdoor Time β WHO-derived limits per group + intensity
- Dose Budget Tracker β real-time WHO budget depletion in activity modal
- Compound Risk Panel β weather-amplified risk with per-factor multipliers
- District Heatmap β 22-district SVG map with realtime color coding
- Forecast vs Actual β MAE / RMSE / accuracy% comparison chart
- WHO Comparison β PM2.5 daily average vs WHO 5/15 Β΅g/mΒ³ guidelines
- Exposure Log Chart β 30-day Recharts bar chart with WHO reference line
- Safety Streak & Badges β 11 unlockable health achievement badges
- Conversational chat with streaming typewriter response
- Pinned / renamed conversations with full history
- Message regeneration, export (.txt / .md)
- Domain-aware (only answers air quality topics)
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENT LAYER β
β React 18 + TypeScript + Vite (port 5173) β
β Recharts Β· ReactMarkdown Β· react-router-dom Β· Tailwind CSS β
βββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββββββββ
β REST API (JWT Bearer)
βββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββββββββ
β BACKEND LAYER β
β ASP.NET Core 8.0 (port 7276) β
β Entity Framework Core Β· JWT Auth Β· APScheduler proxy β
β Controllers: Air Β· Dashboard Β· Activity Β· Anomaly β
β Admin Β· Notification Β· Assistant β
ββββββββββββ¬βββββββββββββββββββββββββββββ¬βββββββββββββββββββββββ
β HTTP β HTTP
ββββββββββββΌβββββββββββ ββββββββββββββΌβββββββββββββββββββββ
β AI SERVER β β EXTERNAL APIs β
β FastAPI Python β β Open-Meteo Weather API β
β (port 8000) β β OpenAQ Air Quality API β
β β β Telegram Bot API β
β Ensemble Model β βββββββββββββββββββββββββββββββββββ
β ββ Random Forest β
β ββ ARIMA (auto AIC) β βββββββββββββββββββββββββββββββββββ
β ββ XGBoost Lite β β DATABASE β
β β β PostgreSQL 16 (prod) β
β APScheduler 60min β β SQLite (dev/test) β
β Anomaly Detector β βββββββββββββββββββββββββββββββββββ
β Cache Manager β
β District Heatmap β
β 22 quαΊn/huyα»n β
βββββββββββββββββββββββ
Data Flow:
- APScheduler triggers
run_compute()every 60 minutes - Ensemble model builds 7-day forecast CSV + 30-day history CSV + current JSON
- Clients read from cache β zero per-request AI computation
- Anomaly detector runs in parallel, triggers alerts via .NET
/api/notification - District heatmap computed with parallel weather fetch per district
| Layer | Technology |
|---|---|
| Frontend | React 18, TypeScript, Vite, Recharts, ReactMarkdown |
| Backend | ASP.NET Core 8.0, C#, Entity Framework Core |
| AI Server | FastAPI, Python 3.11, scikit-learn, XGBoost, statsmodels |
| Database | PostgreSQL 16 (prod) / SQLite (dev) |
| Auth | JWT Bearer Token |
| Cache | CSV + JSON file cache (APScheduler 60-min cycle) |
| Notification | Telegram Bot API Β· SMTP Email |
| DevOps | Docker Compose Β· GitHub Actions CI/CD |
AirSafeNet/
β
βββ .github/
β βββ workflows/
β β βββ ci.yml # CI: lint + type-check + build all layers
β β βββ docker-publish.yml # CD: build & push Docker images on tag
β βββ ISSUE_TEMPLATE/
β β βββ bug_report.md
β β βββ feature_request.md
β βββ PULL_REQUEST_TEMPLATE.md
β βββ dependabot.yml # Auto dependency updates
β βββ release-drafter.yml # Auto-generate release notes
β
βββ assets/
β βββ images/ # Logo, banner
β βββ screenshots/ # UI screenshots
β βββ diagrams/ # Architecture, CI/CD diagrams
β
βββ docs/
β βββ wiki/ # Extended documentation
β
βββ scripts/
β βββ model_manifest.py # Generate model version manifest
β βββ drift_check.py # Check model drift vs new data
β
βββ src/
β β
β βββ airsafenet_ai/ # FastAPI Python AI Server
β β βββ app/
β β β βββ api.py # FastAPI routes
β β β βββ predict.py # Main model inference
β β β βββ ensemble_predict.py # Ensemble (RF + ARIMA + XGBoost)
β β β βββ cache_manager.py # 60-min cache pipeline
β β β βββ anomaly_detector.py # Spike detection + XAI
β β β βββ districts.py # 22-district heatmap
β β β βββ scheduler.py # APScheduler 60-min job
β β β βββ features.py # Feature engineering
β β β βββ data_loader.py # Open-Meteo + OpenAQ fetch
β β β βββ aqi.py # EPA AQI conversion
β β β βββ profiles.py # Risk profiles (Vietnamese)
β β β βββ config.py # LAT/LON/constants
β β βββ models/ # Trained model .pkl files
β β βββ data/ # Cache CSVs/JSONs
β β βββ notebooks/ # Google Colab training notebooks
β β βββ Dockerfile
β β βββ requirements.txt
β β
β βββ airsafenet_backend/ # ASP.NET Core 8.0 Web API
β β βββ airsafenet_backend/
β β β βββ Controllers/ # Air, Dashboard, Activity, Anomaly,
β β β β # Admin, Notification, Assistant
β β β βββ Data/ # AppDbContext, EF migrations
β β β βββ DTOs/ # Request/Response models
β β β βββ Models/ # EF entities
β β β βββ Services/ # AiCachedService, AirExplainService
β β β βββ Program.cs
β β βββ Dockerfile
β β βββ airsafenet_backend.sln
β β
β βββ airsafenet_frontend/ # React + TypeScript + Vite
β βββ src/
β β βββ pages/ # Dashboard, Activity, Heatmap, Impact,
β β β # Assistant, Preferences, Guide, Presentation
β β βββ components/
β β β βββ layout/ # AppShell, AppHeader, SidebarNav
β β β βββ dashboard/ # 30+ visualization components
β β β βββ common/ # SectionHeader, StatusChip, Toast
β β βββ api/ # http.ts, air.ts, dashboard.ts,
β β β # assistant.ts, preferences.ts
β β βββ types/ # TypeScript type definitions
β βββ Dockerfile
β βββ vite.config.ts
β
βββ .env.example # Environment variable template
βββ .gitignore
βββ docker-compose.yml # Full stack orchestration
βββ ARCHITECTURE.md
βββ BRANCHING.md
βββ CODE_OF_CONDUCT.md
βββ COMPETITION_SUBMISSION.md
βββ CONTRIBUTING.md
βββ DEMO_SCRIPT.md
βββ LICENSE
βββ MODEL_VERSIONING.md
βββ RELEASE_TEMPLATE.md
βββ SECURITY.md
βββ SUPPORT.md
βββ README.md
- Docker Desktop β₯ 24.0 & Docker Compose β₯ 2.0 (recommended)
- Or: Node.js β₯ 18, .NET SDK 8.0, Python 3.11, PostgreSQL 16
# 1. Clone repository
git clone https://github.com/NguyenTriBaoThang/AirSafeNet.git
cd AirSafeNet
# 2. Configure environment
cp .env.example .env
# Edit .env with your API keys (see Environment Variables section)
# 3. Start all services
docker compose up -d --build
# 4. Open browser
# Frontend: http://localhost:5173
# Backend: http://localhost:7276/swagger
# AI Server: http://localhost:8000/docsTo stop all services:
docker compose downβΆ 1. AI Server (FastAPI)
cd src/airsafenet_ai
python -m venv .venv
# Windows
.\.venv\Scripts\activate
# macOS/Linux
source .venv/bin/activate
pip install -r requirements.txt
# Optional: install Ensemble dependencies
pip install statsmodels xgboost
cp .env.example .env
uvicorn app.api:app --reload --host 0.0.0.0 --port 8000Place trained model at
src/airsafenet_ai/models/model.pklHealth check:
http://localhost:8000/health
βΆ 2. Backend (ASP.NET Core)
cd src/airsafenet_backend
dotnet restore
dotnet ef database update
dotnet runSwagger UI:
https://localhost:7276/swagger
βΆ 3. Frontend (React + Vite)
cd src/airsafenet_frontend
cp .env.example .env.local
npm install
npm run devWeb app:
http://localhost:5173
Copy .env.example β .env and fill in:
# ββ Database βββββββββββββββββββββββββββββββββββββ
POSTGRES_USER=airsafenet
POSTGRES_PASSWORD=your_strong_password
# ββ JWT Auth ββββββββββββββββββββββββββββββββββββββ
JWT_SECRET=your_min_32_char_secret_key
# ββ Admin βββββββββββββββββββββββββββββββββββββββββ
ADMIN_KEY=your_admin_key
# ββ External APIs βββββββββββββββββββββββββββββββββ
OPENAQ_API_KEY=your_openaq_api_key
# Open-Meteo: Free, no key needed
# ββ Notifications βββββββββββββββββββββββββββββββββ
TELEGRAM_BOT_TOKEN=your_telegram_bot_token
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_USER=your@gmail.com
SMTP_PASS=your_app_password # Gmail App Password
# ββ Frontend ββββββββββββββββββββββββββββββββββββββ
VITE_API_BASE_URL=http://localhost:7276| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Service health check |
GET |
/forecast/current |
Current PM2.5 + AQI (cached) |
GET |
/forecast/range?days=7 |
7-day hourly forecast |
GET |
/history?days=30 |
30-day historical data |
GET |
/districts/current |
22-district real-time AQI |
GET |
/anomaly/latest |
Latest anomaly detection |
GET |
/anomaly/history |
Anomaly history log |
POST |
/admin/compute |
Trigger cache recompute |
| Method | Endpoint | Auth | Description |
|---|---|---|---|
POST |
/api/auth/register |
β | Register account |
POST |
/api/auth/login |
β | Login β JWT token |
GET |
/api/air/current |
β | Current AQI + weather |
GET |
/api/air/forecast?days=7 |
β | Forecast (from cache) |
GET |
/api/air/history?days=30 |
β | History (from cache) |
GET |
/api/air/explain |
β | Weather + AI explanation |
GET/POST |
/api/activity |
β | Activity schedule CRUD |
GET |
/api/activity/forecast |
β | Risk score per activity |
GET |
/api/dashboard/summary |
β | Dashboard summary data |
GET |
/api/anomaly/latest |
β | Anomaly proxy |
POST |
/api/admin/compute |
β Admin | Trigger AI recompute |
Full API specification: see openapi.txt
- Login β Dashboard loads forecast, AQI summary, anomaly banner
- Switch forecast/history, 1/3/7 days
- Check WHO Comparison Chart and Forecast vs Actual
- Settings β set user group (e.g. Respiratory)
- Activity page β Add activity via modal (see Dose Budget update live)
- Smart Schedule Optimizer β enter activity β get top-3 time slots
- Golden Hour Picker β 24h AQI heatmap β select best hour β apply
- Heatmap page β see 22 quαΊn/huyα»n color-coded by AQI
- Click district β popup with PM2.5 and risk level
- Assistant page β ask "PM2.5 hΓ΄m nay nhΖ° thαΊΏ nΓ o?"
- Streaming typewriter response
- Pin, rename, export conversation
- Login as Admin β /admin
- Trigger compute β watch cache refresh
- Monitor scheduler status and file timestamps
- CI (every push/PR to
main): TypeScript check β ESLint β .NET build β Python lint β Docker build verification - CD (every semver tag
v*.*.*): Build multi-arch images β push to GitHub Container Registry β auto-generate release notes
# Create and push a release tag
git tag v1.0.0
git push origin v1.0.0
# β GitHub Actions builds and publishes Docker images automatically
# β GitHub Release created with changelog- Core AI forecast (Random Forest)
- Ensemble Model (ARIMA + XGBoost + dynamic weights)
- Real-time anomaly detection + XAI
- 22-district heatmap (HCMC)
- Activity scheduling + personalized risk scoring
- WHO Dose Budget Tracker
- Compound Risk Score (PM2.5 Γ Weather)
- Safety Streak & Badge gamification
- AQI Spike Interrupt Alert
- PM2.5 Educational Guide page
- Mobile App (React Native / PWA)
- Multi-city support (Hanoi, Da Nang)
- Long-term trend analytics (6 months / 1 year)
- Family Dashboard (multi-profile management)
- Official station data integration
- Cloud deployment (AWS/Azure)
Contributions are welcome! Please read CONTRIBUTING.md first.
# 1. Fork the repository
# 2. Create your feature branch
git checkout -b feature/your-feature-name
# 3. Commit with convention
git commit -m "feat(frontend): add compound risk panel"
# 4. Push and open Pull Request
git push origin feature/your-feature-name| Prefix | Purpose |
|---|---|
feat |
New feature |
fix |
Bug fix |
docs |
Documentation |
style |
CSS / formatting |
refactor |
Code refactor |
test |
Tests |
chore |
Build / config |
Please read SECURITY.md. Do not report security vulnerabilities publicly in issues β contact the maintainer directly.
| Document | Description |
|---|---|
| ARCHITECTURE.md | System architecture deep-dive |
| BRANCHING.md | Git branching strategy |
| COMPETITION_SUBMISSION.md | Competition guide |
| DEMO_SCRIPT.md | Step-by-step demo script |
| MODEL_VERSIONING.md | AI model versioning |
| CONTRIBUTING.md | Contribution guidelines |
| SECURITY.md | Security policy |
| SUPPORT.md | Support information |
| openapi.txt | Full API specification |
MIT License β see LICENSE for details.
| Team | KTT.HUTECH |
| Instructor | MSc. Nguyen Huy Cuong |
| Contributors | Nguyen Tri Bao Thang Β Β·Β Le Trung Kien Β Β·Β Do Chi Thanh Β Β·Β Vo Thanh Trung |
Built with β€οΈ for cleaner air and healthier lives in Ho Chi Minh City, Vietnam.









