๐๏ธ CivicTwin AI Microservices
All modular services that make up the CivicTwin AI platform
๐ Overall Architectureโ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Frontend Layer โ
โ (React/Vite, Leaflet, Interactive Map) โ
โโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโ
โ โ โ
โผ โผ โผ
โโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
โDigital โ โPredictionโ โSimulationโ
โ Twin โ โ & Alert โ โ What-If โ
โโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
โ โ โ
โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโ
โ
โโโโโโโโโโโโโโโผโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโ
โ โ โ โ
โผ โผ โผ โผ
โโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
โ IoT โ โEmergency โ โ Dashboardโ โIncident &โ
โ Sensors โ โResponse โ โ Service โ โAnalytics โ
โโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ โโโโโโโโโโโโ
๐ Core Servicesโ
1. Digital Twin Service โญโ
Purpose: Real-time city modeling
- ๐ Build a city network graph
- ๐ Integrate geospatial data (PostGIS) for roads, intersections, and infrastructure
- โฑ๏ธ Continuous updates from sensors, cameras, IoT
- ๐พ Store state + history
Technologies: Node.js, PostgreSQL + PostGIS, Redis, Kafka
API Port: 3001
Documentation: DigitalTwinService/Readme.md
# Health check
curl http://localhost:3001/api/digital-twin/health
# Get zones
curl http://localhost:3001/api/digital-twin/zones
2. AI Prediction Service ๐คโ
Purpose: Forecast & alert on incidents
- ๐ Traffic Prediction: Traffic flow forecasting (15โ60 minutes ahead)
- ๐ง Flooding Alert: Flood warnings based on weather + sensors
- ๐ Cascade Effects: Simulate cascade impacts
- ๐ฐ Socioeconomic Impact: Predict economic-social impacts (with Amazon Nova)
Models: LSTM, Transformer, Agent-Based, LLM
AI Framework: Amazon Bedrock + Nova
Technologies: Python, FastAPI, TensorFlow/PyTorch
API Port: 8002
Documentation: AIMLService/Readme.md
# Get traffic prediction
curl http://localhost:8002/api/predictions/traffic/road_123?horizonMinutes=60
# Get flooding alert
curl http://localhost:8002/api/predictions/flooding/city
3. Simulation & What-If Service ๐ฎโ
Purpose: Test scenarios before real-world deployment
- ๐๏ธ Drag-and-drop infrastructure (roads, hospitals, schools, etc.)
- ๐ Run agent-based simulation (5โ10 years)
- ๐ Predict impacts: economic, environmental, social, traffic
- ๐ A/B testing scenario comparison
- ๐ Generate detailed reports with Impact Score & Radar Chart
Technologies: Python, Mesa (ABM), FastAPI, Ray
API Port: 8003
Documentation: AnalyticsService/Readme.md
# Create scenario
curl -X POST http://localhost:8003/api/scenarios \
-H "Content-Type: application/json" \
-d '{"name": "New Hospital in District 4"}'
# Run simulation
curl -X POST http://localhost:8003/api/scenarios/scenario_123/simulate
4. Emergency Response & Notification Service ๐จโ
Purpose: Emergency alerts & evacuation guidance
- ๐ Fastest Route For Emergency: Coordinate routes for ambulances
- ๐บ๏ธ Evacuation Guidance: Recommend safe evacuation routes
- ๐ฑ Multi-channel Alerts: Push, SMS, Email, Web
- ๐ Cascade Broadcasting: City-wide alert broadcasting
- ๐ Geolocation-based: Only alert citizens in affected zones
Technologies: Node.js, Express, MongoDB, Firebase FCM, Kafka
API Port: 3005
Documentation: NotificationService/Readme.md
# Broadcast flooding alert
curl -X POST http://localhost:3005/api/emergency/broadcast-alert \
-H "Content-Type: application/json" \
-d '{
"type": "flooding",
"severity": "critical",
"affectedZones": ["zone_1", "zone_2"],
"message": "Flood Warning"
}'
# Find emergency route
curl -X POST http://localhost:3005/api/emergency/fastest-route \
-H "Content-Type: application/json" \
-d '{
"vehicleType": "ambulance",
"fromLocation": {"lat": 16.04, "lon": 108.21},
"toLocation": {"lat": 16.08, "lon": 108.20}
}'
5. IoT Service ๐กโ
Purpose: Receive data from sensors, cameras, and weather APIs
- ๐ท Traffic cameras (RTMP stream)
- ๐ก๏ธ IoT sensors (water level, temperature, pollution)
- ๐ค๏ธ Weather data (OpenWeatherMap, NOAA API)
- ๐ Traffic flow (Grab, HERE Maps, etc.)
- ๐ฑ Reports from app (citizen reports)
Technologies: Node.js, MQTT Broker, Kafka Producer
Documentation: IoTService/Readme.md
6. Dashboard Service ๐โ
Purpose: Data visualization & decision support
- ๐บ๏ธ Interactive Map: Real-time city state display
- ๐ Impact Score (0โ100): Composite impact score of scenarios
- ๐ Radar Chart: 5 indicators (Economic, Environmental, Accessibility, Equity, Safety)
- ๐ฏ Comparison View: Compare multiple scenarios
- ๐ก AI Explanation: "Why is this project good/bad?" (Natural language)
Technologies: React/Vue, D3.js, Chart.js, Leaflet
Documentation: AnalyticsService/Readme.md
7. Incident Service ๐จโ
Purpose: Incident lifecycle management
- ๐ Record incidents (accidents, flooding, fires)
- ๐ท๏ธ Classification & Prioritization (automatically via AI)
- ๐ Track resolution progress
- ๐ Statistics & Reporting
Documentation: IncidentService/Readme.md
8. Search Service ๐โ
Purpose: Fast data search & query
- ๐ Full-text search (hospitals, schools, etc.)
- ๐ Spatial search (radius-based)
- ๐ Real-time indexing (OpenSearch/Elasticsearch)
Documentation: SearchService/Readme.md
๐ Data Flowsโ
Real-time Event Flowโ
Sensors/IoT
โ
MQTT Broker
โ
IoT Service (Adapter)
โ
Kafka Topic
โโโ Digital Twin Service (Update state)
โโโ Prediction Service (Analyze)
โโโ Analytics Service (Store metrics)
โ
Predictions Generated
โโโ Dashboard (Display)
โโโ Notification Service (Alert if needed)
โโโ Incident Service (Track)
Scenario Simulation Flowโ
User Creates Scenario (Frontend)
โ
Simulation Service
โโ Clone current state (from Digital Twin)
โโ Apply changes
โโ Run ABM (Agent-Based Model)
โโ Call Amazon Nova for impact prediction
โโ Generate Impact Score & Radar Chart
โโ Save results
โ
Dashboard displays results
โโ Impact Score
โโ Radar Chart
โโ Timeline of effects
โโ AI explanation
๐ Service Dependenciesโ
| Service | Depends On | Used By |
|---|---|---|
| Digital Twin | IoT Service, Kafka | Prediction, Simulation, Dashboard |
| Prediction | Digital Twin, Weather API | Dashboard, Notification, Simulation |
| Simulation | Digital Twin, Amazon Nova | Dashboard, Incident |
| Notification | Prediction, Incident, Digital Twin | End Users, Admin Portal |
| Dashboard | Digital Twin, Simulation, Prediction | Web UI, Mobile UI |
| IoT | Sensors, External APIs | Digital Twin |
| Incident | Prediction, Notification | Dashboard, Analytics |
๐ Deploymentโ
Docker Composeโ
# Start all services
docker-compose up -d
# View logs
docker-compose logs -f
# Stop all
docker-compose down
Individual Service Startupโ
# Digital Twin
docker-compose up -d digital-twin
# Prediction Service
docker-compose up -d prediction
# Simulation Service
docker-compose up -d simulation
# Emergency Response
docker-compose up -d emergency
# Dashboard
docker-compose up -d dashboard
# IoT
docker-compose up -d iot
๐ API Gatewayโ
All services are exposed through a unified API Gateway at http://localhost:3000:
GET /api/digital-twin/*
GET /api/predictions/*
POST /api/scenarios/*
POST /api/emergency/*
GET /api/dashboard/*
GET /api/incidents/*
GET /api/search/*
๐ Detailed Documentationโ
- Digital Twin Service
- AI Prediction Service
- Simulation Service
- Emergency Response & Notification
- IoT Service
- Incident Service
- Search Service
๐ Troubleshootingโ
Service won't startโ
# Check logs
docker-compose logs <service_name>
# Rebuild service
docker-compose build --no-cache <service_name>
# Restart
docker-compose restart <service_name>
API not respondingโ
# Test connection
curl http://localhost:<PORT>/health
# Check if service is running
docker-compose ps
Database connection errorsโ
# Connect to database
docker-compose exec postgres psql -U civic_user -d civic_twin
# Check tables
\dt
๐ก Best Practicesโ
- Service Communication: Use Kafka for async, HTTP/REST for sync
- Monitoring: Use Prometheus + Grafana to monitor performance
- Logging: Centralize logs with ELK Stack
- Scaling: If scaling is needed, add replicas via Docker Swarm or Kubernetes
- Security: Use API Gateway, JWT tokens, RBAC
๐ Updates & Maintenanceโ
- Weekly: Monitor logs, check for errors
- Monthly: Update dependencies, security patches
- Quarterly: Performance optimization, new features
- As needed: Hotfixes for critical issues
๐ Contactโ
- ๐ง Development: [development@asean-ai.com]
- ๐ Bug Reports: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions