Holotable is a natural-language dashboard builder for monitoring data. People describe a dashboard; a model writes a validated spec (never the data); the server runs the spec's guarded queries against TimescaleDB/PostgreSQL or Prometheus and streams the results.
This file is the rules a change has to follow. What each feature does and why
is on the docs site (docs/src/content/docs/), which is canonical;
CONTRIBUTING.md is the human-facing version of this file, so keep the two in
step. Many rules below are held by a test named beside them: when one fails,
it is telling you the rule.
- The model generates specs, never data. No flow where a model returns metric values, the browser trusts model-produced points, or a chart skips server-side execution.
- The Zod IR (
src/lib/ir.ts) is the one contract between generation, APIs, persistence and rendering. Types are inferred from it; never add a parallel TypeScript shape. - Every query is untrusted, whoever wrote it: SELECT-only, read-only,
allowlisted, row- and time-bounded, through the SQL guard
(
src/lib/sql/safety.ts), the PromQL guard (src/lib/promql/safety.ts) or the LogQL guard (src/lib/logql/safety.ts). Never weaken a guard for convenience. - The server owns time. The IR carries expressions like
now-15m; only the server resolves and enforces windows. - Sources are opaque ids. No connection detail, credential or secret in a spec, a panel or anything sent to the browser.
- Authorization is
can()(src/lib/auth/authorize.ts), from the validated token'sgroupsclaim (or a service-account token's one role). Never from a workspace id in a request; re-authorize the source on every execution, not only at the route.
Exact versions are in package.json. Do not assume older Next or React
behavior: read the installed guides in node_modules/next/dist/docs/ and
follow the patterns already in the repository, especially for Server/Client
Component boundaries, route handlers, streaming and config. App Router only;
"use client" only where hooks, browser APIs or interaction need it.
A client module that pulls in zod or the AI SDK for something a page opens
on demand (a dialog, the dashboard chat) loads through next/dynamic or
import(); test/client-bundle.test.ts holds / (the dashboard list),
/settings and the dashboard view to that.
src/app/routes and pages;src/components/UI, with primitives insrc/components/ui/(reuse before adding);src/lib/domain logic (keep it out of pages, and test it there as functions).test/the Node test runner (*.test.ts;*.test.tsxonly for the rare test that needs a real React unwind, throughtest/support/dom.tsx).e2e/Playwright journeys and axe scans against their own stack. A surface a journey drives is proved there, not mounted again under jsdom, which cannot open a Base UI popup and races a stubbedfetch(#511).docs/the Astro site (its ownpackage.json).deploy/the Helm chart, the quick-start image and the hosted demo (its ownpackage.json, checked by.github/workflows/demo.yml)..claude/skills/holotable/the/holotableskill.test/holotable-skill.test.tsholds its lists of panel kinds, formats and color tokens to the code, so a change to those updates itsreferences/.
Three registries own their kinds. Add a kind by registering it; never
switch on, or compare, a kind outside its registry.
- Panel kinds:
src/lib/panels/registry.ts, one module per kind underkinds/. Its renderer is one line insrc/components/panels/registry.tsand its click mapping one insrc/lib/drilldown-datum.ts; neither compiles without them.panel.queryis optional (a text panel runs none): filter withhasQuery. Read a panel's window and cadence throughpanelTimeRange/panelRefreshMs. A chart kind that needs an ECharts series or component not yet insrc/components/charts/echarts.tsadds one line there: it is the only module that imports ECharts at runtime (test/echarts-runtime.test.ts). - Source kinds:
src/lib/sources/registry.ts(browser half underkinds/, server half underserver/). AsksourceKind()/serverKind(); never importsrc/lib/timescaledb/from a route. Read a query throughisSqlQuery/queryText/queryTimeField, not its fields. Held bytest/source-kinds.test.tsandtest/query-language.test.ts. - Model provider kinds:
src/lib/ai/providers/registry.ts. AskkindOf()/serverProviderKind(); never compareprovideror import an@ai-sdk/*package outsidesrc/lib/ai/providers/. A server half passes its credentials and the vendor's URL to the SDK explicitly, through the fetch the registry picks. Held bytest/provider-kinds.test.ts.
The same idea elsewhere: /settings sections are data in
src/lib/settings.ts (a gated section's page also calls notFound()), and
audit actions are AUDIT_ACTIONS in src/lib/audit.ts, each held to the
route that emits it by test/audit.test.ts. A new mutating route records an
audit event.
An additive, optional field needs nothing special. A change that would make a stored spec fail to parse (a renamed, removed or newly required field, a dropped kind) is breaking:
- bump
SPEC_VERSIONand append an upgrader toUPGRADERSinsrc/lib/ir/upgrade.ts(pure, on plain JSON, importing nothing fromir.ts); - add fixtures of the new version beside the old ones in
test/fixtures/specs/(never edit one;npm run fixture:capturereads one from a live dashboard), and rewrite the snapshots withUPDATE_SNAPSHOTS=1 npm test; - read any spec you did not just build through
StoredDashboard, neverDashboard; - check SQL that reads raw
specjsonb (VERSION_COLUMNSinsrc/lib/db/repo.ts, the source-impact queries), which assumes a top-levelpanelsarray.
The paths in .github/CODEOWNERS (the SQL and PromQL guards, auth/,
secrets/, the IR, time, row scope, variables, the base-URL guard,
metrics-access.ts, the DuckDB path guard) are where a quiet regression is a vulnerability. A
change there needs a test.
- Guards. Run
npm run test:fuzzafter any SQL, PromQL or LogQL guard change. Promote a counterexample intotest/fixtures/sql-fuzz-corpus.ts(orpromql-corpus.ts,logql-corpus.ts) and a named test; never bend the generator around it. - Query rewrites. Row filters and variables work on the parse tree, never a regex, and every rewrite is re-parsed and verified.
- Truncation is said. The row cap keeps the newest rows when the plan
has a time field, and every cut (rows, bytes, points, the browser's
window) travels as the result's
truncatedto a badge on the panel.MAX_WINDOW_POINTSandPROMQL_MAX_POINTSare one point budget and stay equal (test/config.test.ts).buildExecutablePlantakesrowFilteras a required input, bound withrowFilterFor/rowFilterInScope. A variable's value is always a bound parameter, never text. - Model calls. A generation route calls
requireModel(...)before the limits; everystreamObject/streamTextspreads...modelSettings(model)and sets noonErrorof its own (test/ai-invoke.test.ts). A new generation surface usesuseRepairingObject, notuseObject. - Untrusted URLs. A typed model or source URL is fetched only through
the guarded fetch (
src/lib/ai/base-url.ts,src/lib/ai/guarded-fetch.ts), checked at DNS time, with a byte cap on the reply. - Secrets and logs. Credentials are sealed (
src/lib/secrets/seal.ts), never returned, and registered withrememberSecretwhen opened. Write throughlog(src/lib/log.ts), neverconsole; a log line never carries a credential, and SQL and prompts are reduced to digests. - Credentials that are not people. Share links (
hts_) are accepted only by the stream route andsrc/app/embed/(test/share.test.ts); MCP access tokens only by/api/mcp(test/mcp-auth.test.ts); service-account tokens (ht_) are one workspace at viewer or editor, never more.Identity.displayNameandemailnever feed an authorization decision. - The browser sends ids, not statements. Explore and chat send the
question; a stored panel reruns from its stored spec; a stored message
never holds result rows. A schema repair sends only
{ repairOf: id }, the rest comes from the server. A drilldown link names a dashboard by id, resolved and re-checked on the server; the browser builds hrefs only to those. - Workspace scope. Annotations, prompt context and every other workspace-owned row are read and written with the workspace from the record or the path, and every statement filters on it. An example query in a workspace's prompt context passes the guard before it is saved and again before the model sees it.
- Closed by default.
/api/metricsanswers nothing untilMETRICS_TOKENorMETRICS_ALLOWED_CIDRSis set. The realm's refresh token stays sealed on the server; the browser holds only an opaque id scoped to/api/auth. - CSP. An inline
<script>or<style>needs the nonce fromsrc/proxy.ts. Custom visuals (Vega) evaluate throughvega-interpreter, nevernew Function; only the modules listed intest/vega-runtime.test.tsimport Vega.
Keycloak OIDC is the only way a real person signs in. src/app/api/auth/ has
exactly five routes (login, callback, logout, refresh,
backchannel-logout). Never add a development-only path or a seeded user;
make the local Keycloak work instead.
AUTH_MODE=demo is the one exception, for evaluation and the public demo: it
changes minting, never verification, and its guards in validateConfig
(no OIDC_*, no group above editor) stay boot errors. It is not a way to
develop auth code: anything touching src/lib/auth/, sessions or claims runs
against the realm.
Consistent, high-quality UI is a requirement, not polish: a change that works but looks, moves or reads differently from the rest of the app is not done. Before building UI, look at how the nearest existing surface does the same thing and match it.
- Tailwind v4 utilities and the tokens in
src/app/globals.css(surfaces, borders, muted text, the primary accent), composed withcn()fromsrc/lib/utils.ts. No literal colors, no one-off spacing scales, no new fonts. Check every change in both color schemes (and the other themes). A chart's colors are tokens too (--chart-*, the spec's color tokens), read throughChartTheme(src/lib/color/chart-theme.ts);test/color-literals.test.tsholdssrc/free of color literals outsidesrc/lib/color/andglobals.css. - Use the primitives in
src/components/ui/before writing markup:Button/ButtonLink,Input,Textarea,Label,Select,Autocomplete,Checkbox,ChoiceCard(two to five pictured options, one chosen),Menu,Popover,Dialog,ConfirmDialog,Card,Table,Badge,PageHeader,EmptyState,Skeleton,ErrorDisplay,Progress(a bar with theprogressbarrole for work with a known or unknown extent),Logo/Wordmark(the mark, never a stand-in icon). A new kind of control becomes a primitive there, built on Base UI and styled like its neighbors, not a one-off in a feature. - Never a native browser widget where the app has a primitive: no
<select>,<datalist>,window.confirm/alert, or browser-drawn date pickers. The browser draws those in its own style, different in each browser and outside the theme. - Every page renders
PageHeader(title, one sentence on what the page is for, the page's actions) in every state, and has a deliberate empty state (EmptyState), loading state (Skeleton, shaped like what is coming) and error state (ErrorDisplay). A destructive action asks throughConfirmDialogand names what it removes. A button whose own work is running passesbusy, notdisabled: a disabled button drops focus to the page behind it (#540). - Layouts work from phone width up with no sideways scroll; full-width pages use the full width, and text stays at a readable measure.
- Keep presentation separate from domain logic: logic in
src/lib/, tested as functions; components small and composable.
Checked, not hoped for:
- Every text/background token pairing meets WCAG AA in every theme and both color schemes;
test/contrast.test.tsmeasures them (src/lib/color/contrast.ts) and the table indocs/src/content/docs/architecture/accessibility.md. A new pairing goes inCONTRAST_PAIRS. Every theme also clears the quality bar insrc/lib/color/quality.ts(test/theme-quality.test.ts): borders, the focus ring (outline-ring, neveroutline-primary), selection, code colors, and statuses and series distinct under a color-vision deficiency. A new color token goes inTHEME_FILE_TOKENS(src/lib/color/theme-file.ts) too, since an operator'sTHEME_FILE(#508) sets every token and is the only way to add a theme without a pull request; one an older file must load without goes inOPTIONAL_THEME_FILE_TOKENSwith its fallback. A color drawn as an area (an arc, a bar, a tile) isfillHex/fillCss, held to 3:1; as text it istokenHex/tokenCss, held to AA (#641). A status tint istinted bg-tint-<status>/(--tint-<n>), never a barebg-<status>/<n>, and no component asks which theme is on (test/color-literals.test.ts). - A chart goes through
AccessibleChart; a link styled as a button isButtonLink(never<Link><Button>); an icon-only control has anaria-label; anaria-labelon a control that shows text holds that text, word for word and in order (WCAG 2.5.3, checked by axe), with a{" "}between sibling spans so their words stay apart; every input has a label; focus is visible and keyboard order follows the page. - A theme is proven by those unit tests, not the browser.
npm run e2escans every main surface with axe in the default theme's dark and light, and each other theme on one page (the live dashboard) in both schemes (#610); a new page, dialog or menu adds itself to the default theme's scans ine2e/a11y.spec.ts, and a new theme is scanned there by being inPALETTE_INFO.
ECharts, through the existing chart components. Charts merge new data and are
never recreated (FLIP a panel's card, never its chart). Design tokens are
authored in OKLCH and are converted before they reach ECharts, so chart
colors come from the token system too: series from ctx.theme.series (the --chart-* tokens), and
axis text, lines and grid from ctx.theme (useChartTheme, read off the
page), never a literal that suits one color scheme (test/chart-theme.test.ts).
Every kind starts from the one chart style, src/components/charts/style.ts
(shared(theme), the axis, legend, label, fill and corner helpers); no other
chart module sets a borderRadius, fontFamily or fontSize, and a large
area's color goes through soften() (the same test).
Motion is platform-only and gated by the preference in src/lib/motion.ts,
which the root layout resolves onto <html data-motion="reduce|allow">
before first paint (#212). The rules:
- Platform only. View Transitions, the Web Animations API,
@starting-style, and FLIP. No framer-motion, motion, react-spring, auto-animate, or tw-animate-css. - Tokens, not literals. Durations are
duration-(--duration-fast|base|slow)and curves areease-standard/ease-emphasized, all fromglobals.css. Noduration-150, noease-in-out. JS that cannot read a CSS variable usesEASE_EMPHASIZED/DURATION_BASE_MSfromsrc/lib/motion.ts. - Animate
opacityandtransformonly (translate,scale). A position or size change goes through FLIP or a view transition, never a transition ontop,height, ormargin. The one sanctioned height transition is Base UI's Collapsible, which measures the panel into--collapsible-panel-heightfor you (the nav-bar mobile menu). - One switch. Every motion rule keys off
:root[data-motion]; nevermotion-safe:,motion-reduce:, or@media (prefers-reduced-motion)directly, because "Allow" deliberately beats the OS. The global reduce rule inglobals.cssstills CSS; the JS helpers (animateOutinsrc/lib/motion.ts,withViewTransitioninsrc/lib/view-transition.ts) takeenabledfrom!useReducedMotion()in a component orisMotionActive()outside React.view-transition.tsimportsflushSyncand so is client-only;motion.tsis reached by Server Components throughsrc/lib/bootstrap.tsand must stay free of React imports. - Overlays use Base UI's hooks. Enter and exit are
data-starting-style:/data-ending-style:variants on the popup; Base UI keeps the element mounted untiltransitionend, which is why the reduce rule clamps to0.01msrather than0. Something that is not a Base UI popup uses thefade-inutility (enter only, it just unmounts) or, when the exit is worth seeing,src/components/notice.tsxover thenoticeutility, which stays mounted and togglesdata-open. A two-branch render (DashboardChatPanel) runsanimateOutbefore flipping its state. - Scope view-transition names.
withViewTransition(update, enabled, type)putstypeon<html data-vt>for the life of the transition; aview-transition-nameis always written ashtml[data-vt="<type>"] .thing(thehtmltype selector, not:root, so the reduce rule outranks it). Types in use:theme(src/lib/theme-transition.ts, the only way client code changes the theme) andtab(the version history's Changes/Preview tab list;.tab-panelon exactly one element per tab). - Entrances are keyframes.
stagger-in(with--iinline for a list),drop-in(alerts) andpop-in(an icon that swapped because something happened) inglobals.css. Keyframes, not@starting-styletransitions, so they can share an element withtransition-colors;backwardsfill so nothing is held after. No--ion a stream (chat messages): the newest item must not wait behind the others. - Lists FLIP, deletes leave first. A list that reorders, reflows or
filters calls
useFlip(containerRef, enabled)fromsrc/components/use-flip.tsand marks each item withdata-flip-id(FlipGroupwraps a server-rendered list). A delete runsanimateOuton the row before the dispatch orrouter.refresh(), so the others slide into a real gap. Never FLIP the thing under the pointer;DashboardGridtakespinnedIdfor that. - Charts merge, never recreate. FLIP a panel's card, never its chart;
EChart'sResizeObserverpicks up the final size. The fullscreen expand inPanelViewand the dashboard chat's expand are the single-element size FLIPs (flipFrominsrc/lib/motion.ts):translateandscaleon the same element, measured before the class swap. - Pages enter through
src/app/template.tsx. Its.pageelement is new on every navigation and carries the only whole-page entrance; a page never adds another. Next'sexperimental.viewTransitionis off on purpose; see #238 for what has to hold before it goes on. - Spinners freezing under Reduce is intended.
animate-spinandanimate-pulsebecome a single frame at0.01ms; do not "fix" it.
Before finishing: npm run lint, npm run typecheck, npm test, and
npm run build for anything framework- or build-sensitive. Those, and
end-to-end (npm run e2e, where any axe violation fails), are CI's required
checks. CI also runs migrations, integration, Helm, images and smoke, and a
long fuzz; they do not gate the merge, but they are expected to pass. A
docs-only pull request skips build, database, Helm, end-to-end and images
(code-paths in ci.yml); lint, typecheck and tests still run. The other scripts, and when to reach for them:
npm run dev:demo # dev server in AUTH_MODE=demo, no Keycloak needed (not for auth work)
npm run test:fuzz # after any SQL or PromQL guard change (FUZZ_RUNS, FUZZ_SEED)
npm run themes:check # after a token change: every theme against the quality bar
npm run themes:export # a built-in theme as a THEME_FILE (`--silent ... graphite -- --as acme`)
npm run test:integration # after a change to queries, repos or migrations (Docker, or MIGRATE_TEST_DATABASE_URL)
npm run e2e # after a UI or auth change: Playwright journeys and axe scans (Docker)
npm run migrate:verify # after adding a migration: round-trips every one on a scratch database
npm run config:check # after adding an environment variable
npm run eval # after a prompt change: grades recorded generations (--live --record re-records)
npm run fixture:capture # adds a stored spec to the IR fixture library
npm run smoke # checks the seeded dashboards end to end, and each opt-in one that is on
npm run load:stream # many viewers of one dashboard stream, some stalled (against dev:demo)- Tests hold rules, not coverage. A unit test exists because a rule
above would otherwise regress silently: a guard, an authorization
decision, the IR, time, a registry, a parser of untrusted input. Do not
add one for a label or a formatter, a happy path an
e2e/journey walks, a seeded dashboardnpm run smokealready runs, or a shape the typechecker holds. Extend the named test that holds the rule before adding a file, and a change that only moves or restyles UI needs no new unit test. - End-to-end specs run in parallel.
e2e/playwright.config.tshas aparallelproject, aphoneone (the a11y and flow specs on a Pixel 7; open what the phone layout folds away whenisMobile) and, after both, aserialone. A test makes its own records under a name no other test uses (unique()ine2e/support/app.ts) and never counts a shared list; one that changes state the workspace or the person shares (uploads, the DuckDB root, a default model, a preference) is tagged@serialand says why. A journey does not walk a step another journey or a unit test already holds. - Biome is the linter and formatter (
npm run lint:fix); there is no ESLint or Prettier.noFloatingPromises,useExhaustiveDependencies,noExplicitAnyandnoConsoleare errors: fix them rather than suppress. A deliberate fire-and-forget isvoid promise. - Typecheck runs
next typegenfirst; a baretscfails on a cold checkout. - Build with no
.env. Every config value has a fallback. A new environment variable goes inEnvSchema/validateConfigwith a message naming it, warns in development and errors in production, and is covered intest/config.test.ts;npm run config:checkmust still pass on.env.example. - Migrations declare their down path (
-- rollback:or-- irreversible: <reason>) and prefer expand/contract, since old and new code run together during a rollout. CI rolls each one back and compares schema fingerprints. - Helm: the chart's two
failguards (a credential under.Values.config, a grace period below the drain budget) have assertions in CI; change them together. - Docs: a change to something the docs describe updates the page in the
same pull request (
CONTRIBUTING.mdmaps source files to pages).test/docs-drift.test.tsholds the API routes, audit actions and settings tables to the code. - Actions are pinned to a full commit SHA with a
# vX.Y.Zcomment (test/workflow-pins.test.ts). Dependabot's ignores (Node 25+, TypeScript 7+,@grafana/lezer-logql0.4+) are explained in.github/dependabot.yml.