services:
  notifiq:
    image: libreitbe/notifiq-app:latest
    ports:
      - "80:8080"
    volumes:
      - notifiq_data:/app/data
    restart: unless-stopped
    environment:
      # Use .env file (see .env.example)
      - NODE_ENV=${NODE_ENV}
      - DATABASE_URL=postgresql://notifiq:${POSTGRES_PASSWORD}@postgres:5432/notifiq
      - ENCRYPTION_KEY=${ENCRYPTION_KEY}
      - NOTIFIQ_SESSION_SECRET=${NOTIFIQ_SESSION_SECRET}
      - REDIS_HOST=redis
      - REDIS_PORT=6379
      - APP_URL=${APP_URL}
      # Disable queue system (fallback to synchronous delivery)
      - DISABLE_QUEUE=${DISABLE_QUEUE}
      # SMTP server settings for system emails
      - SMTP_HOST=${SMTP_HOST}
      - SMTP_PORT=${SMTP_PORT}
      - SMTP_USER=${SMTP_USER}
      - SMTP_PASSWORD=${SMTP_PASSWORD}
      - SMTP_SECURE=${SMTP_SECURE}
      # From address for system emails
      # Supports format: "Display Name <email@domain.com>"
      - SMTP_FROM_ADDRESS=${SMTP_FROM_ADDRESS}
      # HTTP/HTTPS mode (see .env.example)
      - FORCE_HTTP=${FORCE_HTTP}
      - FORCE_HTTPS=${FORCE_HTTPS}
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "node", "-e", "require('http').get('http://localhost:8080/health', (r) => process.exit(r.statusCode === 200 ? 0 : 1))"]
      interval: 30s
      timeout: 3s
      retries: 3
      start_period: 10s

  redis:
    image: redis:7-alpine
    restart: unless-stopped
    volumes:
      - redis_data:/data
    command: redis-server --appendonly yes
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 3s
      retries: 3

  postgres:
    image: postgres:16-alpine
    restart: unless-stopped
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=notifiq
      - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
      - POSTGRES_DB=notifiq
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U notifiq"]
      interval: 10s
      timeout: 5s
      retries: 5

volumes:
  notifiq_data:
  redis_data:
  postgres_data:
