services:
  auth:
    container_name: auth
    build:
      context: ./auth
      dockerfile: Dockerfile
    restart: unless-stopped
    command: npm run dev
    volumes:
      - ./auth:/app
      - /app/node_modules
    env_file:
      - ./auth/.env
    healthcheck:
      test: ["CMD", "node", "-e", "fetch('http://localhost:3006/health').then(r => r.ok ? process.exit(0) : process.exit(1))"]
      interval: 30s
      timeout: 5s
      retries: 3
    networks:
      - meb-public
      - meb-private
    ports:
      - "3006:3006"
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.auth.rule=Host(`auth.${DOMAIN:-mebboat.it}`)"
      - "traefik.http.routers.auth.entrypoints=websecure"
      - "traefik.http.services.auth.loadbalancer.server.port=3006"
      - "traefik.docker.network=meb-public"

  api:
    container_name: api-services
    build:
      context: ./api
      dockerfile: Dockerfile
    restart: unless-stopped
    command: npm run dev
    volumes:
      - ./api/src:/app/src
      - ./ml:/ml-source
      - /var/run/docker.sock:/var/run/docker.sock
    env_file:
      - ./api/.env
    networks:
      - meb-public
      - meb-private
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.api.rule=Host(`api.${DOMAIN:-mebboat.it}`)"
      - "traefik.http.routers.api.entrypoints=websecure"
      - "traefik.http.services.api.loadbalancer.server.port=3003"
      - "traefik.http.routers.api.tls.certresolver=letsencrypt"
      - "traefik.docker.network=meb-public"

  console:
    build:
      context: ./console
      dockerfile: Dockerfile
    restart: unless-stopped
    command: npm run dev
    volumes:
      - ./console:/app
      - /app/node_modules
    env_file:
      - ./console/.env
    networks:
      - meb-public
      - meb-private
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.console.rule=Host(`console.${DOMAIN:-mebboat.it}`)"
      - "traefik.http.routers.console.entrypoints=websecure"
      - "traefik.http.services.console.loadbalancer.server.port=3004"
      - "traefik.http.routers.console.tls.certresolver=letsencrypt"
      - "traefik.docker.network=meb-public"

  realtime:
    build:
      context: ./realtime
      dockerfile: Dockerfile
    restart: unless-stopped
    command: npm run dev
    volumes:
      - ./realtime:/app
      - /app/node_modules
    env_file:
      - ./realtime/.env
    networks:
      - meb-private
      - meb-public
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.realtime.rule=Host(`realtime.${DOMAIN:-mebboat.it}`)"
      - "traefik.http.routers.realtime.entrypoints=websecure"
      - "traefik.http.services.realtime.loadbalancer.server.port=3000"
      - "traefik.http.routers.realtime.tls.certresolver=letsencrypt"
      - "traefik.docker.network=meb-public"

      - "traefik.http.services.realtime.loadbalancer.sticky.cookie=true"
      - "traefik.http.services.realtime.loadbalancer.sticky.cookie.name=realtime-ws"
      - "traefik.http.services.realtime.loadbalancer.sticky.cookie.secure=true"

  ml:
    container_name: ml-service
    build:
      context: ./ml
      dockerfile: Dockerfile
    restart: unless-stopped
    volumes:
      - ./ml:/app
    env_file:
      - ./ml/.env
    networks:
      - meb-private
      - meb-public
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.ml.rule=Host(`ml.${DOMAIN:-mebboat.it}`)"
      - "traefik.http.routers.ml.entrypoints=websecure"
      - "traefik.http.services.ml.loadbalancer.server.port=8000"
      - "traefik.http.routers.ml.tls.certresolver=letsencrypt"
      - "traefik.docker.network=meb-public"

#   marine:
#     container_name: marine-service
#     build:
#       context: ./marine
#       dockerfile: Dockerfile
#     restart: unless-stopped
#     volumes:
#       - ./marine:/app
#     env_file:
#       - ./marine/.env
#     environment:
#       - REDIS_HOST=meb-redis
#       - REDIS_PORT=6379
#     networks:
#       - meb-proxy-net
#       - meb-internal
#     labels:
#       - "traefik.enable=true"
#       - "traefik.http.routers.marine.rule=Host(`api.${DOMAIN:-mebboat.it}`) && PathPrefix(`/marine`)"
#       - "traefik.http.routers.marine.entrypoints=web"
#       - "traefik.http.services.marine.loadbalancer.server.port=8001"
#       - "traefik.docker.network=meb-proxy-net"
#       - "traefik.http.middlewares.marine-strip.stripprefix.prefixes=/marine"
#       - "traefik.http.routers.marine.middlewares=marine-strip"

#   circuits:
#     container_name: meb-circuits
#     build:
#       context: ./circuits
#       dockerfile: Dockerfile
#     restart: unless-stopped
#     environment:
#       - DATABASE_URL=postgresql://meb:meb@meb-postgres:5432/circuits
#       - AUTH_SERVICE_URL=http://auth:3001
#       - AUTH_URL=http://auth.${DOMAIN:-localhost}
#       - API_URL=http://api.${DOMAIN:-localhost}
#       - NODE_ENV=${NODE_ENV:-development}
#     volumes:
#       - ./circuits/src:/app/src
#       - /app/node_modules
#     healthcheck:
#       test: ["CMD", "node", "-e", "fetch('http://localhost:3005/health').then(r => r.ok ? process.exit(0) : process.exit(1))"]
#       interval: 30s
#       timeout: 5s
#       retries: 3
#     depends_on:
#       - auth
#     networks:
#       - meb-proxy-net
#       - meb-internal
#     labels:
#       - "traefik.enable=true"
#       - "traefik.http.routers.circuits.rule=Host(`circuits.${DOMAIN:-mebboat.it}`)"
#       - "traefik.http.routers.circuits.entrypoints=web"
#       - "traefik.http.services.circuits.loadbalancer.server.port=3005"
#       - "traefik.docker.network=meb-proxy-net"
#       - "traefik.http.routers.circuits.middlewares=cors-ignore"

networks:
  meb-public:
    external: true
  meb-private:
    external: true
