Skip to main content

๐Ÿ—๏ธ 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โ€‹

ServiceDepends OnUsed By
Digital TwinIoT Service, KafkaPrediction, Simulation, Dashboard
PredictionDigital Twin, Weather APIDashboard, Notification, Simulation
SimulationDigital Twin, Amazon NovaDashboard, Incident
NotificationPrediction, Incident, Digital TwinEnd Users, Admin Portal
DashboardDigital Twin, Simulation, PredictionWeb UI, Mobile UI
IoTSensors, External APIsDigital Twin
IncidentPrediction, NotificationDashboard, 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โ€‹


๐Ÿ†˜ 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โ€‹

  1. Service Communication: Use Kafka for async, HTTP/REST for sync
  2. Monitoring: Use Prometheus + Grafana to monitor performance
  3. Logging: Centralize logs with ELK Stack
  4. Scaling: If scaling is needed, add replicas via Docker Swarm or Kubernetes
  5. 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โ€‹