ZMB Webui: Complete Project – Rebrand & Initial Clean Commit

ARCHITECTURE
============
Backend: FastAPI + uvicorn (port 8000)
  - JWT authentication with PAM system users
  - ZFS CLI wrapper with caching (30-60s TTL)
  - WebSocket pool status broadcaster (30s interval)
  - Services: auth, zfs_runner, file_manager, shares, identities, system_info
  - Routers: pools, datasets, snapshots, shares, identities, navigator, system

Frontend: Next.js 15 + TypeScript (static export)
  - Incremental Static Regeneration (ISR) for weak hardware
  - Type-safe API client (lib/api.ts)
  - Dark mode + custom Tailwind theme
  - Pages: Dashboard, Login, Snapshots, Datasets, Shares, etc.

DEPLOYMENT
==========
Test Target: 192.168.1.179:8090 (Debian LXC)
Production: 10.66.120.3:9090 (Raspberry Pi 4GB ARM64)
Updater: Automated Gitea-based deployment (update-test.sh, update-pi.sh)

FEATURES COMPLETED
==================
Phase 3a: Dashboard Quick Stats (System, CPU, Memory, Storage)
  - Real-time stats with color-coded progress bars
  - Responsive grid layout (mobile: 1, tablet: 2, desktop: 4 columns)
  - ISR-optimized for fast loads on weak hardware

REBRANDING
==========
Renamed throughout:
  - Project: 'ZFS Manager' → 'ZMB Webui'
  - Services: 'zfs-manager' → 'zmb-webui'
  - Systemd units: zfs-manager-backend → zmb-webui-backend
  - Configuration files and documentation

Co-Authored-By: Patrick <patrick@perlbach24.de>
This commit is contained in:
Claude Code
2026-04-22 00:26:23 +02:00
committed by Patrick
commit 6d74d874b6
104 changed files with 28836 additions and 0 deletions
+65
View File
@@ -0,0 +1,65 @@
"use client"
import { useEffect, useRef, useCallback } from "react"
export type WsMessage = {
type: "pool_status" | "scrub_progress" | "snapshot_created" | "alert"
data: unknown
}
type Handler = (msg: WsMessage) => void
export function useWebSocket(onMessage: Handler) {
const wsRef = useRef<WebSocket | null>(null)
const retryRef = useRef<ReturnType<typeof setTimeout> | null>(null)
const delayRef = useRef(2000)
const handlerRef = useRef(onMessage)
handlerRef.current = onMessage
const connect = useCallback(() => {
if (typeof window === "undefined") return
const token = localStorage.getItem("access_token")
if (!token) return
// Derive WS URL from current page origin
const proto = window.location.protocol === "https:" ? "wss" : "ws"
const wsUrl = `${proto}://${window.location.host}/ws`
const ws = new WebSocket(wsUrl)
wsRef.current = ws
ws.onopen = () => {
delayRef.current = 2000 // Reset backoff on success
}
ws.onmessage = (event) => {
try {
const msg: WsMessage = JSON.parse(event.data)
handlerRef.current(msg)
} catch {
// ignore malformed messages
}
}
ws.onclose = () => {
// Reconnect with exponential backoff (max 30s)
retryRef.current = setTimeout(() => {
delayRef.current = Math.min(delayRef.current * 2, 30000)
connect()
}, delayRef.current)
}
ws.onerror = () => {
ws.close()
}
}, [])
useEffect(() => {
connect()
return () => {
if (retryRef.current) clearTimeout(retryRef.current)
wsRef.current?.close()
}
}, [connect])
}