services:
  # Backend service (API and core logic)
  nofx:
    build:
      context: .
      dockerfile: ./docker/Dockerfile.backend
      args:
        - GO_VERSION=${GO_VERSION:-1.22-alpine}
        - ALPINE_VERSION=${ALPINE_VERSION:-3.19}
        - TA_LIB_VERSION=${TA_LIB_VERSION:-0.4.0}
    container_name: nofx-trading
    restart: unless-stopped
    ports:
      - "${NOFX_BACKEND_PORT:-8080}:8080"
    volumes:
      - ./config.json:/app/config.json:ro
      - ./config.db:/app/config.db
      - ./beta_codes.txt:/app/beta_codes.txt:ro
      - ./decision_logs:/app/decision_logs
      - ./prompts:/app/prompts
      - /etc/localtime:/etc/localtime:ro  # Sync host time
    environment:
      - TZ=${NOFX_TIMEZONE:-Asia/Shanghai}  # Set timezone
      - NOFX_ENV=${NOFX_ENV:-production}
      - LOG_LEVEL=${LOG_LEVEL:-info}
      - HTTP_PORT=8080
    networks:
      - nofx-network
    healthcheck:
      test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:8080/api/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 60s

  # Frontend service (static serving and proxy)
  nofx-frontend:
    build:
      context: .
      dockerfile: ./docker/Dockerfile.frontend
      args:
        - NODE_VERSION=${NODE_VERSION:-20-alpine}
        - NGINX_VERSION=${NGINX_VERSION:-alpine}
        - VITE_BASE=${VITE_BASE:-/}
    container_name: nofx-frontend
    restart: unless-stopped
    ports:
      - "${NOFX_FRONTEND_PORT:-3000}:80"
    environment:
      - VITE_BASE=${VITE_BASE:-/}
    networks:
      - nofx-network
    depends_on:
      - nofx
    healthcheck:
      test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost/health"]
      interval: 30s
      timeout: 10s
      retries: 3
      start_period: 5s

networks:
  nofx-network:
    driver: bridge