This document provides a comprehensive operational memory, architectural record, and changelog of all work performed on Guardian. Future AI agents and engineers working on this repository should consult this file before making modifications.
Guardian is an ultra-lightweight, self-hosted server & Docker dashboard + app launcher designed to run with minimal CPU and memory overhead on home servers, homelabs, VPSs, Raspberry Pis, and enterprise Linux hosts.
- Backend (
server/): Node.js (v20+ / v22), TypeScript (NodeNext), Express, CORS.- Custom zero-overhead collectors for system telemetry (CPU, Memory, Disk, Network, Processes).
- Docker daemon integration via standard
/var/run/docker.sockUnix socket using direct Docker REST API calls (no heavy CLI wrappers). - Config persistence in JSON (
data/apps.json,data/settings.json).
- Frontend (
client/): React 18, TypeScript, Vite, Tailwind CSS, Lucide icons, glassmorphic dark UI design system. - Packaging (
Dockerfile,docker-compose.yml): Multi-stage Alpine container (node:22-alpine) supporting multi-architecture targets (linux/amd64,linux/arm64/v8). Published to GitHub Container Registry (GHCR):ghcr.io/vineetkishore01/guardian:latest
- Host Metrics Fallback: When running inside a Docker container, host metrics are extracted from mounted
/host/proc,/host/sys, and/host/etc/os-releasepaths configured via environment variables:HOST_PROC=/host/procHOST_SYS=/host/sysHOST_ETC=/host/etc
- Linux Distribution Genericity: Designed and verified to work seamlessly across:
- Debian, Ubuntu, Proxmox VE
- TrueNAS SCALE, Unraid
- Arch Linux, Alpine Linux
- Raspberry Pi OS & ARM64 SBCs
- Mount Propagation: Uses
:ro,rslaveon host mounts (/,/proc,/sys) indocker-compose.yml.exampleto ensure dynamic host mount changes (such as plugging in external storage or new mountpoints) propagate into the container without throwing permission or stale handle errors.
- Communicates directly with
/var/run/docker.sock. - Auto-detects running containers, health status, exposed ports, IP bindings, and resource usage.
- Enables 1-click web launcher mapping: automatically derives external URLs from port bindings or Docker labels (e.g.
guardian.url,traefik.http.routers.*).
- Reads
/procdirectly on Linux hosts or/host/procwhen containerized. - Extracts PID, process name, state, CPU utilization %, and RSS memory usage with zero dependencies.
- Gracefully handles non-Linux host platforms (e.g. Darwin/macOS local dev) by falling back to standard Node child process calls.
- Configurable URL pinging for external / LAN services with latency tracking and status badge indication.
- Queries hardware drives using
smartctl(smartmontoolsinstalled in runner image) with fallback to/sys/blockand hwmon. - Discovers physical block devices (
sd*,nvme*n*,vd*), models, vendors, serial numbers, firmware, and form factors. - Monitors overall SMART health (
passed,warning,failing), temperatures, power-on hours, power cycles, and rotational speed (or SSD indication). - Extracts critical homelab drive failure signals: reallocated sectors (ID 5), pending sectors (ID 197), uncorrectable sectors (ID 198), UDMA CRC cable errors (ID 199), and NVMe media errors/critical warnings.
- Tracks SSD/NVMe wearout % and endurance (TBW/TBR).
- Maps physical drive partitions directly to filesystem mountpoints.
- Caches measurements with a 60-second TTL to avoid spinning up sleeping disks, with a manual refresh trigger (
POST /api/disks/smart/refresh). - Falls back to realistic sample disks when off-host.
- Measures continuous operation down to the second with a live ticking counter.
- Extracts boot time from
/proc/stat(btime) or/proc/uptime. - Analyzes lifetime CPU efficiency by computing idle vs active time since boot from
/proc/uptime. - Evaluates system stability status (
fresh_boot,stable,long_runningfor 30d+ streaks) and load profile vs thread capacity.
- Contains only the application source code, configs, and container definitions:
server/: Backend TypeScript code.client/: Frontend React application.Dockerfile: Multi-stage build for application images.docker-compose.yml: Local production testing.docker-compose.yml.example: User-facing deployment template.README.md: Project documentation.
- Website Code Protection:
- The showcase landing page code is explicitly excluded from
mainso that anyone cloning the public repo receives a clean, focused application codebase. .gitignoreincludes:# Website code lives on gh-pages branch only docs/*.html docs/*.css docs/*.js
- The showcase landing page code is explicitly excluded from
- An isolated branch dedicated strictly to the public showcase landing page served at:
- Live URL:
https://vineetkishore01.github.io/Guardian/
- Live URL:
- Contains:
index.html: Hero section, feature breakdown, live interactive installer, telemetry simulator, and screenshot gallery.styles.css: Custom vanilla CSS with glassmorphic cards, radiant purple/cyan gradients, and responsive layouts.app.js: Tab switching logic, copy-to-clipboard for the 1-line install command, animated telemetry preview, and Cloudflare visit tracking beacon.- 5 Retina high-resolution screenshots highlighting the real application UI.
To monitor traffic and virality on the public showcase website without heavy third-party trackers (like Google Analytics), a custom serverless Cloudflare Worker with KV storage was built and deployed.
- Worker Name:
guardian-counterstill-sun-e8de - Public URL:
https://guardian-counterstill-sun-e8de.vineetkishore01.workers.dev - KV Namespace:
guardian_stats(dfe569263e6142f4a944fb48c339ba30) - Cloudflare Account: Configured and deployed using user's logged-in session via
ego-browser.
- Hit Beacon (
GET /hit?vid=...):- Client-Side Shielding (
app.jsongh-pages):- Automation & WebDriver check (
navigator.webdriver,__nightmare,_phantom,__selenium_unwrapped). - Headless screen / language anomaly filters.
- User-Agent crawler regex filter (Googlebot, Bingbot, Baiduspider, Ahrefs, Semrush, ByteSpider, Censys, Shodan, WhatsApp, Telegram, Applebot, Discord, etc.).
- Session deduplication (
sessionStorage.getItem('guardian_visited_session')) to eliminate page refresh inflation. - Persistent anonymous device UUID (
localStorage.getItem('guardian_visitor_id')) ensuring 1 device = 1 unique visitor across network changes (Wi-Fi, 5G, iCloud Private Relay). - Human interaction / active dwell verification (requires scroll, click, mousemove, keypress, or 3.5s of visible reading before firing).
- Automation & WebDriver check (
- Server Edge Processing:
- Computes unique visitor status using client UUID (
vid_<vid>) or IP fallback. - Enforces
totalVisits = Math.max(totalVisits, todayVisits)to eliminate distributed KV counter drift.
- Computes unique visitor status using client UUID (
- Client-Side Shielding (
- Executive Dashboard (
GET /):- Access directly in a browser:
https://guardian-counterstill-sun-e8de.vineetkishore01.workers.dev/ - Returns a real-time dark-mode HTML dashboard displaying:
- Total Pageviews
- Unique Visitors
- Today's Visits
- Active Bot Shields badge
- One-click stats reset trigger (
/reset?key=<see Cloudflare Worker env, not committed>)
- Access directly in a browser:
# Root dependencies (concurrently dev runner)
npm install
# Server dependencies (Express, TypeScript, @types/node)
cd server && npm install
# Client dependencies (React, Vite, Tailwind CSS)
cd client && npm installAlways ensure both workspaces compile with zero errors:
# Verify backend TypeScript compilation
./server/node_modules/.bin/tsc --project server/tsconfig.json --noEmit
# Verify frontend TypeScript compilation
./client/node_modules/.bin/tsc --project client/tsconfig.json --noEmit# Start both client and server concurrently
npm run dev
# Or start individually:
npm run dev:server # Starts server with tsx watch on :3001
npm run dev:client # Starts Vite dev server on :5173# Builds client into client/dist and server into server/dist
npm run buildcurl -fsSL https://raw.githubusercontent.com/vineetkishore01/Guardian/main/docker-compose.yml.example -o docker-compose.yml && docker compose up -dservices:
guardian:
image: ghcr.io/vineetkishore01/guardian:latest
container_name: guardian
restart: unless-stopped
ports:
- "3000:3000"
environment:
- PORT=3000
- NODE_ENV=production
- HOST_PROC=/host/proc
- HOST_SYS=/host/sys
- HOST_ETC=/host/etc
volumes:
# Docker socket for container control and metrics
- /var/run/docker.sock:/var/run/docker.sock:ro
# Host telemetry filesystem mounts with rslave propagation
- /proc:/host/proc:ro,rslave
- /sys:/host/sys:ro,rslave
- /etc/os-release:/host/etc/os-release:ro
# Persistent storage for custom pinned apps and user settings
- guardian_data:/app/data
volumes:
guardian_data:
driver: local- Keep Website Code Out of
main: Never commit HTML/CSS/JS files intended for the showcase site tomain. If making updates to the showcase website, checkout or work ongh-pagesbranch, commit, push toorigin gh-pages, and switch back tomain. - Never Break Linux Distro Genericity:
When updating collectors in
server/src/collectors/, always respect theHOST_PROC,HOST_SYS, andHOST_ETCenvironment variables and check for file existence before reading paths. Avoid distro-specific assumptions. - Preserve Type Declarations:
Ensure
server/package.jsoncontains@types/nodeand that./server/node_modules/.bin/tsc --noEmitexits with 0 before completing any backend modifications. - Cloudflare Worker Updates:
The worker script source is maintained in the Cloudflare Dashboard under
guardian-counterstill-sun-e8de. If modifications are needed, test changes usingego-browseror the Cloudflare API. - Host-Network and Namespace-Guest Port Discovery:
Docker daemon's
/containers/jsonreturnsPorts: []for any container usingnetwork_mode: hostornetwork_mode: container:<parent>.fetchContainerDetailextractsraw.Config?.ExposedPorts.- For
network_mode: host:publicPortis mapped directly toprivatePort(0.0.0.0) since the container listens directly on host interfaces. - For
network_mode: container:<parent>: Guest exposed ports are matched against parent published ports. buildProbeTargetsfilters out non-HTTP ports (e.g. DNS 53, RTSP 8554, MQTT 1883, HAP 51826) and prioritizes explicitcustomUrlto avoid false down alerts.resolveContainerUrlin the frontend client uses intelligent fallback to well-known service ports so all containers get functional launch URLs.
- For