
services:
  # Unified Frontend and Nginx Gateway
  ai-frontend:
    build: ./frontend
    container_name: ai_unified_frontend
    restart: always
    ports:
      - "8002:80"
    volumes:
      - ./nginx.conf:/etc/nginx/nginx.conf:ro
    deploy:
      resources:
        limits:
          cpus: '0.50'
          memory: 512M
    depends_on:
      - ai-hub

  # AI Hub Backend Service
  ai-hub:
    build: ./ai-hub
    container_name: ai_hub_service
    restart: always
    ports:
      - "50051:50051"
    environment:
      - PATH_PREFIX=/api/v1
      - HUB_API_URL=http://localhost:8000
      - HUB_PUBLIC_URL=http://localhost:8002
      - HUB_GRPC_ENDPOINT=localhost:50051
      - SUPER_ADMINS=${SUPER_ADMINS:-admin@example.com}
      - CORTEX_ADMIN_PASSWORD=${CORTEX_ADMIN_PASSWORD}
      - SECRET_KEY=${SECRET_KEY:-default-insecure-key}
      - DEBUG_GRPC=true
    volumes:
      - ai_hub_data:/app/data:rw
      - ./config.yaml:/app/config.yaml:rw
      - ./ai-hub/app:/app/app:rw
      - ./agent-node:/app/agent-node-source:ro
      - ./skills:/app/skills:ro
      - ./docs:/app/docs:ro
      - ./blueprints:/app/blueprints:ro
      - browser_shm:/dev/shm:rw
    deploy:
      resources:
        limits:
          cpus: '1.0'
          memory: 1G


  # Dedicated Browser Service (M6 Refactor)
  browser-service:
    build: ./browser-service
    container_name: cortex_browser_service
    restart: always
    ports:
      - "50053:50052"
    environment:
      - SHM_PATH=/dev/shm/cortex_browser
    volumes:
      - ./browser-service:/app
      - browser_shm:/dev/shm:rw
    working_dir: /app
    command: python3 main.py
    deploy:
      resources:
        limits:
          cpus: '2.0'
          memory: 2G

# Generic named volume using local driver
volumes:
  ai_hub_data:
    driver: local

  browser_shm:
    driver: local
    driver_opts:
      type: tmpfs
      device: tmpfs
      o: "size=1g,uid=1000"
