# =========================================================
# BreakPilot Lehrer — KI-Lehrerplattform
# =========================================================
# Voraussetzung: breakpilot-core muss laufen!
# Start: docker compose up -d
# =========================================================

networks:
  breakpilot-network:
    external: true
    name: breakpilot-network

volumes:
  klausur_uploads:
  eh_uploads:
  ocr_labeling:
  paddle_models:
  lighton_models:
  paddleocr_models:
  transcription_models:
  transcription_temp:
  lehrer_backend_data:
  opensearch_data:
  # Communication (Jitsi + Matrix)
  synapse_data:
  synapse_db_data:
  jitsi_web_config:
  jitsi_web_crontabs:
  jitsi_transcripts:
  jitsi_prosody_config:
  jitsi_prosody_plugins:
  jitsi_jicofo_config:
  jitsi_jvb_config:
  # Voice
  voice_session_data:

services:

  # =========================================================
  # CORE HEALTH CHECK — wartet auf Core-Infrastruktur
  # =========================================================
  core-health-check:
    image: curlimages/curl:latest
    container_name: bp-lehrer-core-wait
    command: >
      sh -c "
        echo 'Waiting for Core infrastructure...'
        until curl -sf http://bp-core-health:8099/health; do
          echo 'Core not ready, waiting 5s...'
          sleep 5
        done
        echo 'Core is healthy!'
      "
    restart: "no"
    networks:
      - breakpilot-network

  # =========================================================
  # FRONTEND
  # =========================================================
  admin-lehrer:
    build:
      context: ./admin-lehrer
      dockerfile: Dockerfile
      args:
        NEXT_PUBLIC_API_URL: ${NEXT_PUBLIC_API_URL:-https://macmini:8001}
        NEXT_PUBLIC_OLD_ADMIN_URL: ${NEXT_PUBLIC_OLD_ADMIN_URL:-http://macmini:3000/admin}
        NEXT_PUBLIC_KLAUSUR_SERVICE_URL: ${NEXT_PUBLIC_KLAUSUR_SERVICE_URL:-https://macmini:8086}
        NEXT_PUBLIC_VOICE_SERVICE_URL: ${NEXT_PUBLIC_VOICE_SERVICE_URL:-wss://macmini:8091}
    container_name: bp-lehrer-admin
    platform: linux/arm64
    expose:
      - "3000"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - lehrer_backend_data:/app/data
    environment:
      NODE_ENV: production
      BACKEND_URL: http://backend-lehrer:8001
      CONSENT_SERVICE_URL: http://bp-core-consent-service:8081
      KLAUSUR_SERVICE_URL: http://klausur-service:8086
      OLLAMA_URL: ${OLLAMA_URL:-http://host.docker.internal:11434}
      WOODPECKER_URL: http://bp-core-woodpecker-server:8000
      WOODPECKER_TOKEN: ${WOODPECKER_TOKEN:-}
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      core-health-check:
        condition: service_completed_successfully
      backend-lehrer:
        condition: service_started
    restart: unless-stopped
    networks:
      - breakpilot-network

  studio-v2:
    build:
      context: ./studio-v2
      dockerfile: Dockerfile
      args:
        NEXT_PUBLIC_VOICE_SERVICE_URL: ${NEXT_PUBLIC_VOICE_SERVICE_URL:-wss://macmini:8091}
        NEXT_PUBLIC_KLAUSUR_SERVICE_URL: ${NEXT_PUBLIC_KLAUSUR_SERVICE_URL:-https://macmini:8086}
    container_name: bp-lehrer-studio-v2
    platform: linux/arm64
    ports:
      - "3001:3001"
      - "3004:3001"
    environment:
      NODE_ENV: production
      BACKEND_URL: http://backend-lehrer:8001
    depends_on:
      - backend-lehrer
    restart: unless-stopped
    networks:
      - breakpilot-network

  website:
    build:
      context: ./website
      dockerfile: Dockerfile
      args:
        NEXT_PUBLIC_BILLING_API_URL: ${NEXT_PUBLIC_BILLING_API_URL:-https://macmini:8083}
        NEXT_PUBLIC_APP_URL: ${NEXT_PUBLIC_APP_URL:-https://macmini}
        NEXT_PUBLIC_KLAUSUR_SERVICE_URL: ${NEXT_PUBLIC_KLAUSUR_SERVICE_URL:-https://macmini:8086}
        NEXT_PUBLIC_VOICE_SERVICE_URL: ${NEXT_PUBLIC_VOICE_SERVICE_URL:-wss://macmini:8091}
        NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY: ${NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY:-}
    container_name: bp-lehrer-website
    platform: linux/arm64
    expose:
      - "3000"
    environment:
      NODE_ENV: production
      VAST_API_KEY: ${VAST_API_KEY:-}
      CONTROL_API_KEY: ${CONTROL_API_KEY:-}
      BACKEND_URL: http://backend-lehrer:8001
      CONSENT_SERVICE_URL: http://bp-core-consent-service:8081
      EDU_SEARCH_URL: ${EDU_SEARCH_URL:-}
      EDU_SEARCH_API_KEY: ${EDU_SEARCH_API_KEY:-}
      WOODPECKER_URL: http://bp-core-woodpecker-server:8000
      WOODPECKER_TOKEN: ${WOODPECKER_TOKEN:-}
    depends_on:
      - backend-lehrer
    restart: unless-stopped
    networks:
      - breakpilot-network

  # =========================================================
  # BACKEND
  # =========================================================
  backend-lehrer:
    build:
      context: ./backend-lehrer
      dockerfile: Dockerfile
    container_name: bp-lehrer-backend
    user: "0:0"
    platform: linux/arm64
    expose:
      - "8001"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
      - lehrer_backend_data:/app/data
    environment:
      PORT: 8001
      DATABASE_URL: postgresql+asyncpg://${POSTGRES_USER:-breakpilot}:${POSTGRES_PASSWORD:-breakpilot123}@bp-core-postgres:5432/${POSTGRES_DB:-breakpilot_db}?options=-csearch_path%3Dlehrer,core,public
      JWT_SECRET: ${JWT_SECRET:-your-super-secret-jwt-key-change-in-production}
      ENVIRONMENT: ${ENVIRONMENT:-development}
      CONSENT_SERVICE_URL: http://bp-core-consent-service:8081
      KLAUSUR_SERVICE_URL: http://klausur-service:8086
      TROCR_SERVICE_URL: http://paddleocr-service:8095
      VALKEY_URL: redis://bp-core-valkey:6379/0
      SESSION_TTL_HOURS: ${SESSION_TTL_HOURS:-24}
      ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-}
      DEBUG: ${DEBUG:-false}
      ALERTS_AGENT_ENABLED: ${ALERTS_AGENT_ENABLED:-false}
      VAULT_ADDR: http://bp-core-vault:8200
      VAULT_TOKEN: ${VAULT_TOKEN:-breakpilot-dev-token}
      USE_VAULT_SECRETS: ${USE_VAULT_SECRETS:-false}
      VAST_API_KEY: ${VAST_API_KEY:-}
      VAST_INSTANCE_ID: ${VAST_INSTANCE_ID:-}
      CONTROL_API_KEY: ${CONTROL_API_KEY:-}
      OLLAMA_BASE_URL: ${OLLAMA_BASE_URL:-http://host.docker.internal:11434}
      OLLAMA_ENABLED: ${OLLAMA_ENABLED:-true}
      OLLAMA_DEFAULT_MODEL: ${OLLAMA_DEFAULT_MODEL:-llama3.2}
      OLLAMA_VISION_MODEL: ${OLLAMA_VISION_MODEL:-llama3.2-vision}
      OLLAMA_CORRECTION_MODEL: ${OLLAMA_CORRECTION_MODEL:-llama3.2}
      OLLAMA_TIMEOUT: ${OLLAMA_TIMEOUT:-120}
      GAME_USE_DATABASE: ${GAME_USE_DATABASE:-true}
      GAME_REQUIRE_AUTH: ${GAME_REQUIRE_AUTH:-false}
      GAME_REQUIRE_BILLING: ${GAME_REQUIRE_BILLING:-false}
      GAME_LLM_MODEL: ${GAME_LLM_MODEL:-llama3.2}
      SMTP_HOST: ${SMTP_HOST:-bp-core-mailpit}
      SMTP_PORT: ${SMTP_PORT:-1025}
      SMTP_USERNAME: ${SMTP_USERNAME:-}
      SMTP_PASSWORD: ${SMTP_PASSWORD:-}
      SMTP_FROM_NAME: ${SMTP_FROM_NAME:-BreakPilot}
      SMTP_FROM_ADDR: ${SMTP_FROM_ADDR:-noreply@breakpilot.app}
      RAG_SERVICE_URL: http://bp-core-rag-service:8097
    extra_hosts:
      - "host.docker.internal:host-gateway"
      - "mac-mini:192.168.178.163"
    depends_on:
      core-health-check:
        condition: service_completed_successfully
    restart: unless-stopped
    networks:
      - breakpilot-network

  # =========================================================
  # MICROSERVICES
  # =========================================================
  klausur-service:
    build:
      context: ./klausur-service
      dockerfile: Dockerfile
    container_name: bp-lehrer-klausur-service
    platform: linux/arm64
    expose:
      - "8086"
    volumes:
      - klausur_uploads:/app/uploads
      - eh_uploads:/app/eh-uploads
      - ocr_labeling:/app/ocr-labeling
      - paddle_models:/root/.paddlex
      - lighton_models:/root/.cache/huggingface
    environment:
      JWT_SECRET: ${JWT_SECRET:-your-super-secret-jwt-key-change-in-production}
      BACKEND_URL: http://backend-lehrer:8001
      SCHOOL_SERVICE_URL: http://school-service:8084
      ENVIRONMENT: ${ENVIRONMENT:-development}
      DATABASE_URL: postgresql://${POSTGRES_USER:-breakpilot}:${POSTGRES_PASSWORD:-breakpilot123}@bp-core-postgres:5432/${POSTGRES_DB:-breakpilot_db}
      EMBEDDING_SERVICE_URL: http://bp-core-embedding-service:8087
      QDRANT_URL: http://bp-core-qdrant:6333
      MINIO_ENDPOINT: bp-core-minio:9000
      MINIO_ACCESS_KEY: ${MINIO_ROOT_USER:-breakpilot}
      MINIO_SECRET_KEY: ${MINIO_ROOT_PASSWORD:-breakpilot123}
      MINIO_BUCKET: ${MINIO_BUCKET:-breakpilot-rag}
      MINIO_SECURE: "false"
      PADDLEOCR_SERVICE_URL: http://paddleocr-service:8095
      PADDLEOCR_REMOTE_URL: ${PADDLEOCR_REMOTE_URL:-https://hetzner.meghsakha.com:8095}
      PADDLEOCR_API_KEY: ${PADDLEOCR_API_KEY:-}
      VAULT_ADDR: http://bp-core-vault:8200
      VAULT_TOKEN: ${VAULT_TOKEN:-breakpilot-dev-token}
      ANTHROPIC_API_KEY: ${ANTHROPIC_API_KEY:-}
      OLLAMA_BASE_URL: ${OLLAMA_BASE_URL:-http://host.docker.internal:11434}
      OLLAMA_ENABLED: ${OLLAMA_ENABLED:-true}
      OLLAMA_DEFAULT_MODEL: ${OLLAMA_DEFAULT_MODEL:-llama3.2}
      OLLAMA_VISION_MODEL: ${OLLAMA_VISION_MODEL:-llama3.2-vision}
      OLLAMA_CORRECTION_MODEL: ${OLLAMA_CORRECTION_MODEL:-llama3.2}
      OLLAMA_REVIEW_MODEL: ${OLLAMA_REVIEW_MODEL:-qwen3:0.6b}
      OLLAMA_REVIEW_BATCH_SIZE: ${OLLAMA_REVIEW_BATCH_SIZE:-20}
      REVIEW_ENGINE: ${REVIEW_ENGINE:-spell}
      OCR_ENGINE: ${OCR_ENGINE:-auto}
      OLLAMA_HTR_MODEL: ${OLLAMA_HTR_MODEL:-qwen2.5vl:32b}
      HTR_FALLBACK_MODEL: ${HTR_FALLBACK_MODEL:-trocr-large}
      RAG_SERVICE_URL: http://bp-core-rag-service:8097
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      core-health-check:
        condition: service_completed_successfully
      school-service:
        condition: service_started
    healthcheck:
      test: ["CMD", "curl", "-f", "http://127.0.0.1:8086/health"]
      interval: 30s
      timeout: 30s
      retries: 3
      start_period: 10s
    restart: unless-stopped
    networks:
      - breakpilot-network

  school-service:
    build:
      context: ./school-service
      dockerfile: Dockerfile
    container_name: bp-lehrer-school-service
    platform: linux/arm64
    ports:
      - "8084:8084"
    environment:
      DATABASE_URL: postgresql://${POSTGRES_USER:-breakpilot}:${POSTGRES_PASSWORD:-breakpilot123}@bp-core-postgres:5432/${POSTGRES_DB:-breakpilot_db}
      JWT_SECRET: ${JWT_SECRET:-your-super-secret-jwt-key-change-in-production}
      PORT: 8084
      ENVIRONMENT: ${ENVIRONMENT:-development}
      ALLOWED_ORIGINS: "*"
      LLM_GATEWAY_URL: http://backend-lehrer:8001/llm
    depends_on:
      core-health-check:
        condition: service_completed_successfully
    restart: unless-stopped
    networks:
      - breakpilot-network

  paddleocr-service:
    build:
      context: ./paddleocr-service
      dockerfile: Dockerfile
    container_name: bp-lehrer-paddleocr
    profiles: [ocr]
    platform: linux/amd64
    expose:
      - "8095"
    environment:
      PADDLE_PDX_DISABLE_MODEL_SOURCE_CHECK: "True"
    volumes:
      - paddleocr_models:/root/.paddlex
      - paddleocr_models:/root/.paddleocr
    healthcheck:
      test: ["CMD", "curl", "-f", "http://127.0.0.1:8095/health"]
      interval: 30s
      timeout: 60s
      start_period: 180s
      retries: 5
    restart: unless-stopped
    networks:
      - breakpilot-network

  breakpilot-drive:
    build:
      context: ./breakpilot-drive
      dockerfile: Dockerfile
    container_name: bp-lehrer-drive
    ports:
      - "3001:3001"
    environment:
      API_BASE_URL: http://backend-lehrer:8001
      GAME_REQUIRE_AUTH: ${GAME_REQUIRE_AUTH:-false}
      GAME_ENABLE_LEADERBOARDS: ${GAME_ENABLE_LEADERBOARDS:-true}
    depends_on:
      - backend-lehrer
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://127.0.0.1:3001/health.json"]
      interval: 30s
      timeout: 10s
      retries: 3
    profiles:
      - game
    restart: unless-stopped
    networks:
      - breakpilot-network

  agent-core:
    build:
      context: ./agent-core
      dockerfile: Dockerfile
    container_name: bp-lehrer-agent-core
    profiles: [dev]
    platform: linux/arm64
    environment:
      BACKEND_URL: http://backend-lehrer:8001
      OLLAMA_BASE_URL: ${OLLAMA_BASE_URL:-http://host.docker.internal:11434}
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      - backend-lehrer
    restart: unless-stopped
    networks:
      - breakpilot-network

  transcription-worker:
    build:
      context: ./backend-lehrer
      dockerfile: Dockerfile.worker
    container_name: bp-lehrer-transcription-worker
    volumes:
      - transcription_models:/root/.cache/huggingface
      - transcription_temp:/tmp/transcriptions
    environment:
      DATABASE_URL: postgresql://${POSTGRES_USER:-breakpilot}:${POSTGRES_PASSWORD:-breakpilot123}@bp-core-postgres:5432/${POSTGRES_DB:-breakpilot_db}
      REDIS_URL: redis://bp-core-valkey:6379/0
      WHISPER_MODEL: ${WHISPER_MODEL:-base}
      WHISPER_DEVICE: ${WHISPER_DEVICE:-cpu}
      WHISPER_COMPUTE_TYPE: ${WHISPER_COMPUTE_TYPE:-int8}
      PYANNOTE_AUTH_TOKEN: ${PYANNOTE_AUTH_TOKEN:-}
      MINIO_ENDPOINT: bp-core-minio:9000
      MINIO_ACCESS_KEY: ${MINIO_ROOT_USER:-breakpilot}
      MINIO_SECRET_KEY: ${MINIO_ROOT_PASSWORD:-breakpilot123}
      MINIO_BUCKET: ${MINIO_BUCKET:-breakpilot-recordings}
      MINIO_SECURE: "false"
      TZ: ${TZ:-Europe/Berlin}
    deploy:
      resources:
        limits:
          memory: 8G
        reservations:
          memory: 4G
    depends_on:
      core-health-check:
        condition: service_completed_successfully
    profiles:
      - recording
    restart: unless-stopped
    networks:
      - breakpilot-network

  # =========================================================
  # VOICE SERVICE
  # =========================================================
  voice-service:
    build:
      context: ./voice-service
      dockerfile: Dockerfile
    container_name: bp-lehrer-voice-service
    platform: linux/arm64
    expose:
      - "8091"
    volumes:
      - voice_session_data:/app/data/sessions
    environment:
      PORT: 8091
      DATABASE_URL: postgresql://${POSTGRES_USER:-breakpilot}:${POSTGRES_PASSWORD:-breakpilot123}@bp-core-postgres:5432/${POSTGRES_DB:-breakpilot_db}
      VALKEY_URL: redis://bp-core-valkey:6379/0
      KLAUSUR_SERVICE_URL: http://klausur-service:8086
      OLLAMA_BASE_URL: ${OLLAMA_BASE_URL:-http://host.docker.internal:11434}
      OLLAMA_VOICE_MODEL: ${OLLAMA_VOICE_MODEL:-llama3.2}
      ENVIRONMENT: ${ENVIRONMENT:-development}
      JWT_SECRET: ${JWT_SECRET:-your-super-secret-jwt-key-change-in-production}
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      core-health-check:
        condition: service_completed_successfully
    healthcheck:
      test: ["CMD", "curl", "-f", "http://127.0.0.1:8091/health"]
      interval: 30s
      timeout: 10s
      start_period: 60s
      retries: 3
    restart: unless-stopped
    networks:
      - breakpilot-network

  # =========================================================
  # COMMUNICATION: Jitsi Meet
  # =========================================================
  jitsi-web:
    image: jitsi/web:stable-9823
    container_name: bp-lehrer-jitsi-web
    expose:
      - "80"
    volumes:
      - jitsi_web_config:/config
      - jitsi_web_crontabs:/var/spool/cron/crontabs
      - jitsi_transcripts:/usr/share/jitsi-meet/transcripts
    environment:
      ENABLE_XMPP_WEBSOCKET: "true"
      ENABLE_COLIBRI_WEBSOCKET: "true"
      XMPP_DOMAIN: ${XMPP_DOMAIN:-meet.jitsi}
      XMPP_BOSH_URL_BASE: http://jitsi-xmpp:5280
      XMPP_MUC_DOMAIN: ${XMPP_MUC_DOMAIN:-muc.meet.jitsi}
      XMPP_GUEST_DOMAIN: ${XMPP_GUEST_DOMAIN:-guest.meet.jitsi}
      TZ: ${TZ:-Europe/Berlin}
      PUBLIC_URL: ${JITSI_PUBLIC_URL:-https://macmini:8443}
      JICOFO_AUTH_USER: focus
      ENABLE_AUTH: ${JITSI_ENABLE_AUTH:-false}
      ENABLE_GUESTS: "true"
      ENABLE_RECORDING: "true"
      ENABLE_LIVESTREAMING: "false"
      DISABLE_HTTPS: "true"
      APP_NAME: "BreakPilot Meet"
      NATIVE_APP_NAME: "BreakPilot Meet"
      PROVIDER_NAME: "BreakPilot"
    depends_on:
      - jitsi-xmpp
    networks:
      breakpilot-network:
        aliases:
          - meet.jitsi

  jitsi-xmpp:
    image: jitsi/prosody:stable-9823
    container_name: bp-lehrer-jitsi-xmpp
    volumes:
      - jitsi_prosody_config:/config
      - jitsi_prosody_plugins:/prosody-plugins-custom
    environment:
      XMPP_DOMAIN: ${XMPP_DOMAIN:-meet.jitsi}
      XMPP_AUTH_DOMAIN: ${XMPP_AUTH_DOMAIN:-auth.meet.jitsi}
      XMPP_MUC_DOMAIN: ${XMPP_MUC_DOMAIN:-muc.meet.jitsi}
      XMPP_INTERNAL_MUC_DOMAIN: ${XMPP_INTERNAL_MUC_DOMAIN:-internal-muc.meet.jitsi}
      XMPP_GUEST_DOMAIN: ${XMPP_GUEST_DOMAIN:-guest.meet.jitsi}
      XMPP_RECORDER_DOMAIN: ${XMPP_RECORDER_DOMAIN:-recorder.meet.jitsi}
      XMPP_CROSS_DOMAIN: "true"
      TZ: ${TZ:-Europe/Berlin}
      JICOFO_AUTH_USER: focus
      JICOFO_AUTH_PASSWORD: ${JICOFO_AUTH_PASSWORD:-jicofo_secret}
      JVB_AUTH_USER: jvb
      JVB_AUTH_PASSWORD: ${JVB_AUTH_PASSWORD:-jvb_secret}
      JIBRI_XMPP_USER: jibri
      JIBRI_XMPP_PASSWORD: ${JIBRI_XMPP_PASSWORD:-jibri_secret}
      JIBRI_RECORDER_USER: recorder
      JIBRI_RECORDER_PASSWORD: ${JIBRI_RECORDER_PASSWORD:-recorder_secret}
      LOG_LEVEL: ${XMPP_LOG_LEVEL:-warn}
      PUBLIC_URL: ${JITSI_PUBLIC_URL:-https://macmini:8443}
      ENABLE_AUTH: ${JITSI_ENABLE_AUTH:-false}
      ENABLE_GUESTS: "true"
    restart: unless-stopped
    networks:
      breakpilot-network:
        aliases:
          - xmpp.meet.jitsi

  jitsi-jicofo:
    image: jitsi/jicofo:stable-9823
    container_name: bp-lehrer-jitsi-jicofo
    volumes:
      - jitsi_jicofo_config:/config
    environment:
      XMPP_DOMAIN: ${XMPP_DOMAIN:-meet.jitsi}
      XMPP_AUTH_DOMAIN: ${XMPP_AUTH_DOMAIN:-auth.meet.jitsi}
      XMPP_MUC_DOMAIN: ${XMPP_MUC_DOMAIN:-muc.meet.jitsi}
      XMPP_INTERNAL_MUC_DOMAIN: ${XMPP_INTERNAL_MUC_DOMAIN:-internal-muc.meet.jitsi}
      XMPP_SERVER: jitsi-xmpp
      JICOFO_AUTH_USER: focus
      JICOFO_AUTH_PASSWORD: ${JICOFO_AUTH_PASSWORD:-jicofo_secret}
      TZ: ${TZ:-Europe/Berlin}
      ENABLE_AUTH: ${JITSI_ENABLE_AUTH:-false}
      AUTH_TYPE: internal
      ENABLE_AUTO_OWNER: "true"
    depends_on:
      - jitsi-xmpp
    restart: unless-stopped
    networks:
      - breakpilot-network

  jitsi-jvb:
    image: jitsi/jvb:stable-9823
    container_name: bp-lehrer-jitsi-jvb
    ports:
      - "10000:10000/udp"
      - "8080:8080"
    volumes:
      - jitsi_jvb_config:/config
    environment:
      XMPP_DOMAIN: ${XMPP_DOMAIN:-meet.jitsi}
      XMPP_AUTH_DOMAIN: ${XMPP_AUTH_DOMAIN:-auth.meet.jitsi}
      XMPP_INTERNAL_MUC_DOMAIN: ${XMPP_INTERNAL_MUC_DOMAIN:-internal-muc.meet.jitsi}
      XMPP_SERVER: jitsi-xmpp
      JVB_AUTH_USER: jvb
      JVB_AUTH_PASSWORD: ${JVB_AUTH_PASSWORD:-jvb_secret}
      JVB_PORT: 10000
      JVB_STUN_SERVERS: ${JVB_STUN_SERVERS:-stun.l.google.com:19302}
      TZ: ${TZ:-Europe/Berlin}
      PUBLIC_URL: ${JITSI_PUBLIC_URL:-https://macmini:8443}
      COLIBRI_REST_ENABLED: "true"
      ENABLE_COLIBRI_WEBSOCKET: "true"
    depends_on:
      - jitsi-xmpp
    restart: unless-stopped
    networks:
      - breakpilot-network

  # =========================================================
  # COMMUNICATION: Matrix/Synapse
  # =========================================================
  synapse-db:
    image: postgres:16-alpine
    container_name: bp-lehrer-synapse-db
    profiles: [chat]
    environment:
      POSTGRES_USER: synapse
      POSTGRES_PASSWORD: ${SYNAPSE_DB_PASSWORD:-synapse_secret}
      POSTGRES_DB: synapse
      POSTGRES_INITDB_ARGS: "--encoding=UTF-8 --lc-collate=C --lc-ctype=C"
    volumes:
      - synapse_db_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U synapse"]
      interval: 5s
      timeout: 5s
      retries: 5
    restart: unless-stopped
    networks:
      - breakpilot-network

  synapse:
    image: matrixdotorg/synapse:latest
    container_name: bp-lehrer-synapse
    profiles: [chat]
    ports:
      - "8008:8008"
      - "8448:8448"
    volumes:
      - synapse_data:/data
    environment:
      SYNAPSE_SERVER_NAME: ${SYNAPSE_SERVER_NAME:-macmini}
      SYNAPSE_REPORT_STATS: "no"
      SYNAPSE_NO_TLS: "true"
      SYNAPSE_ENABLE_REGISTRATION: ${SYNAPSE_ENABLE_REGISTRATION:-true}
      SYNAPSE_LOG_LEVEL: ${SYNAPSE_LOG_LEVEL:-WARNING}
      UID: "1000"
      GID: "1000"
    healthcheck:
      test: ["CMD", "curl", "-f", "http://127.0.0.1:8008/health"]
      interval: 30s
      timeout: 10s
      start_period: 30s
      retries: 3
    depends_on:
      synapse-db:
        condition: service_healthy
    restart: unless-stopped
    networks:
      - breakpilot-network

  # =========================================================
  # EDU SEARCH
  # =========================================================
  opensearch:
    image: opensearchproject/opensearch:2.11.1
    container_name: bp-lehrer-opensearch
    environment:
      - cluster.name=edu-search-cluster
      - node.name=opensearch-node1
      - discovery.type=single-node
      - bootstrap.memory_lock=true
      - "OPENSEARCH_JAVA_OPTS=-Xms512m -Xmx512m"
      - OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_PASSWORD:-Admin123!}
      - plugins.security.disabled=true
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    volumes:
      - opensearch_data:/usr/share/opensearch/data
    healthcheck:
      test: ["CMD-SHELL", "curl -s http://localhost:9200 >/dev/null || exit 1"]
      interval: 30s
      timeout: 10s
      retries: 5
      start_period: 60s
    restart: unless-stopped
    networks:
      - breakpilot-network

  edu-search-service:
    build:
      context: ./edu-search-service
      dockerfile: Dockerfile
    container_name: bp-lehrer-edu-search
    platform: linux/arm64
    expose:
      - "8088"
    environment:
      PORT: 8088
      OPENSEARCH_URL: http://opensearch:9200
      OPENSEARCH_USERNAME: admin
      OPENSEARCH_PASSWORD: ${OPENSEARCH_PASSWORD:-Admin123!}
      INDEX_NAME: bp_documents_v1
      EDU_SEARCH_API_KEY: ${EDU_SEARCH_API_KEY:-}
      USER_AGENT: "BreakpilotEduCrawler/1.0 (+contact: security@breakpilot.com)"
      RATE_LIMIT_PER_SEC: "0.2"
      MAX_DEPTH: "4"
      MAX_PAGES_PER_RUN: "500"
      DB_HOST: bp-core-postgres
      DB_PORT: "5432"
      DB_USER: ${POSTGRES_USER:-breakpilot}
      DB_PASSWORD: ${POSTGRES_PASSWORD:-breakpilot123}
      DB_NAME: ${POSTGRES_DB:-breakpilot_db}
      DB_SSLMODE: disable
      STAFF_CRAWLER_EMAIL: crawler@breakpilot.de
    depends_on:
      core-health-check:
        condition: service_completed_successfully
      opensearch:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8088/v1/health"]
      interval: 30s
      timeout: 3s
      start_period: 10s
      retries: 3
    restart: unless-stopped
    networks:
      - breakpilot-network

  # =========================================================
  # DOCUMENTATION
  # =========================================================
  docs:
    build:
      context: .
      dockerfile: docs-src/Dockerfile
    container_name: bp-lehrer-docs
    profiles: [docs]
    platform: linux/arm64
    ports:
      - "8010:80"
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://127.0.0.1:80/"]
      interval: 30s
      timeout: 10s
      retries: 3
    restart: unless-stopped
    networks:
      - breakpilot-network
