# Project name used as prefix for containers, volumes, and networks
name: ras

# Docker registry mirror for China users (change to empty or "docker.io" if you have direct access)
x-registry-mirror: &registry-mirror docker.1ms.run

services:
  # MinIO (S3 compatible storage)
  minio:
    image: ${REGISTRY_MIRROR:-docker.1ms.run}/minio/minio
    ports:
      - "9000:9000"
      - "9001:9001"
    volumes:
      - minio_data:/data
    environment:
      MINIO_ROOT_USER: admin
      MINIO_ROOT_PASSWORD: password123
    command: server /data --console-address ":9001"
    healthcheck:
      test: ["CMD", "mc", "ready", "local"]
      interval: 5s
      timeout: 5s
      retries: 5

  # Backend API
  backend:
    build:
      context: ../api
      dockerfile: Dockerfile
      args:
        REGISTRY_MIRROR: ${REGISTRY_MIRROR:-docker.1ms.run}
    ports:
      - "8100:8100"
    environment:
      - DATABASE_URL=sqlite:///./data/app.db
      - MINIO_ENDPOINT=minio:9000
      - MINIO_ACCESS_KEY=admin
      - MINIO_SECRET_KEY=password123
      - MINIO_BUCKET=ai-audio
    volumes:
      - backend_data:/app/data
    depends_on:
      minio:
        condition: service_started
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8100/health"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 10s

  # Conversation Engine
  engine:
    build:
      context: ../engine
      dockerfile: Dockerfile
    ports:
      - "8001:8001"
    environment:
      - HOST=0.0.0.0
      - PORT=8001
      - BACKEND_MODE=http
      - BACKEND_URL=http://backend:8100
      - LOG_LEVEL=INFO
      - CORS_ORIGINS=["http://localhost:6000","http://localhost:3000"]
    volumes:
      - ../engine/config:/app/config:ro
      - ../engine/data:/app/data:ro
      - engine_logs:/app/logs
    depends_on:
      backend:
        condition: service_started
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8001/health"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 15s

  # Frontend (Vite + React) – production: built static files served on 6000
  frontend:
    build:
      context: ../web
      dockerfile: Dockerfile
      args:
        REGISTRY_MIRROR: ${REGISTRY_MIRROR:-docker.1ms.run}
        VITE_API_BASE_URL: ${VITE_API_BASE_URL:-http://localhost:8100/api}
        VITE_ENGINE_WS_URL: ${VITE_ENGINE_WS_URL:-ws://localhost:8001/ws}
    ports:
      - "6000:6000"
    depends_on:
      - backend
      - engine

  # Frontend dev – hot reload on port 3000 (run with: docker compose --profile dev up)
  frontend-dev:
    profiles:
      - dev
    build:
      context: ../web
      dockerfile: Dockerfile.dev
      args:
        REGISTRY_MIRROR: ${REGISTRY_MIRROR:-docker.1ms.run}
    ports:
      - "3000:3000"
    environment:
      - VITE_API_BASE_URL=${VITE_API_BASE_URL:-http://localhost:8100/api}
      - VITE_ENGINE_WS_URL=${VITE_ENGINE_WS_URL:-ws://localhost:8001/ws}
    volumes:
      - ../web:/app
      - frontend_dev_node_modules:/app/node_modules
    depends_on:
      - backend
      - engine

volumes:
  minio_data:
  backend_data:
  engine_logs:
  frontend_dev_node_modules:
