Skip to content

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.


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 chunks

The handler injects two things into index.html before serving it:

  1. <base href="/{basePath}/"> — resolves all relative asset URLs under the mount path.
  2. <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.


The panel handler (createFetchHandler) dispatches in this order:

  1. Healthcheck — GET /healthcheck (under the base path) answers { "ok": true }.
  2. JSON API — paths matching /api/* or /config. Any other method than GET/HEAD outside the API is a 405 with Allow.
  3. Static assets — paths ending in a file extension that exist under dist/ui.
  4. 404 — a path that looks like a static asset (/assets/main.abc123.js) but is not found.
  5. SPA fallback — everything else (including /, /flags/my-flag, etc.) returns the injected index.html.

This means the SPA can use client-side routing freely — any unknown path falls through to index.html.


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 the routing prop: "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).

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 to GET /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/version are 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.)

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 no logoUrl is 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.

Terminal window
bun run demo # boots a throwaway in-memory standalone + seeds a full dataset
bun run seed:demo # seeds an already-running server ($BASE_URL)

dist/ui/
bun run build:ui
# Runs: vite build --config vite.ui.config.ts

During development:

Terminal window
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):

Terminal window
bun run build
# Runs: bun run build:lib && bun run build:ui

When you mount the panel at a non-root path (e.g., /flags), set basePath: "/flags" in FlagsPanelOptions. The handler:

  1. Prepends <base href="/flags/"> to index.html.
  2. 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.


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.


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.


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.