services:
  # ── Infrastructure ────────────────────────────────────────────────

  postgres:
    image: postgres:18-alpine
    environment:
      POSTGRES_DB: diraigent
      POSTGRES_USER: diraigent
      POSTGRES_PASSWORD: diraigent
    ports:
      - "5433:5432"
    volumes:
      - pgdata:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U diraigent"]
      interval: 5s
      timeout: 5s
      retries: 5

  nats:
    image: nats:latest
    command: ["-js", "-sd", "/data"]
    ports:
      - "4222:4222"
      - "8222:8222"
    volumes:
      - nats-data:/data

  # ── Diraigent ─────────────────────────────────────────────────────

  api:
    image: diraigent/api:latest
    ports:
      - "8082:8082"
    environment:
      HOST: 0.0.0.0
      PORT: 8082
      DATABASE_URL: postgres://diraigent:diraigent@postgres:5432/diraigent
      DEV_USER_ID: ${DEV_USER_ID:-}
      AUTH_ISSUER: ${AUTH_ISSUER:-}
      AUTH_JWKS_URL: ${AUTH_JWKS_URL:-}
      SERVICE_NAME: diraigent-api
      LOKI_URL: ${LOKI_URL:-}
      LOKI_ENV: ${LOKI_ENV:-dev}
      NATS_URL: nats://nats:4222
      CORS_ORIGINS: ${CORS_ORIGINS:-http://localhost:8080}
    depends_on:
      postgres:
        condition: service_healthy
      nats:
        condition: service_started
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://localhost:8082/health/live"]
      interval: 10s
      timeout: 5s
      retries: 3

  web:
    image: diraigent/web:latest
    ports:
      - "8080:80"
    depends_on:
      api:
        condition: service_healthy

  orchestra:
    image: diraigent/orchestra:latest
    environment:
      AGENT_ID: ${AGENT_ID}
      NATS_URL: nats://nats:4222
      DIRAIGENT_API: http://api:8082/api/v1/diraigent
      MAX_WORKERS: ${MAX_WORKERS:-3}
      GIT_REPO_URL: ${GIT_REPO_URL:-}
      ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-}
    volumes:
      - ./repo:/repo
    depends_on:
      nats:
        condition: service_started
      api:
        condition: service_healthy
    profiles:
      - agent

volumes:
  pgdata:
  nats-data:
