# Local phase-1 stack only. Never reuse guest/guest or this topology as production deployment configuration.
services:
  api-gateway:
    build:
      context: .
      dockerfile: Dockerfile.microservices
      target: api-gateway
    ports:
      - "4000:4000"
    environment:
      NODE_ENV: development
      PORT: 4000
      HOST: 0.0.0.0
      MONGODB_URI: mongodb://mongodb:27017/oudelaa?replicaSet=rs0
      REDIS_ENABLED: "true"
      REDIS_URL: redis://redis:6379
      REDIS_SOCKET_ADAPTER_ENABLED: "true"
      QUEUE_ENABLED: "true"
      RABBITMQ_URL: amqp://guest:guest@rabbitmq:5672
      NOTIFICATION_SERVICE_ENABLED: "true"
      OUTBOX_DISPATCHER_ENABLED: "true"
      JWT_ACCESS_SECRET: ${JWT_ACCESS_SECRET:?Set JWT_ACCESS_SECRET in the selected local env file}
      JWT_REFRESH_SECRET: ${JWT_REFRESH_SECRET:?Set JWT_REFRESH_SECRET in the selected local env file}
      REFRESH_TOKEN_HASH_SECRET: ${REFRESH_TOKEN_HASH_SECRET:-}
      SUPERADMIN_EMAIL: ${SUPERADMIN_EMAIL:?Set SUPERADMIN_EMAIL in the selected local env file}
      SUPERADMIN_ACCESS_SECRET: ${SUPERADMIN_ACCESS_SECRET:?Set SUPERADMIN_ACCESS_SECRET in the selected local env file}
      SUPERADMIN_REFRESH_SECRET: ${SUPERADMIN_REFRESH_SECRET:?Set SUPERADMIN_REFRESH_SECRET in the selected local env file}
      STORAGE_PROVIDER: local
      STORAGE_BASE_PATH: uploads
    depends_on:
      mongodb:
        condition: service_healthy
      redis:
        condition: service_healthy
      rabbitmq:
        condition: service_healthy
      notification-service:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://127.0.0.1:4000/api/v1/health/ready"]
      interval: 10s
      timeout: 5s
      retries: 12
    volumes:
      - gateway_uploads:/app/uploads
    restart: unless-stopped

  notification-service:
    build:
      context: .
      dockerfile: Dockerfile.microservices
      target: notification-service
    ports:
      - "127.0.0.1:4001:4001"
    environment:
      NODE_ENV: development
      NOTIFICATION_SERVICE_PORT: 4001
      NOTIFICATION_MONGODB_URI: mongodb://mongodb:27017/oudelaa?replicaSet=rs0
      RABBITMQ_URL: amqp://guest:guest@rabbitmq:5672
      NOTIFICATION_RMQ_PREFETCH: 10
      MONGODB_AUTO_INDEX: "true"
    depends_on:
      mongodb:
        condition: service_healthy
      rabbitmq:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "wget", "-q", "--spider", "http://127.0.0.1:4001/health/ready"]
      interval: 10s
      timeout: 5s
      retries: 12
    restart: unless-stopped

  rabbitmq:
    image: rabbitmq:3.13-management-alpine
    ports:
      - "127.0.0.1:15672:15672"
    healthcheck:
      test: ["CMD-SHELL", "rabbitmq-diagnostics -q check_running && rabbitmq-diagnostics -q check_port_connectivity"]
      interval: 5s
      timeout: 5s
      retries: 12
    volumes:
      - rabbitmq_data:/var/lib/rabbitmq

  redis:
    image: redis:7-alpine
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 12
    volumes:
      - redis_data:/data

  mongodb:
    image: mongo:8
    command: ["mongod", "--replSet", "rs0", "--bind_ip_all"]
    healthcheck:
      test: ["CMD", "mongosh", "--quiet", "--eval", "try { if (rs.status().ok === 1) quit(0); quit(1) } catch (e) { rs.initiate({_id:'rs0',members:[{_id:0,host:'mongodb:27017'}]}); quit(0) }"]
      interval: 5s
      timeout: 5s
      retries: 12
    volumes:
      - mongodb_data:/data/db

volumes:
  gateway_uploads:
  rabbitmq_data:
  redis_data:
  mongodb_data:
