# @strutvane/ui: An Admin Panel That Builds Itself From Your API

Every business app needs an admin panel. Somebody in operations has to look up a customer, fix a typo in an invoice, or find all the orders stuck in "pending".

And almost every admin panel is built the same way: a list page, a detail page, a create form, an edit form, repeated for every table. Add pagination. Add filters. Add a delete button with a "are you sure?" dialog. Hide the edit button for people who can't edit. Make it work on a phone. Make it work with a keyboard. Make it work with a screen reader.

It's a lot of work, and none of it is the interesting part of your product.

`@strutvane/ui` does that work once, for every resource.

---

## What it is

`@strutvane/ui` is the **admin UI behaviour** of Strutvane, an open-source (MIT) TypeScript framework for business (B2B) apps. It's a React package that reads your API's **resource manifest** (a JSON document at `/.well-known/strutvane.json` that describes each resource, its fields and what the current user may do) and draws a list, detail, create and edit page for every resource, plus the sidebar. **Zero per-resource code.**

The key word is *behaviour*. `@strutvane/ui` has **no look of its own**. Every pixel comes from a **design package** you choose, so changing the design changes every screen without touching one.

## Why it exists

Two problems kept coming up.

**The admin drifts away from the backend.** Someone adds a field to a table, and the admin form doesn't show it for weeks. Or the backend tightens a permission, but the admin still shows a "Delete" button that now fails. When the UI is generated from the same manifest the API publishes, it can't drift.

**Behaviour and looks are tangled together.** In most admin kits, if you don't like the look, you rewrite the components, and you lose the behaviour (the keyboard shortcuts, the accessibility, the unsaved-changes guard) along with it. Strutvane splits them on purpose: `@strutvane/ui` owns *what the admin does*, and a design owns *how it looks*.

## What you get

**Navigation**

- A **sidebar** built from the manifest: one entry per resource the viewer may list, grouped and ordered, with badges. On phones it becomes a drawer.
- **Breadcrumbs and a Back button** on every page. Back returns to the list with its page, filters and sort intact (they live in the URL).
- A **command palette** (Ctrl/Cmd+K or `/`) to jump to screens, search records on the server (only what you may see) and run actions.
- **Keyboard shortcuts**: `?` for help, `n` for new, `e` for edit, `g d` for home. Single-key shortcuts never fire while you're typing.

**Lists**

- Server-side filtering, search, sorting and numbered pages ("Showing 26–50 of 312 posts").
- **Filter chips** you can remove one by one, or all at once.
- A **Columns** menu and **compact rows**, remembered per viewer.
- **Delete with confirmation**, and **Undo** after a soft delete.
- New, Edit and Delete buttons appear **only when the manifest allows them**. (The API still enforces every rule; hiding a button is a courtesy, not the security.)

**Forms**

- The right input for each field type: decimals keep exactly what you typed, dates and times show in your time zone, and relations get a searchable, paginated picker.
- Validation on the client from the manifest, and server validation errors land **on the right field**.
- An **unsaved-changes guard**: leaving a changed form asks first.
- One submission at a time, so a double-click never creates two records.
- If your session expires mid-edit, a **"Sign in again" dialog opens over the form and keeps your draft**.

**Safety and accessibility**

- Writes send a CSRF token (a protection against other sites submitting forms on your behalf). Reads are retried on network hiccups; writes never are.
- Errors are never shown raw: you get friendly messages from a catalogue, and a trace reference for server errors.
- A crashing cell or widget is contained to itself, so one bad value doesn't take down the page.
- **WCAG 2.2 AA is release-blocking**: real tables with captions and sort state, labelled landmarks, focus management in dialogs, polite announcements, and automated accessibility checks (axe) in the test suite on every screen.

## Designs: the look is swappable

A design provides light and dark tokens, fonts, the shell (sidebar, top bar, sign-in layout), sixteen component skins, a chart palette and four illustrations. Two official designs exist today:

- **Crisp** (`@strutvane/design-crisp`): the quiet, business-first default.
- **Vivid** (`@strutvane/design-vivid`): colourful, roomier dashboards.

Any design can be rebranded with four public tokens: `--brand-hue`, `--font-sans`, `--radius` and `--density`.

Want to build your own? `@strutvane/ui/testing` ships `designConformance()`, a test kit every design must pass. It checks every slot, **WCAG AA contrast for every token pair in both themes at every brand hue**, no hard-coded colours, no horizontal scrolling at 375 px wide, and zero axe violations on nine reference screens.

## How it fits into Strutvane

`@strutvane/ui` talks to the backend **only over HTTP**:

- **`@strutvane/framework`** publishes the manifest and the CRUD API the screens use.
- **`@strutvane/auth`** provides the session endpoints for sign-in and sign-out (you can switch that off for an API without them).
- A **design package** provides the look.

Add-on packages can add pages to the sidebar too, each shown only when the user has the matching permission.

## A quick look

```bash
npm install @strutvane/ui
```

The whole admin, with the Crisp design and one custom screen of your own:

```tsx
import { StrutvaneApp, type RouteDefinition } from '@strutvane/ui/react'
import { crisp } from '@strutvane/design-crisp'

const routes: RouteDefinition[] = [{ path: '/reports', title: 'Reports', element: <Reports /> }]

export function App() {
  return (
    <StrutvaneApp
      apiUrl="/api"
      appName="Acme"
      design={crisp}
      brand={{ brandHue: 150 }}
      routes={routes}
    />
  )
}
```

Your own routes win over the generated ones, and those with a `title` join the sidebar.

When you need something special, there are **overrides**: a custom cell for one column of one resource, a custom input widget for every field of a type, or your own wording for any message.

`@strutvane/framework` is a required peer dependency (the shared types live there), along with React 19 and TanStack for the React parts.

> ⚠️ This is a **0.2 preview**. The APIs may still change before 1.0, planned for January 2027.

## Built to be trusted

- **499 automated tests**: core logic in Node, React screens in jsdom with Testing Library, user-event and axe-core, and property-based tests (fast-check) for the parsers.
- Coverage minimums of 90% (85% for branches).
- **CI on Linux, Windows and macOS**, on Node 24 and Node 26.
- **Security-reviewed** and secure by default.
- **Every release is staged by CI and approved by a human with two-factor authentication**, and published with **npm provenance**.

---

## Try it, and tell me what you think

- ⭐ **GitHub:** [github.com/vishwajit-vm/strutvane-ui](https://github.com/vishwajit-vm/strutvane-ui)
- 📦 **npm:** [npmjs.com/package/@strutvane/ui](https://www.npmjs.com/package/@strutvane/ui)
- 💬 **Feedback welcome.** What's the one admin-panel feature you always end up building by hand? If it's missing here, I want to know.

Next in the series: the two designs, **Crisp** and **Vivid**. Follow along! 🎨

*— Vishwajit VM*

---

*Part of the Strutvane series. Strutvane™ is open source under the MIT licence.*
