version: "3.9"

networks:
  hxki-internal:
    external: true

services:

  # ========== CADDY (Reverse Proxy mit SSL) ==========
  caddy:
    image: caddy:latest
    container_name: hx-caddy
    restart: unless-stopped
    networks:
      - hxki-internal
    ports:
      - "80:80"
      - "443:443"
    volumes:
      - ./caddy/Caddyfile:/etc/caddy/Caddyfile
      - caddy_data:/data
      - caddy_config:/config

  # ========== N8N (Master Instanz) ==========
  hxki-n8n:
    image: docker.n8n.io/n8nio/n8n
    container_name: hxki-n8n
    restart: unless-stopped
    networks:
      - hxki-internal
    environment:
      - N8N_BASIC_AUTH_ACTIVE=false
      - N8N_DIAGNOSTICS_ENABLED=false
      - N8N_HOST=n8n.hx-ki.com
      - N8N_PORT=5678
      - N8N_EDITOR_BASE_URL=https://n8n.hx-ki.com
      - WEBHOOK_URL=https://n8n.hx-ki.com
    volumes:
      - /data/HXKI_WORKSPACE/router:/home/node/.n8n
      - /data/HXKI_WORKSPACE:/data/HXKI_WORKSPACE

  # ========== Grafana ==========
  hxki-grafana:
    image: grafana/grafana:latest
    container_name: hxki-grafana
    restart: unless-stopped
    networks:
      - hxki-internal
    volumes:
      - grafana_data:/var/lib/grafana
      - /opt/hx-ki/monitoring/grafana/provisioning:/etc/grafana/provisioning:ro

  # ========== Postgres ==========
  hxki-postgres:
    image: postgres:15
    container_name: hxki-postgres
    restart: unless-stopped
    environment:
      POSTGRES_PASSWORD: "hxki_password"
    networks:
      - hxki-internal
    volumes:
      - postgres_data:/var/lib/postgresql/data

  # ========== MariaDB ==========
  hxki-mariadb:
    image: mariadb:10.11
    container_name: hxki-mariadb
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: "hxki_password"
    networks:
      - hxki-internal
    volumes:
      - mariadb_data:/var/lib/mysql

  # ========== WebUI ==========
  hxki-web:
    image: node:18
    container_name: hxki-web
    networks:
      - hxki-internal
    command: >
      bash -c "cd /app && npm install && npm run start"
    volumes:
      - ./web:/app

volumes:
  grafana_data:
  postgres_data:
  mariadb_data:
  caddy_data:
  caddy_config:
