version: '3.8'

# =============================================================================
# TRADING PLATFORM - Production Docker Compose
# =============================================================================
# Servidor: 72.60.226.4
# Dominio: trading.isem.dev / api.trading.isem.dev
# =============================================================================

services:
  # ===========================================================================
  # BACKEND API
  # ===========================================================================
  backend:
    image: ${DOCKER_REGISTRY:-72.60.226.4:5000}/trading-platform-backend:${VERSION:-latest}
    container_name: trading-backend
    restart: unless-stopped
    ports:
      - "3081:3081"
    environment:
      - NODE_ENV=production
    env_file:
      - ../apps/backend/.env.production
    volumes:
      - backend-logs:/var/log/trading-platform
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:3081/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 40s
    networks:
      - trading-network
      - isem-network
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 1G
        reservations:
          cpus: '0.5'
          memory: 512M
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

  # ===========================================================================
  # FRONTEND
  # ===========================================================================
  frontend:
    image: ${DOCKER_REGISTRY:-72.60.226.4:5000}/trading-platform-frontend:${VERSION:-latest}
    container_name: trading-frontend
    restart: unless-stopped
    ports:
      - "3080:80"
    depends_on:
      backend:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:80"]
      interval: 30s
      timeout: 10s
      retries: 3
    networks:
      - trading-network
    deploy:
      resources:
        limits:
          cpus: '0.5'
          memory: 256M
    logging:
      driver: "json-file"
      options:
        max-size: "10m"
        max-file: "3"

  # ===========================================================================
  # WEBSOCKET SERVICE
  # ===========================================================================
  websocket:
    image: ${DOCKER_REGISTRY:-72.60.226.4:5000}/trading-platform-backend:${VERSION:-latest}
    container_name: trading-websocket
    restart: unless-stopped
    ports:
      - "3082:3082"
    environment:
      - NODE_ENV=production
      - PORT=3082
      - SERVICE_TYPE=websocket
    env_file:
      - ../apps/backend/.env.production
    depends_on:
      backend:
        condition: service_healthy
    networks:
      - trading-network
      - isem-network
    deploy:
      resources:
        limits:
          cpus: '1'
          memory: 512M

  # ===========================================================================
  # ML ENGINE (Python/FastAPI)
  # ===========================================================================
  ml-engine:
    image: ${DOCKER_REGISTRY:-72.60.226.4:5000}/trading-platform-ml-engine:${VERSION:-latest}
    container_name: trading-ml-engine
    restart: unless-stopped
    ports:
      - "3083:3083"
    environment:
      - ENVIRONMENT=production
    env_file:
      - ../apps/ml-engine/.env.production
    volumes:
      - ml-models:/app/models
    depends_on:
      backend:
        condition: service_healthy
    networks:
      - trading-network
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 2G

  # ===========================================================================
  # DATA SERVICE (Python)
  # ===========================================================================
  data-service:
    image: ${DOCKER_REGISTRY:-72.60.226.4:5000}/trading-platform-data-service:${VERSION:-latest}
    container_name: trading-data-service
    restart: unless-stopped
    ports:
      - "3084:3084"
    environment:
      - ENVIRONMENT=production
    env_file:
      - ../apps/data-service/.env.production
    networks:
      - trading-network
      - isem-network
    deploy:
      resources:
        limits:
          cpus: '1'
          memory: 512M

  # ===========================================================================
  # LLM AGENT (Python/FastAPI)
  # ===========================================================================
  llm-agent:
    image: ${DOCKER_REGISTRY:-72.60.226.4:5000}/trading-platform-llm-agent:${VERSION:-latest}
    container_name: trading-llm-agent
    restart: unless-stopped
    ports:
      - "3085:3085"
    environment:
      - ENVIRONMENT=production
    env_file:
      - ../apps/llm-agent/.env.production
    networks:
      - trading-network
    deploy:
      resources:
        limits:
          cpus: '1'
          memory: 1G

  # ===========================================================================
  # TRADING AGENTS (Python/FastAPI)
  # ===========================================================================
  trading-agents:
    image: ${DOCKER_REGISTRY:-72.60.226.4:5000}/trading-platform-trading-agents:${VERSION:-latest}
    container_name: trading-agents
    restart: unless-stopped
    ports:
      - "3086:3086"
    environment:
      - ENVIRONMENT=production
    env_file:
      - ../apps/trading-agents/.env.production
    networks:
      - trading-network
      - isem-network
    deploy:
      resources:
        limits:
          cpus: '2'
          memory: 1G

# =============================================================================
# VOLUMES
# =============================================================================
volumes:
  backend-logs:
    driver: local
  ml-models:
    driver: local

# =============================================================================
# NETWORKS
# =============================================================================
networks:
  trading-network:
    driver: bridge
  isem-network:
    external: true
    name: isem-network
