version: '3.8'

# Build local pour Mac ARM64
services:
  postgres:
    image: postgres:15-alpine
    container_name: xpeditis-postgres-dev
    ports:
      - "5432:5432"
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: xpeditis_dev
      POSTGRES_USER: xpeditis
      POSTGRES_PASSWORD: xpeditis_dev_password
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U xpeditis"]
      interval: 10s
      timeout: 5s
      retries: 5

  redis:
    image: redis:7-alpine
    container_name: xpeditis-redis-dev
    ports:
      - "6379:6379"
    command: redis-server --requirepass xpeditis_redis_password
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5

  minio:
    image: minio/minio:latest
    container_name: xpeditis-minio-dev
    ports:
      - "9000:9000"
      - "9001:9001"
    command: server /data --console-address ":9001"
    volumes:
      - minio_data:/data
    environment:
      MINIO_ROOT_USER: minioadmin
      MINIO_ROOT_PASSWORD: minioadmin

  backend:
    build:
      context: ./apps/backend
      dockerfile: Dockerfile
    container_name: xpeditis-backend-dev
    ports:
      - "4000:4000"
    labels:
      logging: promtail
      logging.service: backend
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    environment:
      NODE_ENV: development
      # Force JSON logs in Docker so Promtail can parse them
      LOG_FORMAT: json
      PORT: 4000
      API_PREFIX: api/v1

      # Database
      DATABASE_HOST: postgres
      DATABASE_PORT: 5432
      DATABASE_USER: xpeditis
      DATABASE_PASSWORD: xpeditis_dev_password
      DATABASE_NAME: xpeditis_dev
      DATABASE_SYNC: false
      DATABASE_LOGGING: true

      # Redis
      REDIS_HOST: redis
      REDIS_PORT: 6379
      REDIS_PASSWORD: xpeditis_redis_password
      REDIS_DB: 0

      # JWT
      JWT_SECRET: dev-secret-jwt-key-for-docker
      JWT_ACCESS_EXPIRATION: 15m
      JWT_REFRESH_EXPIRATION: 7d

      # S3/MinIO
      AWS_S3_ENDPOINT: http://minio:9000
      AWS_REGION: us-east-1
      AWS_ACCESS_KEY_ID: minioadmin
      AWS_SECRET_ACCESS_KEY: minioadmin
      AWS_S3_BUCKET: xpeditis-csv-rates

      # CORS - Allow both localhost (browser) and container network
      CORS_ORIGIN: "http://localhost:3000,http://localhost:4000"

      # Application URL
      APP_URL: http://localhost:3000

      # Security
      BCRYPT_ROUNDS: 10
      SESSION_TIMEOUT_MS: 7200000

      # Rate Limiting
      RATE_LIMIT_TTL: 60
      RATE_LIMIT_MAX: 100

      # SMTP (Brevo)
      SMTP_HOST: smtp-relay.brevo.com
      SMTP_PORT: 587
      SMTP_USER: 9637ef001@smtp-brevo.com
      SMTP_PASS: xsmtpsib-8d965bda028cd63bed868a119f9e0330485204bf9f4e1f92a3a11c8e61000722-xUYUSrGGxhMqlUcu
      SMTP_SECURE: "false"
      SMTP_FROM: noreply@xpeditis.com

  frontend:
    build:
      context: ./apps/frontend
      dockerfile: Dockerfile
      args:
        NEXT_PUBLIC_API_URL: http://localhost:4000
    container_name: xpeditis-frontend-dev
    ports:
      - "3000:3000"
    labels:
      logging: promtail
      logging.service: frontend
    depends_on:
      - backend
    environment:
      NEXT_PUBLIC_API_URL: http://localhost:4000

volumes:
  postgres_data:
  redis_data:
  minio_data:
