Karyo
Documentation/ Architecture

Frontend

Karyo 2.1.1rendered at build time
On this page

The two front ends, how each routes, and where action gating actually happens.

Derived from frontend/web/src/routes/router.tsx, frontend/mobile/src/routes/router.tsx, and the guard components.

Two applications, one origin

React and TypeScript throughout (ADR 0016). The desktop console is served at /, the floor PWA at /m/, both as static bundles from the nginx container with SPA fallbacks. They share an origin with the API, so there is no CORS surface in production.

They are separate applications, not one responsive build: separate src trees, separate route tables, separate Vitest projects.

Desktop routing

React Router v7, imported from react-router (frontend/web/src/routes/router.tsx, router), not react-router-dom.

The whole tree sits under one AuthGuard backed by oidc-client-ts. It discovers public issuer, browser client and scopes from /api/v1/auth/config, uses authorization code with PKCE and stores tokens only in session storage. Callback state is matched before restoring a same-origin deep link; stale, mismatched and network-path destinations fall back to /. Authority comes from /api/v1/me, not by decoding provider claims in the browser. Silo tenancy still fixes the Company, but the console and floor app select an authorized Business Unit within it. Operational API calls carry X-Karyo-Business-Unit-Id; switching selection resets the workspace's cached queries and forms. Selection never changes the principal's approved affiliation. The console header trail reads Group > Page on every page. It starts with the sidebar group of the page's entry in frontend/web/src/config/navigation.ts (Fulfillment for Orders, Insights for Monitors) and ends with that entry's title, so moving or renaming an entry changes its breadcrumb too. A group is plain text because it has nowhere to send the reader. On the page itself the title is the current crumb; on a record route it is a link, the way back to the list, and the page names the record in its heading. The header clock shows from the xl breakpoint (1280px), so below it the whole Group > Page trail keeps its full names beside the pickers, and the header gaps are tighter from 1024 to 1279px so the longest trail fits at 1024px. The title still truncates, with its full name as a tooltip, so the trail never runs into the Business Unit picker.

Four routes exist only as redirects. /replenishment and /pick-orders both Navigate to /tasks with a ?type= filter (frontend/web/src/routes/router.tsx, router), because replenishment and picking are task types in the unified work view rather than pages of their own. /insights/reports and /insights/occupancy both Navigate to / (router), because Reports and Occupancy moved onto Home as widgets and the fixed warehouse widget rather than pages of their own. Every redirect keeps bookmarks and printed links working.

Action gating mirrors the server

The console gates on Karyo's catalogue actions, never on a provider role (ADR 0048). frontend/web/src/config/actions.ts is the console's one list of action keys, mirroring libs/karyo-security/src/main/kotlin/com/karyo/security/Actions.kt. usePermissions (frontend/web/src/hooks/use-permissions.ts) reads the actions of the selected Business Unit from /api/v1/me businessUnits[]; for the administration actions the selected unit never narrows (UNIT_INDEPENDENT_ACTIONS), it reads the actions held anywhere. With no unit selected no unit-scoped action holds, and the floor app's menu follows the same rule. A control shows only when the action of the call it makes is there. The server still checks the exact Facility on every request.

Only /admin/* is route-guarded. AdminShell itself carries no guard; each admin page sits behind its own AdminGuard on the action its first read declares, taken from that page's entry in adminNavItems (frontend/web/src/config/admin-navigation.ts): extensions.read for Extensions, integrations.manage for Integrations, settings.manage for system properties, document templates and Health, organization.read for Clients, users.read for Users, operations.view for Documents, inventory.read for unit load types and the audit log, and layout.read for capacity. The sidebar filters the same entries through visibleAdminNavItems, so the guard and the navigation cannot disagree about who may open a page.

Everything outside /admin is authenticated-only. Operational authority is enforced at the API, not in the route table. Pages only mirror it: an engine page hides a write control unless the caller holds the action its route declares, operations.supervise or operations.execute. The Manager standard profile holds the first and the Operator profile the second; neither holds the other, and Administrator holds neither (services/karyo-app/src/main/resources/db/migration/auth/V1214__action_catalogue.sql).

Every engine page renders through its normal path

The router knows nothing about licensing, because the console has none: there is no features/license/ module, no page asks GET /api/v1/license, and frontend/web/src/pages/__tests__/engine-pages.test.tsx renders all seven engine pages (waves, streaming, monitors, forecasting, slotting, simulation and the document-templates admin page), asserting that each mounts its live view and that no request to /api/v1/license is made. Every engine page is an ordinary route in its home sidebar group, and the only thing between a caller and a page is the action: the admin guards above, and the authorized flag every list hook takes so a caller without the read action sees the permission state with the query idle. GET /api/v1/license stays on the server for integrations that read it (ADR 0030); the console does not.

A capability that still needs configuration says so on its own screen, as a fact rather than a lock. Slotting (frontend/web/src/pages/insights/slotting-page.tsx, /insights/slotting/:id? with the SKU as the record) needs Loci: without a Loci base URL the route's 503 slotting-engine-not-configured problem (isLociNotConfigured in slotting-api.ts, neither toasted nor retried) becomes a Slotting advice requires Loci state naming KARYO_LOCI_BASE_URL (karyo.slotting.loci.base-url), with no table and no earlier advice, and the Items page shows no classes and says they need Loci. With Loci, an engine strip (slotting-engine-strip.tsx) names who advised: Loci, with its version, its advice level (chosen by Loci from the evidence, since Karyo asks for the auto level), the state-as-of and valid-until instants. A configured Loci that does not answer is a 502 problem the page shows in its error state with a "Reload slotting advice" retry. The detail pane (slotting-detail.tsx) shows the reason, the target zone, where the SKU is now, the constraints Karyo enforces (a fixed-location hold) and next-step links into Inventory, Tasks and Locations; nothing on it moves stock (The engine boundaries).

Not every engine has a page. Cross-docking has no desktop route at all: it is triggered by a receiving observer and surfaces as transport orders in /tasks, which is why frontend/web/src/pages/tasks/work-model.ts, WORK_TYPE_META carries a CROSS_DOCK task type and no cross-dock page exists. Cartonization has no screen by construction - it changes how packout plans boxes, and is chosen on the order-strategy form.

Floor PWA

Fifteen routes, all under one auth guard, all task-shaped (frontend/mobile/src/routes/router.tsx, router): the work inbox at /, /pick/:ref, /move/:ref, /count/:ref, /receive/:ref, plus a menu, an inquiry screen, receipt selection, ad-hoc move and count, pack, reprint, sort, packout and a /sync-issues screen.

/sort and /packout are wave-engine surfaces, so the floor app reaches the wave engine's functionality. The floor app, like the console, has no licence awareness: its numbered menu gates on catalogue actions, and Sort and Pack-out also on the Waves capability (frontend/mobile/src/menu/registry.ts, MENU, frontend/mobile/src/menu/use-menu.ts, useMenu). They show while the installation's profile shows Waves, or while open waves drain after it is switched off, and their routes follow the same rule (ADR 0052).

Design system: Daylight Ledger

The console's visual system is one semantic token set with two themes (frontend/web/src/index.css). Tailwind v4 @theme inline maps every colour role (background, card, primary, destructive, the five status tones neutral, progress, success, attention, blocked with -soft and -solid variants, the sidebar and chart roles) onto CSS variables that a :root block sets for the light theme and a .dark block for night. The ThemeProvider (components/theme/theme-provider.tsx) puts light or dark on <html>; system follows the OS. A retired control value in storage maps to dark.

Four tests keep the system honest, and they run in the ordinary Vitest suite:

  • src/test/theme-contrast.test.ts computes WCAG contrast for every text pair (4.5:1) and UI pair (3:1) in both blocks, and fails if the two blocks define different variables.
  • src/test/type-scale.test.ts pins the type ladder at 12px and up and forbids arbitrary text-[Npx] classes in components and pages.
  • src/test/token-purity.test.ts forbids hex, rgb() and palette classes under components, pages, features, lib and config.
  • src/test/focus-visible.test.ts keeps the one focus ring rule.

On top of the tokens sit four component families, each with its own tests: the state family (components/state/state-panel.tsx: loading, empty, error, permission), the status badge (components/status/status-badge.tsx: icon plus word plus tone, so a state is never colour alone), the data table (components/data-table, TanStack Table v9 through useDataTable with sorting, selection, pagination, pinning, two densities and a virtualized body) and the form composition (components/form/form.tsx). Orders (pages/orders/orders-page.tsx) is the reference page on the table, and the only one with checkbox selection and a batch bar. Phase 2 moved Tasks, Receiving, ASNs, Shipments, Inventory, Locations, Items and Users onto it, and added My Queue and Exceptions on the same pattern; Phase 3 moved Slotting onto it, with the SKU as the record (/insights/slotting/:id?). Monitors uses it inside the page for its Exceptions card, with the open alert as the record (/insights/monitors/:id?). Orders itself joined the record route (/orders/:id?) and ListDetail last, so its phone list carries the selection checkboxes. The master-detail kit (components/master-detail) remains for the pages not yet moved (the admin section, Cycle Count, Strategies, Packing, Waves).

A list page composes three Phase 2 primitives from components/list-detail. useRecordRoute reads the open record from an optional route segment (/asns/:id?, /inventory/:item@:loc), replacing the URL on a desktop and pushing it on a phone so Back returns to the list. ListDetail renders the table with the record below it on desktop and tablet widths, and on a phone a stacked list or a full-screen record with a Back control. NarrowedNote declares a page-local filter ("12 of 50 on this page") whenever chips or a search box narrow a server page rather than querying it. A metric is components/metric/metric.tsx: value, unit, definition behind an info control, and an explicit truth (value, absent with its reason, unauthorized). Shared StatusBadge and Metric are the required primitives for operational states and figures, so a page does not hand-build a competing badge or number. Every list hook takes authorized so a caller without the read action sees the permission state with the query idle. The receiving workbench moved to /receiving/:id/workbench so that /receiving/:id is the record route.

Exceptions (pages/exceptions) runs nine checks as pure functions over the core APIs (exception-checks.ts) and shows the monitors engine's firing-alert count as one more summary section with a link to Monitors. It does not render the alert rows; Monitors is the working alert list. The alerts are still read through useFiringAlerts() on the same query key as the Monitors page and the Control dashboard, so the three share one cache entry.

Navigation is one placement, read twice. frontend/web/src/config/navigation.ts declares every console page in one of five groups (Overview, Inbound, Fulfillment, Warehouse, Insights); a NavItem carries a title, a URL, an icon, its group and an optional catalogue action, and getGroupedNavItems(permissions) buckets what the caller's actions let it see in render order. The sidebar and the ⌘K palette both read that one function, so they cannot drift apart. The engine pages sit in their home groups like every other page (Waves and Streaming under Fulfillment; Monitors, Forecasting, Slotting and Simulation under Insights), and frontend/web/src/config/__tests__/navigation.test.ts pins the groups and the placement.

Known debt

The configureVitest worker cap in frontend/web/vitest.config.ts, capTestWorkers, WORKER_CEILING exists because Vitest merges command-line options over the config file, so a plain maxWorkers setting would not survive a --maxWorkers override.