# Production-mode compose.
# Usage:
#   docker compose up --build
#
# Requires:
#   - backend/.env populated (copy from backend/.env.example)
#   - GITEA_NPM_TOKEN env var set when BYTELYST_PACKAGE_SOURCE=gitea
#
# For hot-reload dev mode use:
#   docker compose -f docker-compose.yml -f docker-compose.dev.yml up
#
# For Docker backend + local Vite web:
#   pnpm dev  (or: sh scripts/dev.sh)

services:
  # ---------------------------------------------------------------------------
  # Backend — trading engine + REST API + Socket.IO
  # ---------------------------------------------------------------------------
  backend:
    build:
      context: .
      dockerfile: backend/Dockerfile
      args:
        BYTELYST_PACKAGE_SOURCE: ${BYTELYST_PACKAGE_SOURCE:-vendor}
        GITEA_NPM_TOKEN: ${GITEA_NPM_TOKEN:-}
    container_name: invttrdg-backend
    env_file:
      - backend/.env
    ports:
      - '4025:4018'
    networks:
      - default
      - platform_net
    restart: unless-stopped
    healthcheck:
      test: ['CMD', 'wget', '-qO-', 'http://localhost:4018/health/live']
      interval: 30s
      timeout: 5s
      retries: 3
      start_period: 15s

  # ---------------------------------------------------------------------------
  # Web — Vite SPA served via nginx
  # ---------------------------------------------------------------------------
  web:
    build:
      context: .
      dockerfile: web/Dockerfile
      args:
        BYTELYST_PACKAGE_SOURCE: ${BYTELYST_PACKAGE_SOURCE:-vendor}
        GITEA_NPM_TOKEN: ${GITEA_NPM_TOKEN:-}
        VITE_PRODUCT_ID: ${VITE_PRODUCT_ID:-invttrdg}
        # Public web builds must use the hosted APIs even if local .env contains dev localhost values.
        VITE_PLATFORM_URL: https://api.bytelyst.com/platform/api
        VITE_TRADING_API_URL: https://api.bytelyst.com/invttrdg
        VITE_BACKTEST_ENABLED: ${VITE_BACKTEST_ENABLED:-true}
    container_name: invttrdg-web
    ports:
      - '3085:3085'
    networks:
      - default
      - platform_net
    restart: unless-stopped
    depends_on:
      backend:
        condition: service_healthy

networks:
  default: {}
  platform_net:
    external: true
    name: learning_ai_common_plat_default
