version: '3.8'

services:
  evolution-api:
    image: atendai/evolution-api:latest
    container_name: evolution-api
    restart: unless-stopped
    networks:
      - traefik-public
      - database-internal
    env_file:
      - .env
    environment:
      DATABASE_PROVIDER: postgresql
      DATABASE_CONNECTION_URI: postgresql://evolution_user:${DB_PASSWORD}@postgres-main:5432/evolution
      AUTHENTICATION_API_KEY: ${API_KEY}
      SERVER_URL: https://wpp.ai-impress.com
    volumes:
      - evolution-data:/evolution/instances
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=traefik-public"
      # API router without Authelia (higher priority)
      - "traefik.http.routers.evolution-api.rule=Host(`wpp.ai-impress.com`) && (PathPrefix(`/instance`) || PathPrefix(`/message`) || PathPrefix(`/chat`) || PathPrefix(`/webhook`) || PathPrefix(`/settings`))"
      - "traefik.http.routers.evolution-api.entrypoints=websecure"
      - "traefik.http.routers.evolution-api.tls.certresolver=cloudflare"
      - "traefik.http.routers.evolution-api.priority=100"
      # Web UI router with Authelia (lower priority)
      - "traefik.http.routers.evolution.rule=Host(`wpp.ai-impress.com`)"
      - "traefik.http.routers.evolution.entrypoints=websecure"
      - "traefik.http.routers.evolution.tls.certresolver=cloudflare"
      - "traefik.http.routers.evolution.middlewares=authelia@file"
      - "traefik.http.routers.evolution.priority=50"
      # Service
      - "traefik.http.services.evolution.loadbalancer.server.port=8080"

volumes:
  evolution-data:

networks:
  traefik-public:
    external: true
  database-internal:
    external: true
