nyuchimzizi
Mzizi — an open-architecture project of the Bundu Foundation, operated and developed by Nyuchi. Built on the Five African Minerals palette.
Built by Nyuchi Africav4.0.39
Reactive chaos diagnostics — N8 Assurance (Z-axis/depth). Runs through the entire 3D architecture, able to inject failures at any component on any horizontal layer, through any vertical spine. Two modes: (1) Injection — random error/latency at configurable probability per layer intersection. (2) Reactive — when a real error is caught anywhere in the 3D space, probe adjacent systems for blast radius. The depth dimension that proves X and Y axes work.
View the full component source code below.
"use client"
import * as React from "react"
/* ═══════════════════════════════════════════════════════════════
NYUCHI CHAOS — Layer 5 Resilience
Reactive chaos diagnostics. Runs in production.
Injection mode + Reactive mode.
═══════════════════════════════════════════════════════════════ */
// ── Chaos Configuration ─────────────────────────────────────────
// BACKLINKS: Uses data-portal and data-slot attributes to identify components
// during chaos injection. When injecting an error, Fundi reads the data-portal
// attribute to link the failure back to the design portal documentation.
export interface ChaosConfig {
/** Enable chaos injection (default: false in dev, configurable in prod) */
enabled: boolean
/** Probability of error injection per render (0-1, default: 0.001 = 0.1%) */
errorProbability: number
/** Probability of latency injection per fetch (0-1, default: 0.005 = 0.5%) */
latencyProbability: number
/** Maximum injected latency in ms */
maxLatencyMs: number
/** Layers to target (empty = all) */
targetLayers: number[]
/** Feature flag key for remote control */
featureFlag?: string
}
const DEFAULT_CONFIG: ChaosConfig = {
enabled: false,
errorProbability: 0.001,
latencyProbability: 0.005,
maxLatencyMs: 3000,
targetLayers: [],
}
// ── Injection Mode ──────────────────────────────────────────────
export function shouldInjectError(config: ChaosConfig = DEFAULT_CONFIG): boolean {
if (!config.enabled) return false
return Math.random() < config.errorProbability
}
export function shouldInjectLatency(config: ChaosConfig = DEFAULT_CONFIG): boolean {
if (!config.enabled) return false
return Math.random() < config.latencyProbability
}
export function getInjectedLatency(config: ChaosConfig = DEFAULT_CONFIG): number {
return Math.floor(Math.random() * config.maxLatencyMs)
}
export class ChaosInjectedError extends Error {
constructor(layer: number, component: string) {
super(`[nyuchi:chaos] Injected error in Layer ${layer} component "${component}"`)
this.name = "ChaosInjectedError"
}
}
// ── Reactive Mode — Blast Radius Diagnostics ────────────────────
export interface ProbeResult {
target: string
status: "healthy" | "degraded" | "error" | "timeout"
latencyMs: number
error?: string
}
export interface DiagnosticReport {
timestamp: string
triggerComponent: string
triggerError: string
probes: ProbeResult[]
blastRadius: "isolated" | "partial" | "systemic"
recommendation: string
}
async function probeEndpoint(url: string, label: string, timeoutMs: number = 5000): Promise<ProbeResult> {
const start = performance.now()
try {
const controller = new AbortController()
const timer = setTimeout(() => controller.abort(), timeoutMs)
const res = await fetch(url, { method: "HEAD", signal: controller.signal })
clearTimeout(timer)
const latencyMs = Math.round(performance.now() - start)
return { target: label, status: res.ok ? "healthy" : "degraded", latencyMs }
} catch (e) {
const latencyMs = Math.round(performance.now() - start)
const isTimeout = (e as Error).name === "AbortError"
return { target: label, status: isTimeout ? "timeout" : "error", latencyMs, error: (e as Error).message }
}
}
export async function diagnoseBlastRadius(
triggerComponent: string,
triggerError: Error,
endpoints: { url: string; label: string }[] = [
{ url: "/api/health", label: "API" },
{ url: "/api/weather?lat=-17.83&lon=31.05", label: "Weather API" },
]
): Promise<DiagnosticReport> {
const probes = await Promise.all(endpoints.map((e) => probeEndpoint(e.url, e.label)))
const errorCount = probes.filter((p) => p.status === "error" || p.status === "timeout").length
const blastRadius: DiagnosticReport["blastRadius"] =
errorCount === 0 ? "isolated" : errorCount < probes.length / 2 ? "partial" : "systemic"
const recommendation =
blastRadius === "isolated" ? "Component-level issue. Retry should resolve." :
blastRadius === "partial" ? "Multiple services affected. Check infrastructure." :
"Systemic outage. Activate incident response."
const report: DiagnosticReport = {
timestamp: new Date().toISOString(),
triggerComponent,
triggerError: triggerError.message,
probes,
blastRadius,
recommendation,
}
// Log structured diagnostic report
console.warn("[nyuchi:chaos] Diagnostic report:", JSON.stringify(report, null, 2))
return report
}
// ── React Integration ───────────────────────────────────────────
const ChaosContext = React.createContext<ChaosConfig>(DEFAULT_CONFIG)
export function ChaosProvider({ config, children }: { config?: Partial<ChaosConfig>; children: React.ReactNode }) {
const merged = React.useMemo(() => ({ ...DEFAULT_CONFIG, ...config }), [config])
return <ChaosContext.Provider value={merged}>{children}</ChaosContext.Provider>
}
export function useChaos(): ChaosConfig {
return React.useContext(ChaosContext)
}
/**
* Hook for reactive chaos diagnostics.
* Call diagnose() when an error boundary catches an error.
* Returns the latest diagnostic report.
*/
export function useChaosDiagnostics() {
const [report, setReport] = React.useState<DiagnosticReport | null>(null)
const [diagnosing, setDiagnosing] = React.useState(false)
const diagnose = React.useCallback(async (component: string, error: Error) => {
setDiagnosing(true)
try {
const r = await diagnoseBlastRadius(component, error)
setReport(r)
} finally {
setDiagnosing(false)
}
}, [])
return { report, diagnosing, diagnose }
}
export type { ChaosConfig, ProbeResult, DiagnosticReport }
npx shadcn@latest add https://mzizi.dev/api/v1/ui/mzizi-chaosFetch this component's metadata and source code from the registry API.
/api/v1/ui/mzizi-chaos