version: '3.8'

services:
  # Kafka Infrastructure
  zookeeper:
    image: confluentinc/cp-zookeeper:7.4.0
    container_name: websearch-zookeeper
    environment:
      ZOOKEEPER_CLIENT_PORT: 2181
      ZOOKEEPER_TICK_TIME: 2000
    ports:
      - "2182:2181"
    networks:
      - websearch-network
    healthcheck:
      test: ["CMD", "nc", "-z", "localhost", "2181"]
      interval: 30s
      timeout: 10s
      retries: 3

  kafka:
    image: confluentinc/cp-kafka:7.4.0
    container_name: websearch-kafka
    depends_on:
      zookeeper:
        condition: service_healthy
    ports:
      - "9093:9092"
    environment:
      KAFKA_BROKER_ID: 1
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:29092,PLAINTEXT_HOST://localhost:9093
      KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT
      KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT
      KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1
      KAFKA_AUTO_CREATE_TOPICS_ENABLE: true
    networks:
      - websearch-network
    healthcheck:
      test: ["CMD", "kafka-broker-api-versions", "--bootstrap-server", "localhost:9093"]
      interval: 30s
      timeout: 10s
      retries: 3

  # Redis for caching and session management
  redis:
    image: redis:7-alpine
    container_name: websearch-redis
    ports:
      - "6378:6379"
    command: redis-server --appendonly yes
    volumes:
      - redis-data:/data
    networks:
      - websearch-network
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 30s
      timeout: 10s
      retries: 3

  # API Gateway Service
  api-gateway:
    build:
      context: .
      dockerfile: services/api-gateway/Dockerfile
    container_name: websearch-api-gateway
    ports:
      - "8010:8000"
    depends_on:
      kafka:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      - KAFKA_BOOTSTRAP_SERVERS=kafka:29092
      - REDIS_URL=redis://redis:6379
      - SERVICE_NAME=api-gateway
      - LOG_LEVEL=INFO
    volumes:
      - ./shared/results:/app/results
    networks:
      - websearch-network
    restart: unless-stopped

  # Google Search Service
  google-search-service:
    build:
      context: .
      dockerfile: services/google-search/Dockerfile
    container_name: websearch-google-search
    depends_on:
      kafka:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      - KAFKA_BOOTSTRAP_SERVERS=kafka:29092
      - SERVICE_NAME=google-search-service
      - SEARCH_ENGINE=google
      - REDIS_URL=redis://redis:6379
      - LOG_LEVEL=INFO
    volumes:
      - ./shared/results:/app/results
      - /dev/shm:/dev/shm
    networks:
      - websearch-network
    restart: unless-stopped

  # Bing Search Service
  # bing-search-service:
  #   build:
  #     context: .
  #     dockerfile: services/bing-search/Dockerfile
  #   container_name: websearch-bing-search
  #   depends_on:
  #     kafka:
  #       condition: service_healthy
  #     redis:
  #       condition: service_healthy
  #   environment:
  #     - KAFKA_BOOTSTRAP_SERVERS=kafka:29092
  #     - SERVICE_NAME=bing-search-service
  #     - SEARCH_ENGINE=bing
  #     - REDIS_URL=redis://redis:6379
  #     - LOG_LEVEL=INFO
  #   volumes:
  #     - ./shared/results:/app/results
  #     - /dev/shm:/dev/shm
  #   networks:
  #     - websearch-network
  #   restart: unless-stopped

  # # Yandex Search Service
  # yandex-search-service:
  #   build:
  #     context: .
  #     dockerfile: services/yandex-search/Dockerfile
  #   container_name: websearch-yandex-search
  #   depends_on:
  #     kafka:
  #       condition: service_healthy
  #     redis:
  #       condition: service_healthy
  #   environment:
  #     - KAFKA_BOOTSTRAP_SERVERS=kafka:29092
  #     - SERVICE_NAME=yandex-search-service
  #     - SEARCH_ENGINE=yandex
  #     - REDIS_URL=redis://redis:6379
  #     - LOG_LEVEL=INFO
  #   volumes:
  #     - ./shared/results:/app/results
  #     - /dev/shm:/dev/shm
  #   networks:
  #     - websearch-network
  #   restart: unless-stopped

  # # DuckDuckGo Search Service
  # duckduckgo-search-service:
  #   build:
  #     context: .
  #     dockerfile: services/duckduckgo-search/Dockerfile
  #   container_name: websearch-duckduckgo-search
  #   depends_on:
  #     kafka:
  #       condition: service_healthy
  #     redis:
  #       condition: service_healthy
  #   environment:
  #     - KAFKA_BOOTSTRAP_SERVERS=kafka:29092
  #     - SERVICE_NAME=duckduckgo-search-service
  #     - SEARCH_ENGINE=duckduckgo
  #     - REDIS_URL=redis://redis:6379
  #     - LOG_LEVEL=INFO
  #   volumes:
  #     - ./shared/results:/app/results
  #     - /dev/shm:/dev/shm
  #   networks:
  #     - websearch-network
  #   restart: unless-stopped

  # # Yahoo Search Service
  # yahoo-search-service:
  #   build:
  #     context: .
  #     dockerfile: services/yahoo-search/Dockerfile
  #   container_name: websearch-yahoo-search
  #   depends_on:
  #     kafka:
  #       condition: service_healthy
  #     redis:
  #       condition: service_healthy
  #   environment:
  #     - KAFKA_BOOTSTRAP_SERVERS=kafka:29092
  #     - SERVICE_NAME=yahoo-search-service
  #     - SEARCH_ENGINE=yahoo
  #     - REDIS_URL=redis://redis:6379
  #     - LOG_LEVEL=INFO
  #   volumes:
  #     - ./shared/results:/app/results
  #     - /dev/shm:/dev/shm
  #   networks:
  #     - websearch-network
  #   restart: unless-stopped

  # # Baidu Search Service
  # baidu-search-service:
  #   build:
  #     context: .
  #     dockerfile: services/baidu-search/Dockerfile
  #   container_name: websearch-baidu-search
  #   depends_on:
  #     kafka:
  #       condition: service_healthy
  #     redis:
  #       condition: service_healthy
  #   environment:
  #     - KAFKA_BOOTSTRAP_SERVERS=kafka:29092
  #     - SERVICE_NAME=baidu-search-service
  #     - SEARCH_ENGINE=baidu
  #     - REDIS_URL=redis://redis:6379
  #     - LOG_LEVEL=INFO
  #   volumes:
  #     - ./shared/results:/app/results
  #     - /dev/shm:/dev/shm
  #   networks:
  #     - websearch-network
  #   restart: unless-stopped

  # Metadata Extraction Service
  metadata-service:
    build:
      context: .
      dockerfile: services/metadata-extraction/Dockerfile
    container_name: websearch-metadata-service
    depends_on:
      kafka:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      - KAFKA_BOOTSTRAP_SERVERS=kafka:29092
      - SERVICE_NAME=metadata-service
      - REDIS_URL=redis://redis:6379
      - LOG_LEVEL=INFO
    volumes:
      - ./shared/results:/app/results
      - /dev/shm:/dev/shm
    networks:
      - websearch-network
    restart: unless-stopped

  # Data Processing Service
  data-processing-service:
    build:
      context: .
      dockerfile: services/data-processing/Dockerfile
    container_name: websearch-data-processing
    depends_on:
      kafka:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      - KAFKA_BOOTSTRAP_SERVERS=kafka:29092
      - REDIS_URL=redis://redis:6379
      - SERVICE_NAME=data-processing-service
      - LOG_LEVEL=INFO
    volumes:
      - ./shared/results:/app/results
    networks:
      - websearch-network
    restart: unless-stopped

  # File Export Service
  file-export-service:
    build:
      context: .
      dockerfile: services/file-export/Dockerfile
    container_name: websearch-file-export
    depends_on:
      kafka:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      - KAFKA_BOOTSTRAP_SERVERS=kafka:29092
      - SERVICE_NAME=file-export-service
      - REDIS_URL=redis://redis:6379
      - LOG_LEVEL=INFO
    volumes:
      - ./shared/results:/app/results
    networks:
      - websearch-network
    restart: unless-stopped

networks:
  websearch-network:
    driver: bridge

volumes:
  redis-data:
