name: call-center-pg

x-app-env: &app_env
  CC_DATA_DIR: /app/.data_pg_parallel
  SCHEMA_MANAGEMENT_MODE: migrations
  AUTH_SERVICE_URL: http://auth-service:8000
  AUDIT_SERVICE_URL: http://audit-service:8000
  CUSTOMER_SERVICE_URL: http://customer-service:8000
  INTERACTION_SERVICE_URL: http://interaction-service:8000
  ROUTING_SERVICE_URL: http://routing-service:8000
  VOICE_ADAPTER_SERVICE_URL: http://voice-adapter-service:8000
  RECORDING_SERVICE_URL: http://recording-service:8000
  IVR_SERVICE_URL: http://ivr-service:8000
  EVENT_BUS_SERVICE_URL: http://event-bus-service:8000
  ASTERISK_BRIDGE_SERVICE_URL: http://asterisk-bridge-service:8000
  TELEGRAM_ADAPTER_SERVICE_URL: http://telegram-adapter-service:8000
  WHATSAPP_ADAPTER_SERVICE_URL: http://whatsapp-adapter-service:8000
  AI_ORCHESTRATOR_SERVICE_URL: http://ai-orchestrator-service:8000
  AI_VOICE_RUNTIME_SERVICE_URL: http://ai-voice-runtime-service:8000
  WEBCHAT_ADAPTER_SERVICE_URL: http://webchat-adapter-service:8000
  EMAIL_ADAPTER_SERVICE_URL: http://email-adapter-service:8000
  KB_SERVICE_URL: http://kb-service:8000
  REPORTING_SERVICE_URL: http://reporting-service:8000
  SUPERVISOR_SERVICE_URL: http://supervisor-service:8000
  SALES_SERVICE_URL: http://sales-service:8000
  AI_VOICE_ASR_PROVIDER: yandex
  AI_VOICE_TTS_PROVIDER: yandex
  AI_VOICE_V2_STREAMING_ASR_BACKEND: yandex_speechkit
  AI_VOICE_V2_STREAMING_ASR_BASE_URL: http://streaming-asr-sidecar:8021
  AI_VOICE_V2_STREAMING_ASR_TIMEOUT_SECONDS: "4"
  AI_VOICE_V2_STREAMING_ASR_PARTIAL_POLL_ENABLED: "1"

x-service-defaults: &service_defaults
  build:
    context: ..
  image: call-center-app:pg-parallel
  restart: unless-stopped
  env_file:
    - ../.env.production
    - ../.env.postgres.parallel.server
  environment:
    <<: *app_env
  volumes:
    - ../.data_pg_parallel:/app/.data_pg_parallel
  networks:
    - default
    - postgres
  extra_hosts:
    - host.docker.internal:host-gateway
  healthcheck:
    test:
      - CMD
      - python
      - -c
      - |
        from urllib.request import urlopen
        import sys
        sys.exit(0 if urlopen("http://127.0.0.1:8000/health", timeout=2).getcode() == 200 else 1)
    interval: 15s
    timeout: 5s
    retries: 10
    start_period: 10s

services:
  auth-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.auth_service.app:app

  audit-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.audit_service.app:app

  customer-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.customer_service.app:app

  interaction-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.interaction_service.app:app

  routing-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.routing_service.app:app

  voice-adapter-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.voice_adapter_service.app:app

  recording-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.recording_service.app:app
      CC_RECORDINGS_DIR: /app/.data_pg_parallel/recordings
      RECORDING_MAX_BYTES: 26214400

  ivr-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.ivr_service.app:app

  telegram-adapter-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.telegram_adapter_service.app:app

  whatsapp-adapter-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.whatsapp_adapter_service.app:app

  ai-orchestrator-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.ai_orchestrator_service.app:app

  streaming-asr-sidecar:
    <<: *service_defaults
    command: ["sh", "-c", "uvicorn $${APP_MODULE} --host 0.0.0.0 --port 8021"]
    environment:
      <<: *app_env
      APP_MODULE: services.streaming_asr_sidecar_service.app:app
      AI_VOICE_V2_STREAMING_ASR_MODEL: base
      AI_VOICE_V2_STREAMING_ASR_COMPUTE_TYPE: int8
      AI_VOICE_V2_STREAMING_ASR_DEVICE: cpu
      AI_VOICE_V2_STREAMING_ASR_CACHE_DIR: /models/faster_whisper
      AI_VOICE_V2_STREAMING_ASR_SUPPORTED_LANGUAGES: ru
    volumes:
      - ../.data_pg_parallel:/app/.data_pg_parallel
      - ../.models/faster_whisper:/models/faster_whisper
    healthcheck:
      test:
        - CMD
        - python
        - -c
        - |
          from urllib.request import urlopen
          import sys
          sys.exit(0 if urlopen("http://127.0.0.1:8021/health", timeout=2).getcode() == 200 else 1)
      interval: 15s
      timeout: 5s
      retries: 10
      start_period: 10s

  ai-voice-runtime-service:
    <<: *service_defaults
    depends_on:
      - streaming-asr-sidecar
    environment:
      <<: *app_env
      APP_MODULE: services.ai_voice_runtime_service.app:app

  webchat-adapter-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.webchat_adapter_service.app:app

  email-adapter-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.email_adapter_service.app:app

  kb-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.kb_service.app:app

  reporting-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.reporting_service.app:app

  supervisor-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.supervisor_service.app:app

  sales-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.sales_service.app:app
      SALES_TELEGRAM_BRIDGE_ENABLED: "1"
      SALES_VOICE_RUNTIME_ENABLED: "1"

  event-bus-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.event_bus_service.app:app

  asterisk-bridge-service:
    <<: *service_defaults
    environment:
      <<: *app_env
      APP_MODULE: services.asterisk_bridge_service.app:app
      ASTERISK_IVR_FASTAGI_HOST: 0.0.0.0
      ASTERISK_IVR_FASTAGI_PORT: 4573

  api-gateway:
    <<: *service_defaults
    depends_on:
      - auth-service
      - audit-service
      - customer-service
      - interaction-service
      - routing-service
      - voice-adapter-service
      - recording-service
      - ivr-service
      - telegram-adapter-service
      - whatsapp-adapter-service
      - ai-orchestrator-service
      - ai-voice-runtime-service
      - webchat-adapter-service
      - email-adapter-service
      - kb-service
      - reporting-service
      - supervisor-service
      - sales-service
      - event-bus-service
      - asterisk-bridge-service
    environment:
      <<: *app_env
      APP_MODULE: gateway.app:app
    ports:
      - "18080:8000"

networks:
  postgres:
    external: true
    name: call-center-postgres_default
