services:
  conductor-backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    container_name: conductor-backend
    restart: unless-stopped
    env_file: .env
    volumes:
      # Session JSONL files (read-only)
      - /var/lib/docker/volumes/openclaw_config/_data/agents/main/sessions:/data/sessions:ro
      # Conductor workspace (HEARTBEAT.md, git log, memory files)
      - /var/lib/docker/volumes/openclaw_workspace/_data:/data/workspace:rw
      # OpenClaw config (openclaw.json)
      - /var/lib/docker/volumes/openclaw_config/_data:/data/openclaw:ro
      # Upload storage for DocuDigest
      - conductor_uploads:/tmp/uploads
    networks:
      - conductor_internal # reachable by frontend
      - n8n_n8n_net        # reach postgres
      - openclaw_default   # reach gateway
    healthcheck:
      test: ["CMD", "python3", "-c", "import urllib.request; urllib.request.urlopen('http://localhost:8000/api/health')"]
      interval: 30s
      timeout: 5s
      retries: 3

  conductor-frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
      args:
        - NEXT_PUBLIC_DASHBOARD_TOKEN=${DASHBOARD_TOKEN}
        - NEXT_PUBLIC_GOOGLE_AUTH_ENABLED=${NEXT_PUBLIC_GOOGLE_AUTH_ENABLED:-false}
    container_name: conductor-frontend
    restart: unless-stopped
    environment:
      - BACKEND_URL=http://conductor-backend:8000
      - NEXTAUTH_URL=${NEXTAUTH_URL}
      - NEXTAUTH_URL_INTERNAL=http://conductor-frontend:3000
      - NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
      - DASHBOARD_USER=${DASHBOARD_USER}
      - DASHBOARD_PASSWORD=${DASHBOARD_PASSWORD}
      - GOOGLE_CLIENT_ID=${GOOGLE_CLIENT_ID:-}
      - GOOGLE_CLIENT_SECRET=${GOOGLE_CLIENT_SECRET:-}
    networks:
      - conductor_internal
    depends_on:
      - conductor-backend

  conductor-nginx:
    image: nginx:alpine
    container_name: conductor-nginx
    restart: unless-stopped
    ports:
      - "3456:80"
    volumes:
      - ./nginx.conf:/etc/nginx/conf.d/default.conf:ro
    networks:
      - conductor_internal
    depends_on:
      - conductor-frontend

networks:
  conductor_internal:
    driver: bridge
  n8n_n8n_net:
    external: true
  openclaw_default:
    external: true

volumes:
  conductor_uploads:
