
x-app-env: &app_env
  CC_DATA_DIR: /app/.data
  DATABASE_URL: postgresql://mvp:mvp@postgres:5432/mvpcc
  SCHEMA_MANAGEMENT_MODE: migrations
  EVENT_BUS_ENABLED: "1"
  EVENT_BUS_URL: amqp://guest:guest@rabbitmq:5672/
  EVENT_BUS_EXCHANGE: mvpcc.domain.events
  EVENT_BUS_DISPATCH_BATCH_SIZE: "50"
  EVENT_BUS_MAX_ATTEMPTS: "5"
  EVENT_BUS_POLL_INTERVAL_SECONDS: "2"
  EVENT_BUS_CONSUMER_ENABLED: "1"
  EVENT_BUS_AUDIT_QUEUE: mvpcc.audit.events
  EVENT_BUS_REPORTING_QUEUE: mvpcc.reporting.events
  ASTERISK_BRIDGE_ENABLED: "0"
  ASTERISK_AMI_EVENT_PREFIX: MVPCC
  ASTERISK_QUEUE_MAP_JSON: "{}"
  AI_VOICE_RUNTIME_SERVICE_URL: http://ai-voice-runtime-service:8000
  AI_VOICE_ENABLED: "0"
  AI_VOICE_QUEUE_CONFIG_JSON: "{}"
  AI_VOICE_POLICY_MODE: v2_fast_conversational
  AI_VOICE_ASR_PROVIDER: ${AI_VOICE_ASR_PROVIDER:-yandex}
  AI_VOICE_TTS_PROVIDER: ${AI_VOICE_TTS_PROVIDER:-yandex}
  AI_VOICE_AUDIOSOCKET_ENABLED: "1"
  AI_VOICE_AUDIOSOCKET_HOST: 0.0.0.0
  AI_VOICE_AUDIOSOCKET_PORT: "9019"
  AI_VOICE_ASR_MODEL: gpt-4o-mini-transcribe
  AI_VOICE_TTS_MODEL: gpt-4o-mini-tts
  AI_VOICE_TTS_VOICE: alloy
  AI_VOICE_TTS_CACHE_ENABLED: "1"
  AI_VOICE_TTS_CACHE_DIR: /app/.data/ai_voice_tts_cache
  AI_VOICE_VAD_MIN_SPEECH_MS: "300"
  AI_VOICE_VAD_TRAILING_SILENCE_MS: "400"
  AI_VOICE_V2_ENABLED: "1"
  AI_VOICE_V2_QUEUE_CODES: voice_lab_ai
  AI_VOICE_V2_ACK_MODE: immediate_short
  AI_VOICE_V2_DUPLEX_ENABLED: "1"
  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"
  AI_VOICE_V2_PREBAKED_ACK_ENABLED: "1"
  AI_VOICE_V2_PREBAKED_ACK_DIR: /app/.data/voice_v2_ack_bank
  AI_VOICE_V2_STREAMING_TTS: "1"
  AI_VOICE_V2_PARTIAL_ASR: "1"
  AI_VOICE_V2_EMOTIVE_ACK_ENABLED: "1"
  AI_VOICE_V2_EMOTIVE_ACK_RU_ONLY: "1"
  AI_VOICE_TURN_MAX_MS: "10000"
  AI_VOICE_MEDIA_IDLE_TIMEOUT_SECONDS: "15"
  AI_VOICE_MAX_CONTEXT_SEGMENTS: "12"
  AI_VOICE_HANDOFF_TIMEOUT_SECONDS: "8"
  AI_VOICE_RUNTIME_TRUSTED_SERVICE_SUBJECTS: svc:ai-voice-runtime

services:
  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_DB: mvpcc
      POSTGRES_USER: mvp
      POSTGRES_PASSWORD: mvp
    volumes:
      - pgdata:/var/lib/postgresql/data
    ports:
      - "5432:5432"

  rabbitmq:
    image: rabbitmq:3-management
    ports:
      - "5672:5672"
      - "15672:15672"

  auth-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.auth_service.app:app
    volumes:
      - ../.data:/app/.data
    ports:
      - "8001:8000"

  audit-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.audit_service.app:app
    volumes:
      - ../.data:/app/.data
    ports:
      - "8002:8000"

  customer-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.customer_service.app:app
    volumes:
      - ../.data:/app/.data
    ports:
      - "8003:8000"

  interaction-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.interaction_service.app:app
    volumes:
      - ../.data:/app/.data
    ports:
      - "8004:8000"

  routing-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.routing_service.app:app
    volumes:
      - ../.data:/app/.data
    ports:
      - "8005:8000"

  voice-adapter-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.voice_adapter_service.app:app
    volumes:
      - ../.data:/app/.data
    ports:
      - "8006:8000"

  recording-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.recording_service.app:app
      CC_RECORDINGS_DIR: /app/.data/recordings
      RECORDING_MAX_BYTES: 26214400
    volumes:
      - ../.data:/app/.data
    ports:
      - "8013:8000"

  ivr-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.ivr_service.app:app
    volumes:
      - ../.data:/app/.data
    ports:
      - "8014:8000"

  telegram-adapter-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.telegram_adapter_service.app:app
    volumes:
      - ../.data:/app/.data
    ports:
      - "8007:8000"

  whatsapp-adapter-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.whatsapp_adapter_service.app:app
    volumes:
      - ../.data:/app/.data
    ports:
      - "8019:8000"

  ai-orchestrator-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.ai_orchestrator_service.app:app
      TELEGRAM_ADAPTER_SERVICE_URL: http://telegram-adapter-service:8000
      WHATSAPP_ADAPTER_SERVICE_URL: http://whatsapp-adapter-service:8000
      INTERACTION_SERVICE_URL: http://interaction-service:8000
    volumes:
      - ../.data:/app/.data
    ports:
      - "8017:8000"

  streaming-asr-sidecar:
    build: ..
    depends_on: [postgres, rabbitmq]
    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:/app/.data
      - ../.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
    ports:
      - "8021:8021"

  ai-voice-runtime-service:
    build: ..
    depends_on: [postgres, rabbitmq, streaming-asr-sidecar]
    environment:
      <<: *app_env
      APP_MODULE: services.ai_voice_runtime_service.app:app
      AI_ORCHESTRATOR_SERVICE_URL: http://ai-orchestrator-service:8000
      ASTERISK_BRIDGE_SERVICE_URL: http://asterisk-bridge-service:8000
    volumes:
      - ../.data:/app/.data
    ports:
      - "8018:8000"
      - "9019:9019"

  webchat-adapter-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.webchat_adapter_service.app:app
    volumes:
      - ../.data:/app/.data
    ports:
      - "8011:8000"

  email-adapter-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.email_adapter_service.app:app
    volumes:
      - ../.data:/app/.data
    ports:
      - "8012:8000"

  kb-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.kb_service.app:app
    volumes:
      - ../.data:/app/.data
    ports:
      - "8008:8000"

  reporting-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.reporting_service.app:app
    volumes:
      - ../.data:/app/.data
    ports:
      - "8009:8000"

  supervisor-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.supervisor_service.app:app
    volumes:
      - ../.data:/app/.data
    ports:
      - "8010:8000"

  sales-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.sales_service.app:app
      SALES_TELEGRAM_BRIDGE_ENABLED: "1"
      SALES_VOICE_RUNTIME_ENABLED: "1"
    volumes:
      - ../.data:/app/.data
    ports:
      - "8020:8000"

  event-bus-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.event_bus_service.app:app
    volumes:
      - ../.data:/app/.data
    ports:
      - "8015:8000"

  asterisk-bridge-service:
    build: ..
    depends_on: [postgres, rabbitmq]
    environment:
      <<: *app_env
      APP_MODULE: services.asterisk_bridge_service.app:app
      INTERACTION_SERVICE_URL: http://interaction-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
    volumes:
      - ../.data:/app/.data
    ports:
      - "8016:8000"
      - "4573:4573"

  api-gateway:
    build: ..
    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_MODULE: gateway.app:app
      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
      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
    ports:
      - "8080:8000"

volumes:
  pgdata:
