Hackathon Solution: Good Health & Well-Being through AI-Driven Air Quality Intelligence
Urban residents in fast-developing Malaysian cities face growing health risks from worsening air quality and traffic congestion. Prolonged exposure to pollutants like PM2.5, NO₂, and CO contributes to respiratory illnesses, while congestion increases stress and accident risks. Despite available open datasets, city health planning often lacks real-time insights, leaving vulnerable communities exposed.
NafasLokal is an AI-driven solution that integrates air quality, traffic patterns, and health data to support better decision-making for healthier cities.
- Problem Statement
- Our Solution
- Key Features
- System Requirements
- Installation Guide
- Environment Configuration
- Running the Application
- Deployment Options
- Project Structure
- Tech Stack
- Data Integration
- API Documentation
- Troubleshooting
- Team
- License
- Air pollution health crisis: Malaysian cities experience hazardous air quality during haze season and peak traffic hours
- Lack of actionable insights: Raw pollution data exists but isn't translated into health-protective actions
- Vulnerable populations at risk: Children, elderly, asthma patients, and outdoor workers need timely, personalized alerts
- No incentive for behavior change: People lack motivation to choose healthier commute options
NafasLokal addresses these challenges through four integrated pillars:
- Live PM2.5, NO₂, CO, and O₃ data from DOE Malaysia, WAQI, and OpenAQ
- Location-based exposure scoring with health risk levels
- Interactive map with pollution heatmaps and station markers
- 24-hour pollutant forecasts using machine learning
- Personalized health scores based on exposure patterns
- Actionable recommendations (optimal exercise windows, route suggestions)
- Vulnerable group advisories with specific guidance
- Daily/weekly challenges encouraging healthier choices
- XP system, streaks, badges, and leaderboards
- Rewards for choosing public transit, avoiding peak pollution hours
- Community impact tracking
- Route recommendations based on real-time air quality
- Peak pollution hour alerts
- Transit vs. driving comparison for exposure levels
- Green corridor suggestions
| Feature | Description | Status |
|---|---|---|
| Live Dashboard | Real-time AQI with multi-source data fusion | ✅ Implemented |
| AI Health Score | Personalized health assessment based on exposure | ✅ Implemented |
| AI Chatbot | Conversational AI for health & air quality queries | ✅ Implemented |
| Pollutant Forecast | 24-hour predictions for PM2.5, NO₂, O₃, CO | ✅ Implemented |
| BreathQuest | Gamification with challenges, badges, leaderboard | ✅ Implemented |
| Interactive Map | Heatmap visualization with station markers | ✅ Implemented |
| Trend Analytics | 7-day/30-day historical analysis | ✅ Implemented |
| Health Alerts | Push notifications for high-risk periods | ✅ Implemented |
| Healthcare Finder | Nearby healthcare facilities locator | ✅ Implemented |
| Health Profile | Personalized health passport for recommendations | ✅ Implemented |
| User Authentication | Secure login and registration system | ✅ Implemented |
| Component | Requirement |
|---|---|
| Operating System | Windows 10/11, macOS 10.15+, or Linux (Ubuntu 20.04+) |
| Node.js | v20.0.0 or higher |
| npm | v10.0.0 or higher |
| RAM | 4GB minimum, 8GB recommended |
| Storage | 500MB for dependencies and build files |
| Browser | Chrome 90+, Firefox 90+, Safari 14+, Edge 90+ |
| Component | Requirement |
|---|---|
| Docker | v24.0.0 or higher |
| Docker Compose | v2.20.0 or higher |
# Clone the repository
git clone https://github.com/aimanzahar/air.git
# Navigate to project directory
cd air# Install Node.js dependencies
npm install
# Or using npm ci for exact versions (recommended for production)
npm ci# Copy the example environment file
# Windows (PowerShell):
Copy-Item .env.example .env.local
# Windows (Command Prompt):
copy .env.example .env.local
# Linux/macOS:
cp .env.example .env.localEdit .env.local with your configuration. See Environment Configuration for details.
# Login to Convex (first time only)
npx convex login
# Initialize Convex project (first time only)
npx convex init
# Deploy Convex functions
npx convex deployCreate a .env.local file in the root directory with the following variables:
| Variable | Description | How to Obtain |
|---|---|---|
NEXT_PUBLIC_CONVEX_URL |
Your Convex deployment URL | Sign up at convex.dev, create project, copy URL from dashboard |
CONVEX_DEPLOY_KEY |
Convex deployment API key | Convex Dashboard → Settings → API Keys → Create "Deployment" key |
OPENAI_API_KEY |
OpenAI API key for AI features | Sign up at platform.openai.com |
OPENAI_BASE_URL |
OpenAI API endpoint | https://api.openai.com/v1 (default) |
OPENAI_MODEL |
AI model to use | gpt-4 or gpt-3.5-turbo |
| Variable | Description | Default |
|---|---|---|
PORT |
Application port | 3000 |
NODE_ENV |
Environment mode | development |
NEXT_TELEMETRY_DISABLED |
Disable Next.js telemetry | 1 |
WAQI_API_TOKEN |
WAQI API token (enhanced data) | Uses public API |
OPENAQ_API_KEY |
OpenAQ API key (enhanced data) | Uses public API |
# Convex Database
NEXT_PUBLIC_CONVEX_URL=https://your-project.convex.cloud
CONVEX_DEPLOY_KEY=convex_1a2b3c4d5e...
# AI Configuration
OPENAI_API_KEY=sk-your-openai-key-here
OPENAI_BASE_URL=https://api.openai.com/v1
OPENAI_MODEL=gpt-4
# Application
NODE_ENV=development
PORT=3000# Start development server with hot reload
npm run devThe application will be available at http://localhost:3000
# Build the application
npm run build
# Start production server
npm start# Build and start with Docker Compose
docker-compose up --build
# Or run in detached mode
docker-compose up -d --build- Push code to GitHub
- Visit vercel.com and import your repository
- Add environment variables in Vercel dashboard
- Deploy automatically
See DEPLOYMENT.md for detailed Docker and Portainer deployment instructions.
# Quick Docker deployment
docker build -t nafaslokal .
docker run -p 3000:3000 --env-file .env.local nafaslokal# On your server
git clone https://github.com/aimanzahar/air.git
cd air
npm ci
cp .env.example .env.local
# Edit .env.local with your values
npm run build
npm startair/
├── convex/ # Convex backend (real-time database)
│ ├── air/ # Air quality module
│ │ ├── schema.ts # Database schema definitions
│ │ ├── auth.ts # Authentication functions
│ │ ├── passport.ts # User profile functions
│ │ ├── healthProfile.ts # Health profile functions
│ │ └── airQualityHistory.ts # Air quality data functions
│ └── _generated/ # Auto-generated Convex files
│
├── src/
│ ├── app/ # Next.js App Router pages
│ │ ├── page.tsx # Landing page
│ │ ├── dashboard/ # Main dashboard with air quality map
│ │ ├── ai-health/ # AI health predictions page
│ │ ├── gamification/ # BreathQuest gamification page
│ │ ├── register/ # User registration page
│ │ └── api/ # API routes
│ │ ├── ai-health/ # AI health endpoint
│ │ ├── air-quality/ # Air quality data endpoint
│ │ ├── chat/ # AI chatbot endpoint
│ │ ├── healthcare/ # Healthcare facilities endpoint
│ │ ├── waqi/ # WAQI API integration
│ │ ├── openaq/ # OpenAQ API integration
│ │ └── doe/ # DOE Malaysia API integration
│ │
│ ├── components/ # React components
│ │ ├── map/ # Map components (AirQualityMap, Heatmap)
│ │ ├── chat/ # Chat widget components
│ │ ├── health/ # Health profile components
│ │ ├── healthcare/ # Healthcare finder components
│ │ ├── analytics/ # Analytics & comparison charts
│ │ └── navigation/ # Navigation components
│ │
│ ├── contexts/ # React context providers
│ │ ├── AuthContext.tsx # Authentication state
│ │ └── ChatContext.tsx # Chat state management
│ │
│ ├── lib/ # Utility libraries
│ │ ├── airQualityService.ts # Air quality data fetching
│ │ ├── chatService.ts # Chat API service
│ │ ├── healthcareService.ts # Healthcare API service
│ │ └── locationService.ts # Geolocation utilities
│ │
│ └── types/ # TypeScript type definitions
│ ├── airQuality.ts # Air quality types
│ └── chat.ts # Chat types
│
├── docs/ # Documentation
│ └── chatbot-architecture.md
│
├── scripts/ # Deployment scripts
│ ├── start.sh # Production start script
│ └── verify-convex.sh # Convex verification
│
├── public/ # Static assets
├── docker-compose.yml # Docker Compose configuration
├── Dockerfile # Docker build configuration
├── DEPLOYMENT.md # Deployment guide
└── package.json # Project dependencies
| Layer | Technology | Purpose |
|---|---|---|
| Frontend | Next.js 16 (App Router) | React framework with SSR/SSG |
| UI Framework | React 19 | Component-based UI |
| Styling | Tailwind CSS 4 | Utility-first CSS framework |
| Backend | Convex | Real-time serverless database |
| AI/ML | OpenAI API | Health predictions & chatbot |
| Maps | Leaflet + React-Leaflet | Interactive map visualization |
| Charts | Recharts | Data visualization |
| Language | TypeScript 5 | Type-safe JavaScript |
| Icons | Heroicons | UI icons |
{
"next": "16.0.5",
"react": "19.2.0",
"convex": "^1.29.3",
"openai": "^6.9.1",
"leaflet": "^1.9.4",
"recharts": "^3.5.1",
"tailwindcss": "^4"
}NafasLokal aggregates data from multiple authoritative sources:
| Source | Description | Data Provided |
|---|---|---|
| DOE Malaysia | Official Department of Environment Malaysia | AQI, PM2.5, PM10, CO, NO₂, O₃, SO₂ |
| WAQI | World Air Quality Index | Global real-time AQI data |
| OpenAQ | Open-source environmental platform | Historical and real-time readings |
| Endpoint | Method | Description |
|---|---|---|
/api/air-quality |
GET | Fetch air quality data by location |
/api/ai-health |
POST | Get AI health predictions |
/api/chat |
POST | AI chatbot interaction |
/api/healthcare |
GET | Find nearby healthcare facilities |
/api/waqi |
GET | WAQI API proxy |
/api/openaq |
GET | OpenAQ API proxy |
/api/doe |
GET | DOE Malaysia API proxy |
/api/health |
GET | Health check endpoint |
The application uses Convex for real-time data:
| Function | Description |
|---|---|
passport:ensureProfile |
Create/get user profile |
passport:logExposure |
Log air quality exposure |
passport:getExposureHistory |
Fetch exposure history |
healthProfile:saveHealthProfile |
Save health profile |
healthProfile:getHealthProfile |
Get health profile |
airQualityHistory:saveReading |
Save AQ reading |
airQualityHistory:getHistory |
Get AQ history |
Cause: Convex functions not deployed
Solution:
npx convex deployCause: Missing environment variables
Solution: Ensure .env.local exists with proper values
Cause: Browser location permission denied
Solution: Allow location access or the map will use Kuala Lumpur as default
Cause: OpenAI API key not configured
Solution: Add valid OPENAI_API_KEY to .env.local
Cause: Insufficient memory for Next.js build
Solution:
# Increase Node.js memory limit
$env:NODE_OPTIONS="--max-old-space-size=4096"
npm run build- Check the Convex Documentation
- Review Next.js Documentation
- Open an issue on GitHub
- Daily: Morning air checks, avoiding peak pollution
- Weekly: Clean route choices, public transit usage
- Achievements: Long-term health milestones
- XP points for healthy actions
- Streak bonuses for consistency
- Badges for achievements
- Leaderboard rankings
- Daily Commuters - Route optimization for lower exposure
- Parents - Protect children during outdoor activities
- Elderly - Health alerts for sensitive individuals
- Outdoor Workers - Mask and schedule recommendations
- Health-Conscious Citizens - Track and improve air exposure
- Health Protection: Reduces respiratory illness risk through actionable alerts
- Behavior Change: Gamification drives adoption of healthier commute choices
- Community Data: Crowdsourced readings improve pollution mapping
- Vulnerable Support: Targeted advisories for at-risk populations
- Urban Planning: Data insights for city health policy decisions
Malaysia-first air wellness platform with clean, modern design
Real-time AQI dashboard with interactive map, exposure tracking, and AI chat
Personalized health scores with 24-hour pollutant forecasts
Gamified challenges with XP system, badges, and leaderboards
- Mobile app (React Native)
- Integration with wearables for personal exposure tracking
- Clinic proximity analysis for underserved areas
- Traffic density API integration
- Multi-city expansion (Penang, JB)
Built for Malaysia's urban health future.
MIT License
- DOE Malaysia for air quality data
- WAQI for global air quality index
- OpenAQ for open environmental data
- Convex for real-time database infrastructure
- OpenAI for AI/ML capabilities