# StemeDB Docker Compose
#
# Runs the complete stack:
# 1. stemedb-api: Rust backend (port 18180)
# 2. seed: One-shot TypeScript script to populate claims
# 3. community: Next.js frontend (port 18187)
#
# Usage:
#   docker compose up        # Start all services
#   docker compose up -d     # Start in background
#   docker compose logs -f   # Follow logs
#   docker compose down -v   # Stop and remove volumes

services:
  # Rust API backend
  stemedb-api:
    build:
      context: .
      dockerfile: Dockerfile
    environment:
      - STEMEDB_WAL_DIR=/data/wal
      - STEMEDB_DB_DIR=/data/db
      - STEMEDB_BIND_ADDR=0.0.0.0:18180
      - STEMEDB_METER_ENABLED=false
      - RUST_LOG=stemedb_api=info
    ports:
      - "18180:18180"
    volumes:
      - stemedb-data:/data
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:18180/v1/health"]
      interval: 5s
      timeout: 3s
      retries: 10
      start_period: 30s

  # Seed script - runs once to populate demo data
  seed:
    build:
      context: ./community
      dockerfile: Dockerfile
    command: ["npx", "tsx", "scripts/seed-claims.ts"]
    environment:
      - STEMEDB_API_URL=http://stemedb-api:18180
    depends_on:
      stemedb-api:
        condition: service_healthy
    restart: "no"

  # Next.js frontend
  community:
    build:
      context: ./community
      dockerfile: Dockerfile
    environment:
      - STEMEDB_API_URL=http://stemedb-api:18180
      - NEXT_PUBLIC_STEMEDB_API_URL=http://localhost:18180
    ports:
      - "18187:18187"
    depends_on:
      seed:
        condition: service_completed_successfully

volumes:
  stemedb-data:
