UI
The admin UI is a bundled single-page application (SPA). It is built with React, Vite, and Tailwind v4, compiled to dist/ui, and served by the panel handler. Consumers who mount the panel do not install or import React — it is a build-time dependency of the UI package only, never a peer dependency of @xtandard/flags.
Bundled SPA Model
Section titled “Bundled SPA Model”The panel handler serves the admin UI from the dist/ui directory at build time. The SPA is a static bundle:
dist/ui/ index.html ← entry point; receives <base> and bootstrap config at serve time assets/ ← hashed JS/CSS chunksThe handler injects two things into index.html before serving it:
<base href="/{basePath}/">— resolves all relative asset URLs under the mount path.<script>window.__FLAGS_CONFIG__ = { title, basePath, readonly, defaultProjectKey, defaultEnvironmentKey }</script>— bootstrap config read by the SPA on startup.
The /config API endpoint returns the same object for dynamic runtime use.
Served Routes
Section titled “Served Routes”The panel handler (createFetchHandler) dispatches in this order:
- Healthcheck —
GET /healthcheck(under the base path) answers{ "ok": true }. - JSON API — paths matching
/api/*or/config. Any other method thanGET/HEADoutside the API is a405withAllow. - Static assets — paths ending in a file extension that exist under
dist/ui. - 404 — a path that looks like a static asset (
/assets/main.abc123.js) but is not found. - SPA fallback — everything else (including
/,/flags/my-flag, etc.) returns the injectedindex.html.
This means the SPA can use client-side routing freely — any unknown path falls through to index.html.
Routing (wouter, pluggable)
Section titled “Routing (wouter, pluggable)”The dashboard routes views and selection via wouter, with a pluggable location strategy (see ADR 0005):
- Bundled SPA → browser-history routing based at
basePath(clean paths like/flags/my-flag); the SPA-catch-all above makes deep links survive refresh. <FlagsDashboard>embed → hash routing by default (#/…) so it never touches the host app’s router. Override with theroutingprop:"hash" | "browser" | "memory"or a custom wouter hook (+routerBase).
Routes: / (+ /flags), /flags/:key (/flags/new = create), /segments(/:key), /snapshots(/:version), /audit. The selected project/environment ride in the query (?project=&env=) and are preserved across navigation; the flags list also persists its filter (?tab=archived) and search (?q=). The “new flag” modal is intentionally ephemeral (the editor itself is the route).
Snapshots: download / import
Section titled “Snapshots: download / import”From /snapshots you can move a version’s configuration in and out as JSON (see ADR 0011):
- Download — the snapshot detail dialog has a Download JSON button (
snapshot-vN.json). The file embeds a"$schema"reference toGET /api/schema.json, so editors like VS Code validate and autocomplete it. - Import — the Import JSON button (header) loads a
{ flags, segments? }document into the draft (replacing it), then routes to Flags so you can review the diff and publish it as a new version. Import does not create a version directly — it reuses the normal draft → diff → publish flow, so an unwanted import is one Discard away. Invalid input is rejected (422) before anything is written; extra fields like$schema/versionare ignored, so a downloaded snapshot re-imports cleanly.
GET /api/schema.json serves a self-contained JSON Schema (2020-12) for import documents, unauthenticated and CORS-open so editors can fetch it from a $schema URL. (Round-trip is functional, not byte-exact: published snapshots inline inSegment segments into flags, so a re-import evaluates identically but won’t restore every original named segment.)
Branding
Section titled “Branding”The navbar is configurable via createFetchHandler({ title, logoUrl }) (or TITLE / LOGO_URL env vars on the standalone, or props on <FlagsDashboard>):
title— wordmark text (default@xtandard/flags), shown when nologoUrlis set.logoUrl— a logo image shown in place of the title wordmark (height-constrained, max-width 320px).
There is no default glyph — the navbar shows the title wordmark, or your logo when logoUrl is set.
One-command demo
Section titled “One-command demo”bun run demo # boots a throwaway in-memory standalone + seeds a full datasetbun run seed:demo # seeds an already-running server ($BASE_URL)Building the UI
Section titled “Building the UI”bun run build:ui# Runs: vite build --config vite.ui.config.tsDuring development:
bun run dev:ui# Runs: vite --config vite.ui.config.ts# Starts Vite dev server for the UI only (not the panel API)The full build (library + UI):
bun run build# Runs: bun run build:lib && bun run build:uibasePath and window.__FLAGS_CONFIG__
Section titled “basePath and window.__FLAGS_CONFIG__”When you mount the panel at a non-root path (e.g., /flags), set basePath: "/flags" in FlagsPanelOptions. The handler:
- Prepends
<base href="/flags/">toindex.html. - Injects
window.__FLAGS_CONFIG__.basePath = "/flags".
The SPA reads window.__FLAGS_CONFIG__ on startup so it can construct correct API URLs and router base paths relative to the mount point.
No React Peer for Consumers
Section titled “No React Peer for Consumers”Mounting the panel does not require React in your project. The SPA is pre-built into dist/ui. The handler serves static files — it has no React dependency.
React is only a dev dependency used to build the UI bundle. If you are building the package from source, react and react-dom are in devDependencies.
Custom UI Directory
Section titled “Custom UI Directory”The default uiDir is resolved relative to the package installation path (./ui beside the built module). You can override it for Docker image path adjustments or to serve a custom-built UI:
import { createFetchHandler } from "@xtandard/flags";
const { fetch, core } = createFetchHandler({ sourceStorage, uiDir: "/app/dist/ui", // absolute path inside the container});The standalone app reads UI_DIR from the environment for the same purpose.
Fallback Page
Section titled “Fallback Page”If the dist/ui directory is absent (e.g., the library was installed but bun run build:ui has not run), the handler serves a minimal fallback HTML page that:
- Displays the configured
title. - Notes that the UI bundle is not built and instructs you to run
bun run build:ui. - Makes clear that the JSON API at
api/is fully available.
This lets the API and CLI work without the UI being built.