{meta.label}
{meta.role}
Health payload
{pretty(health.body)}
import { useCallback, useEffect, useMemo, useState } from "react"; const runtime = typeof window !== "undefined" && window.__ENV__ ? window.__ENV__ : {}; const configured = { auth: runtime.AUTH_API || import.meta.env.VITE_AUTH_API || "", employee: runtime.EMPLOYEE_API || import.meta.env.VITE_EMPLOYEE_API || "", transit: runtime.TRANSIT_API || import.meta.env.VITE_TRANSIT_API || "", errors: runtime.ERROR_LOG_API || import.meta.env.VITE_ERROR_LOG_API || "", }; const serviceMeta = { auth: { label: "Auth API", role: "Identity & tokens", color: "amber", data: "Login, JWT sessions, current user profile", routes: ["/login", "/me", "/health"], docs: "https://github.com/your-org/auth_api/blob/main/README.md", }, employee: { label: "Employee API", role: "People operations", color: "teal", data: "Employee onboarding and employee records", routes: ["/health", "/createemployee"], docs: "https://github.com/your-org/employee_api/blob/main/README.md", }, transit: { label: "Transit API", role: "Routes & schedules", color: "blue", data: "Schedules, routes, GPS, fleet and admin data", routes: [ "/health", "/public/schedules/:scheduleId/progress", "/schedule/daily?date=YYYY-MM-DD", "/admin/stops", ], docs: "https://github.com/your-org/transit_api/blob/main/README.md", }, errors: { label: "Error Log API", role: "Incident archive", color: "coral", data: "Centralized bad requests and service errors", routes: ["/health", "/error_log?limit=100"], docs: "https://github.com/your-org/error_log_api/blob/main/README.md", }, }; const healthPaths = { auth: "/health", employee: "/health", transit: "/health", errors: "/health", }; const testerRoutes = [ { service: "auth", method: "POST", path: "/login", label: "Login (userCode + password)" }, { service: "auth", method: "GET", path: "/me", label: "Current session" }, { service: "employee", method: "GET", path: "/health", label: "Employee health", }, { service: "transit", method: "GET", path: "/health", label: "Transit health", }, { service: "transit", method: "GET", path: "/public/schedules/1/progress", label: "Public schedule progress", }, { service: "transit", method: "GET", path: "/schedule/daily?date=2026-09-20", label: "Driver daily schedule", }, { service: "errors", method: "GET", path: "/error_log?limit=25", label: "Recent error log", }, ]; function pretty(value) { try { return JSON.stringify(value, null, 2); } catch { return String(value); } } function App() { const [urls, setUrls] = useState( () => JSON.parse(localStorage.getItem("transit-monitor-urls") || "null") || configured, ); const [token, setToken] = useState( () => localStorage.getItem("transit-monitor-token") || "", ); const [user, setUser] = useState( () => JSON.parse(localStorage.getItem("transit-monitor-user") || "null"), ); const [health, setHealth] = useState({}); const [history, setHistory] = useState({}); const [errors, setErrors] = useState([]); const [errorState, setErrorState] = useState("idle"); const [interval, setIntervalValue] = useState(30); const [lastRefresh, setLastRefresh] = useState(null); const [activeView, setActiveView] = useState("overview"); const [tester, setTester] = useState({ service: "transit", method: "GET", path: "/health", body: "", }); const [testerResult, setTesterResult] = useState(null); const [busy, setBusy] = useState(false); const [loginLoading, setLoginLoading] = useState(false); const [loginError, setLoginError] = useState(""); const login = useCallback(async (userCode, password) => { const url = urls.auth; if (!url) { setLoginError("Auth API URL not configured"); return; } setLoginLoading(true); setLoginError(""); try { const response = await fetch(`${url}/login`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ userCode, password }), }); const data = await response.json(); if (!response.ok) { throw new Error(data.error || `HTTP ${response.status}`); } setToken(data.token); setUser(data.user); localStorage.setItem("transit-monitor-token", data.token); localStorage.setItem("transit-monitor-user", JSON.stringify(data.user)); setLoginError(""); } catch (error) { setLoginError(error.message); } finally { setLoginLoading(false); } }, [urls.auth]); const logout = useCallback(() => { setToken(""); setUser(null); localStorage.removeItem("transit-monitor-token"); localStorage.removeItem("transit-monitor-user"); }, []); const checkService = useCallback( async (key) => { const started = performance.now(); const url = urls[key]; if (!url) { return { ok: false, status: 0, body: { error: "No URL configured" }, latency: 0, checkedAt: new Date().toISOString(), }; } const headers = token ? { Authorization: `Bearer ${token}` } : {}; try { const response = await fetch(`${url}${healthPaths[key]}`, { headers, }); const body = await response.json().catch(() => null); return { ok: response.ok, status: response.status, body, latency: Math.round(performance.now() - started), checkedAt: new Date().toISOString(), }; } catch (error) { return { ok: false, status: 0, body: { error: error.message }, latency: Math.round(performance.now() - started), checkedAt: new Date().toISOString(), }; } }, [token, urls], ); const refreshHealth = useCallback(async () => { const results = await Promise.all( Object.keys(serviceMeta).map(async (key) => [ key, await checkService(key), ]), ); const next = Object.fromEntries(results); setHealth(next); setHistory((current) => Object.fromEntries( Object.entries(next).map(([key, value]) => [ key, [...(current[key] || []), value.latency].slice(-18), ]), ), ); setLastRefresh(new Date()); }, [checkService]); const loadErrors = useCallback(async () => { if (!token) { setErrors([]); setErrorState("missing-token"); return; } setErrorState("loading"); try { const response = await fetch(`${urls.errors}/error_log?limit=80`, { headers: { Authorization: `Bearer ${token}` }, }); const body = await response.json(); if (!response.ok) throw new Error(body.error || `HTTP ${response.status}`); setErrors(body.errors || []); setErrorState("ready"); } catch (error) { setErrorState(error.message); } }, [token, urls.errors]); useEffect(() => { refreshHealth(); const timer = setInterval(refreshHealth, interval * 1000); return () => clearInterval(timer); }, [refreshHealth, interval]); useEffect(() => { if (activeView === "incidents") loadErrors(); }, [activeView, loadErrors]); const saveSettings = (nextUrls, nextToken) => { setUrls(nextUrls); setToken(nextToken); localStorage.setItem("transit-monitor-urls", JSON.stringify(nextUrls)); localStorage.setItem("transit-monitor-token", nextToken); }; const runRequest = async () => { const route = testerRoutes.find( (item) => item.service === tester.service && item.method === tester.method && item.path === tester.path, ); const isMutation = tester.method !== "GET"; if ( isMutation && !window.confirm("This request can change data. Continue?") ) return; setBusy(true); setTesterResult(null); const started = performance.now(); try { const response = await fetch(`${urls[tester.service]}${tester.path}`, { method: tester.method, headers: { ...(token ? { Authorization: `Bearer ${token}` } : {}), ...(tester.body ? { "Content-Type": "application/json" } : {}), }, body: tester.body || undefined, }); const text = await response.text(); let body; try { body = JSON.parse(text); } catch { body = text; } setTesterResult({ ok: response.ok, status: response.status, latency: Math.round(performance.now() - started), body, label: route?.label, }); } catch (error) { setTesterResult({ ok: false, status: 0, latency: Math.round(performance.now() - started), body: { error: error.message }, }); } finally { setBusy(false); } }; const healthyCount = Object.values(health).filter((item) => item.ok).length; const configuredCount = Object.keys(serviceMeta).length; const avgLatency = Math.round( Object.values(health).reduce((sum, item) => sum + (item.latency || 0), 0) / Math.max(Object.keys(health).length, 1), ); return (
SYSTEM PULSE /{" "} {lastRefresh ? lastRefresh.toLocaleTimeString() : "CONNECTING"}
A live field view across the APIs that keep XTransit running.
DATA MAP
{meta.role}
{pretty(health.body)}
OPERATOR NOTES
SERVICE DOCUMENTATION
{meta.role}
{meta.data}
{route}ENDPOINT ATLAS
{meta.data}
{route}
))}
CENTRAL ERROR LOG
CONTROLLED EXECUTION
Requests go directly from this browser to the configured service. Write routes require a confirmation.
RESPONSE
{pretty(result.body)}
) : (
RUNTIME CONFIGURATION
Point the dashboard at local Docker ports or deployed domains. Nothing here is sent anywhere except the service you choose to call.
RUNTIME CONFIGURATION
Point the dashboard at local Docker ports or deployed domains. Nothing here is sent anywhere except the service you choose to call.
User Code: {user?.userCode}
Role: {user?.job}
Admin: {user?.isAdmin ? "Yes" : "No"}