Skip to main content

๐Ÿ“ฆ CivicTwin AI Installation Guide

Detailed guide to install and run CivicTwin AI on your local machine or server


๐Ÿ”ง System Requirementsโ€‹

Basic Requirementsโ€‹

  • OS: Linux, macOS, Windows (WSL2)
  • RAM: Minimum 8GB (16GB recommended)
  • Disk: 20GB free (for data + AI models)
  • Internet: Stable connection
TechnologyVersionNotes
Docker20.10+Download Docker Desktop
Docker Compose2.0+Bundled with Docker Desktop
Git2.30+Download Git

Benefit: No need to install Node.js, PostgreSQL, Redis... Everything is in containers!

Without Dockerโ€‹

See BUILD_WITHOUT_DOCKER.md

TechnologyVersionPurpose
Node.js18.0+Backend API, Microservices
npm/yarn9.0+Package manager
PostgreSQL12.0+Main database
PostGIS3.0+Geospatial extension
Python3.9+AI prediction models
Redis6.0+Caching & sessions

๐Ÿš€ Quick Installation (5 minutes)โ€‹

Step 1: Clone Repositoryโ€‹

git clone https://github.com/asean-ai/civic-twin.git
cd civic-twin

Step 2: Create .env fileโ€‹

cp .env.example .env

Edit .env (especially these lines):

# Database
DATABASE_URL=postgresql://civic_user:civic_pass@postgres:5432/civic_twin
POSTGIS_ENABLED=true

# AWS (Bedrock) - For AI predictions
AWS_REGION=us-east-1
AWS_ACCESS_KEY_ID=your_aws_key
AWS_SECRET_ACCESS_KEY=your_aws_secret

# Application
NODE_ENV=development
PORT=3000

# Maps
MAPBOX_TOKEN=your_mapbox_token # Optional, get from https://mapbox.com

# Redis
REDIS_URL=redis://redis:6379

# Session
SESSION_SECRET=your_secret_key_here

Step 3: Run with Docker Composeโ€‹

# Build & run containers
docker-compose up -d

# Wait 1-2 minutes for all services to start
docker-compose ps

Step 4: Initialize Databaseโ€‹

# Run migrations
docker-compose exec api npm run migrate

# (Optional) Seed sample data
docker-compose exec api npm run seed

Step 5: Access the Applicationโ€‹


๐Ÿ“‹ Docker Servicesโ€‹

When running docker-compose up -d, the following services will start:

# View service list
docker-compose ps

# OUTPUT:
# NAME IMAGE STATUS
# api civic-twin-api:latest Up 2 minutes
# frontend civic-twin-frontend:latest Up 2 minutes
# postgres postgres:15 Up 2 minutes
# redis redis:7 Up 2 minutes
# adminer adminer:latest Up 2 minutes

Portsโ€‹

  • Frontend: 5173 (Vite dev server)
  • Backend API: 3000 (Express.js)
  • PostgreSQL: 5432 (internal, not exposed)
  • Redis: 6379 (internal)
  • Adminer: 8080 (Database admin tool)

๐Ÿงช Verify Installationโ€‹

1. Check API Healthโ€‹

curl http://localhost:3000/api/health

Expected result:

{
"status": "ok",
"timestamp": "2026-03-31T10:30:00Z",
"services": {
"database": "connected",
"redis": "connected",
"ai": "ready"
}
}

2. Check Frontendโ€‹

Open browser: http://localhost:5173

You will see:

  • ๐Ÿ“ Interactive city map
  • ๐ŸŽฎ "Create Scenario" button
  • ๐Ÿ“Š Dashboard (if logged in)

3. Check Databaseโ€‹

Visit: http://localhost:8080

  • System: PostgreSQL
  • Server: postgres
  • Username: civic_user
  • Password: civic_pass
  • Database: civic_twin

๐Ÿ› ๏ธ Useful Commandsโ€‹

Developmentโ€‹

# Watch mode (auto reload)
docker-compose exec api npm run dev

# View logs
docker-compose logs -f api

# Bash shell into container
docker-compose exec api bash

Databaseโ€‹

# Connect to PostgreSQL
docker-compose exec postgres psql -U civic_user -d civic_twin

# Reset database (warning: deletes all data!)
docker-compose exec api npm run migrate:reset
docker-compose exec api npm run seed

Build & Deploymentโ€‹

# Build production images
docker-compose -f docker-compose.prod.yml build

# Push to registry (if available)
docker tag civic-twin-api:latest your-registry.com/civic-twin-api:latest
docker push your-registry.com/civic-twin-api:latest

๐Ÿšจ Troubleshootingโ€‹

Error: "Container exited with code 1"โ€‹

# View detailed logs
docker-compose logs api

# Check if .env is correct
cat .env | grep DATABASE_URL

# Try rebuilding
docker-compose down
docker-compose build --no-cache
docker-compose up -d

Error: "Port 5173 already in use"โ€‹

# Find process using the port
lsof -i :5173 # macOS/Linux
netstat -ano | findstr :5173 # Windows

# Or specify a different port
PORT=3001 FRONTEND_PORT=5174 docker-compose up -d

Error: "PostgreSQL connection refused"โ€‹

# Check if PostgreSQL container is running
docker-compose ps postgres

# Connect directly
docker-compose exec postgres psql -U civic_user -d civic_twin

# If still failing, reset database
docker-compose down -v # -v: delete volumes
docker-compose up -d
docker-compose exec api npm run migrate

Error: "AWS credentials not found"โ€‹

# Check .env
grep AWS_ .env

# Or configure AWS CLI
aws configure

๐Ÿ“š Advanced Setupโ€‹

Using Custom Domainโ€‹

Add to /etc/hosts (macOS/Linux):

127.0.0.1 civic.local

Windows (C:\Windows\System32\drivers\etc\hosts):

127.0.0.1 civic.local

Then update .env:

FRONTEND_URL=http://civic.local:5173
API_URL=http://civic.local:3000

Enable HTTPS (Local)โ€‹

# Create self-signed certificate
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365

# Update docker-compose.yml
# ... (see nginx.conf template)

Scaling (Multiple Workers)โ€‹

In docker-compose.yml:

api:
deploy:
replicas: 3 # Run 3 API instances

โœ… Installation Complete Checklistโ€‹

Check for these signs:


๐Ÿ“– Next Stepsโ€‹

  1. Getting Started โ€“ Familiarize with the interface
  2. Architecture โ€“ Understand the system in detail
  3. Services โ€“ Learn about each module
  4. Development โ€“ Setup for development

๐Ÿ’ฌ Need Help?โ€‹