Skip to content

xtymac/eventflow

Repository files navigation

Nagoya Construction Lifecycle

A GIS + workflow prototype for road construction lifecycle management, targeting local government road management staff in Nagoya.

Tech Stack

  • Frontend: React + TypeScript + Vite, Mantine UI, Zustand, React Query, MapLibre GL JS
  • Backend: Node.js + TypeScript + Fastify, Drizzle ORM
  • Database: PostgreSQL + PostGIS
  • NGSI-LD: FIWARE Orion-LD context broker
  • DevOps: Docker Compose

Quick Start

Prerequisites

  • Node.js 20+
  • Docker & Docker Compose
  • npm or pnpm

Development Setup

  1. Start infrastructure services:

    docker compose up -d db mongo orion-ld
  2. Install dependencies:

    npm install
  3. Generate database migrations:

    cd backend
    npm run db:generate
    npm run db:migrate
    npm run db:seed
    cd ..
  4. Start development servers:

    npm run dev

    This starts:

Full Docker Setup

Run everything in containers:

docker compose up -d

Project Structure

nagoya-construction-lifecycle/
├── backend/                 # Fastify API server
│   ├── src/
│   │   ├── db/             # Database schema & migrations
│   │   ├── routes/         # API endpoints
│   │   ├── services/       # Business logic
│   │   └── ngsi/           # NGSI-LD context files
│   └── drizzle/            # Migration files
├── frontend/               # React application
│   └── src/
│       ├── components/     # UI components
│       ├── features/       # Feature modules
│       ├── hooks/          # Custom hooks
│       └── stores/         # Zustand state
├── shared/                 # Shared TypeScript types
└── sample-data/            # Sample GeoJSON data

API Endpoints

Endpoint Method Description
/events GET, POST List/Create events
/events/:id GET, PUT Get/Update event
/events/:id/status PATCH Change status
/events/:id/decision PATCH Set post-end decision
/assets GET, POST List/Create assets
/assets/:id GET, PUT Get/Update asset
/assets/:id/retire PATCH Retire asset
/inspections GET, POST List/Create inspections
/import/geojson POST Import GeoJSON
/export/geojson GET Export GeoJSON

Key Features

  • Construction Event Lifecycle: Planned → Active → Ended
  • Map Visualization: Events and road assets displayed on MapLibre GL JS
  • Post-End Decision: Permanent change or archive after event ends
  • Road Asset Traceability: All changes linked to source events
  • NGSI-LD Sync: Real-time sync to Orion-LD context broker

Environment Variables

Backend

  • DATABASE_URL: PostgreSQL connection string
  • ORION_LD_URL: Orion-LD endpoint
  • PORT: Server port (default: 3000)
  • TZ: Timezone (default: Asia/Tokyo)

Frontend

  • VITE_API_URL: Backend API URL

EC2 Production Deployment

Server Details

Deployment Commands

# Sync code to EC2
rsync -avz --exclude 'node_modules' --exclude '.git' \
  -e "ssh -i ~/.ssh/eventflow-prod-key.pem" \
  ./ ubuntu@18.177.72.233:/home/ubuntu/nagoya-construction-lifecycle/

# Rebuild and restart
ssh -i ~/.ssh/eventflow-prod-key.pem ubuntu@18.177.72.233 \
  "cd /home/ubuntu/nagoya-construction-lifecycle && docker compose up -d --build"

Important Configuration Notes

  1. PostgreSQL Password Fix: The database volume may have a different password than docker-compose.yml. A docker-compose.override.yml is configured to automatically reset the password via healthcheck:

    services:
      db:
        healthcheck:
          test: ["CMD-SHELL", "pg_isready -U postgres && psql -U postgres -c \"ALTER USER postgres WITH PASSWORD 'postgres'\" > /dev/null 2>&1 || true"]
  2. Uploads Volume Mount: The API container requires access to the uploads directory for import diffs and snapshots:

    volumes:
      - ./backend/uploads:/app/uploads
  3. Services:

    • nagoya-api: Backend API (port 3000)
    • nagoya-web: Frontend (port 5173)
    • nagoya-db: PostgreSQL + PostGIS
    • nagoya-martin: MVT tile server
    • nagoya-caddy: Reverse proxy with HTTPS

Troubleshooting

# Check API logs
docker logs nagoya-api --tail 50

# Reset DB password manually if needed
docker exec nagoya-db psql -U postgres -c "ALTER USER postgres WITH PASSWORD 'postgres';"
docker restart nagoya-api nagoya-martin

License

Private - Eukarya Inc.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages