# Development overlay — hot-reload for backend and web.
# Usage:
#   docker compose -f docker-compose.yml -f docker-compose.dev.yml up
#
# Both services mount local source directories so edits are reflected immediately
# without rebuilding the image. Requires node_modules to exist locally
# (run the matching root install first, for example `pnpm run install:common-plat`).

version: '3.9'

services:
  # ---------------------------------------------------------------------------
  # Backend dev — tsx hot-reload
  # ---------------------------------------------------------------------------
  backend:
    build:
      context: .
      dockerfile: backend/Dockerfile
      target: builder          # Stop at the build stage; no production image
    command: >
      sh -c "cd /app/backend && node --import tsx src/bootstrap.ts"
    volumes:
      - ./backend/src:/app/backend/src:ro
      - ./shared:/app/shared:ro
      - ./.env:/app/.env:ro
    environment:
      NODE_ENV: development
    # Override healthcheck for faster feedback in dev
    healthcheck:
      interval: 10s
      start_period: 5s

  # ---------------------------------------------------------------------------
  # Web dev — Vite dev server (HMR)
  # ---------------------------------------------------------------------------
  web:
    image: node:20-alpine
    working_dir: /app/web
    command: >
      sh -c "corepack enable && pnpm run dev --host 0.0.0.0 --port 3048"
    volumes:
      - ./web:/app/web:ro
      - ./shared:/app/shared:ro
      - ./web/node_modules:/app/web/node_modules
      - ./.env:/app/.env:ro
    ports:
      - '3048:3048'
    environment:
      NODE_ENV: development
      VITE_PRODUCT_ID: ${VITE_PRODUCT_ID:-invttrdg}
      VITE_PLATFORM_URL: ${VITE_PLATFORM_URL:-http://localhost:4003/api}
      VITE_TRADING_API_URL: ${VITE_TRADING_API_URL:-http://localhost:4018}
      VITE_BACKTEST_ENABLED: ${VITE_BACKTEST_ENABLED:-true}
    depends_on:
      - backend
