services:
  jellyfin:
    image: jellyfin/jellyfin:latest
    container_name: jellyfin
    restart: unless-stopped
    group_add:
      - "993"  # render group for VAAPI hardware acceleration
    
    ports:
      - "8096:8096"      # HTTP web UI
      - "8920:8920"      # HTTPS
      - "7359:7359/udp"  # Network discovery
      - "1900:1900/udp"  # DLNA
      
    expose:
      - "8096"
    
    environment:
      - PUID=1000
      - PGID=1000
      - TZ=Australia/Perth
    
    volumes:
      # Config on NVMe (fast)
      - ./config:/config
      - ./cache:/cache
      
      # Media libraries (read-only for safety)
      - "/mnt/media/Movies:/media/movies:ro"
      - "/mnt/media/TV Shows:/media/tv-shows:ro"
      - "/mnt/media/Anime:/media/anime:ro"
      - "/mnt/media/Kids TV:/media/kids-tv:ro"
      - "/mnt/media/Kids Movies:/media/kids-movies:ro"
      - "/tank/home-videos:/media/home-videos:ro"
      - "/tank/videos:/media/home-videos:ro"
      - "/tank/photos:/media/home-photos:ro"
    
    devices:
      # Hardware transcoding (Vega graphics)
      - /dev/dri:/dev/dri
    
    networks:
      - jellyfin-net

  qbittorrent:
      image: linuxserver/qbittorrent:latest
      container_name: qbittorrent
      environment:
        PUID: 1000
        PGID: 1000
        TZ: "${TZ}"
        WEBUI_PORT: 8090
      volumes:
        - ~/.docker_volumes/qbittorrent/config:/config
        - /mnt/media/downloads:/downloads
        - /mnt/media/anime:/animeq
      ports:
        - "8090:8090"
        - "6881:6881"
        - "6881:6881/udp"
      expose:
        - "8090"
      restart: unless-stopped
      deploy:
        resources:
          limits:
            memory: 1G
      logging:
        driver: json-file
        options:
          max-size: "10m"
          max-file: "3"

  sonarr:
      image: linuxserver/sonarr:latest
      container_name: sonarr
      environment:
        PUID: 1000
        PGID: 1000
        TZ: "${TZ}"
        DOCKER_MODS: "linuxserver/mods:universal-package-install"
        INSTALL_PACKAGES: "ffmpeg"
      volumes:
        - ~/.docker_volumes/sonarr/config:/config
        - /mnt/media/Anime:/tv
        - ~/media/downloads:/downloads
      ports:
        - "8989:8989"
      expose:
        - "8989"
      restart: unless-stopped
      depends_on:
        - qbittorrent
      deploy:
        resources:
          limits:
            memory: 512M
      logging:
        driver: json-file
        options:
          max-size: "10m"
          max-file: "3"

  prowlarr:
      image: linuxserver/prowlarr:latest
      container_name: prowlarr
      environment:
        PUID: 1000
        PGID: 1000
        TZ: "${TZ}"
      volumes:
        - ~/.docker_volumes/prowlarr/config:/config
      ports:
        - "9696:9696"
      expose:
        - "9696"
      restart: unless-stopped
      depends_on:
        - qbittorrent
        - sonarr
      healthcheck:
        test: ["CMD", "curl", "-f", "http://localhost:9696/ping"]
        interval: 30s
        timeout: 5s
        retries: 3
        start_period: 30s
      deploy:
        resources:
          limits:
            memory: 512M
      logging:
        driver: json-file
        options:
          max-size: "10m"
          max-file: "3"

  jellyseerr:
      image: fallenbagel/jellyseerr:latest
      container_name: jellyseerr
      environment:
        PUID: 1000
        PGID: 1000
        TZ: "${TZ}"
      volumes:
        - ~/.docker_volumes/jellyseerr/config:/app/config
      ports:
        - "5055:5055"
      expose:
        - "5055"
      restart: unless-stopped
      depends_on:
        - jellyfin
        - sonarr
      healthcheck:
        test: ["CMD", "wget", "--no-verbose", "--tries=1", "--spider", "http://localhost:5055/api/v1/status"]
        interval: 30s
        timeout: 5s
        retries: 3
        start_period: 30s
      deploy:
        resources:
          limits:
            memory: 512M
      logging:
        driver: json-file
        options:
          max-size: "10m"
          max-file: "3"
  caddy:
    image: caddy:latest
    container_name: caddy
    restart: unless-stopped
    ports:
      - "443:443"
      - "443:443/udp" # For HTTP/3 support
    volumes:
      - ./Caddyfile:/etc/caddy/Caddyfile
      - ./caddy_data:/data
      - ./caddy_config:/config
    networks:
      - jellyfin-net

  crowdsec:
    image: crowdsecurity/crowdsec:latest
    container_name: crowdsec
    restart: unless-stopped
    environment:
      - COLLECTIONS=crowdsecurity/linux crowdsecurity/caddy crowdsecurity/base-httping
    volumes:
      - /var/log:/var/log:ro
      - ./crowdsec_data:/var/lib/crowdsec/data
      - ./crowdsec_config:/etc/crowdsec
    networks:
      - jellyfin-net

networks:
  jellyfin-net:
    driver: bridge
