services:
  mysql:
    image: mysql:8.4
    container_name: ai_kb_v2_mysql
    environment:
      MYSQL_ROOT_PASSWORD: rootpass
      MYSQL_DATABASE: ai_knowledge_base_v2
      MYSQL_USER: ai_kb
      MYSQL_PASSWORD: ai_kb
      TZ: Asia/Shanghai
    command:
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
    ports:
      - "3307:3306"
    volumes:
      - ai_kb_v2_mysql_data:/var/lib/mysql
    healthcheck:
      test: ["CMD-SHELL", "mysqladmin ping -h 127.0.0.1 -uai_kb -pai_kb --silent"]
      interval: 5s
      timeout: 5s
      retries: 20

  backend:
    build:
      context: ./apps/backend
    container_name: ai_kb_v2_backend
    environment:
      APP_ENV: docker
      DEBUG: "true"
      DATABASE_URL: mysql+pymysql://ai_kb:ai_kb@mysql:3306/ai_knowledge_base_v2?charset=utf8mb4
      JWT_SECRET_KEY: local-dev-secret-change-before-production
      MOCK_SMS_ENABLED: "true"
      MOCK_SMS_CODE: "123456"
      MOCK_RAG_ENABLED: "false"
      MOCK_MODEL_ENABLED: "true"
      FEISHU_MOCK_ENABLED: "false"
      FEISHU_SEARCH_URL: "${FEISHU_SEARCH_URL:-}"
      FEISHU_APP_ID: "${FEISHU_APP_ID:-}"
      FEISHU_APP_SECRET: "${FEISHU_APP_SECRET:-}"
      AUTO_CREATE_TABLES: "false"
    ports:
      - "8100:8100"
    depends_on:
      mysql:
        condition: service_healthy

  user-client:
    build:
      context: ./apps/user-client
    container_name: ai_kb_v2_user_client
    environment:
      VITE_API_BASE_URL: http://127.0.0.1:8100/api
    ports:
      - "5173:5173"
    depends_on:
      - backend

  admin-web:
    build:
      context: ./apps/admin-web
    container_name: ai_kb_v2_admin_web
    environment:
      VITE_API_BASE_URL: http://127.0.0.1:8100/api
    ports:
      - "5174:5174"
    depends_on:
      - backend

volumes:
  ai_kb_v2_mysql_data:
