Files
d1c5d643c1 web: adopt @goauthentik/theme tokens in the app styles (#22523)
* web/testing/snapshots: enable visual comparisons

As an experiment, I have added three visual comparisons:

- dashboard
- event notification rules table
- new prompt form

… which provides a wide variety of controls that I can see and compare. As we move toward a more robust testing scheme *and* toward a more dispersed repository of artifacts (theme, elements, etc), I wanted a way to ensure that our upgrades to Patternfly and components didn’t break anything. I spent the day learning much more about Playwright and the snapshot tests.

I don’t think @BeryJu’s concern for snapshot size isn’t wholly warranted. I’ve manually restricted the viewport to 1280x800, so each snapshot pair (“light” and “dark”) is about 220Kb. The current project repo is 795Mb in size; it would take 40 tests to increase the size of the repository by 1%. If we have half that many snapshot pairs by next year, I’ll be delighted.

One challenge these tests present is that they should be run on a completely fresh database with no modifications; the dashboard and notifications page should reflect only the default status of an authentik instance when it comes up. The purpose of the snapshots isn’t to record the utility of the front-end; it’s to record and preserve the appearance of select elements in the page.

* Of course prettier had opinions.

* Optimised images with calibre/image-actions

* web/theme: the patternfly bridge

Generates the PatternFly 4 variables from the theme source instead of
maintaining them by hand: moves the token modules from src/tokens/ to
src/authentik/, and adds src/patternfly/ which emits the PF variables
from those tokens.

Known gaps: 17 colors remain unmapped and undefined; PatternFly dark
mode is not emitted yet; the linter cannot compare PatternFly and
authentik colors because the theme is authored in oklch.

* web: compare screenshots against the base branch locally

Replace the committed page snapshots with a local visual comparison
workflow. `pnpm run test:visual` screenshots every Storybook story in
light and dark, and compares it against the merge-base with
origin/main. Baselines are recorded on demand from a temporary
worktree and cached in the git-ignored `.visual/` store, keyed by
commit and platform, so no images are committed.

A `pages` suite covers admin screens without generated data (login,
a modal form, a wizard) on a running instance.

Also break an import cycle between the notifications mixin and the
drawer components, which broke the Page Navbar story.

* web: load @goauthentik/theme in the app styles

Build packages/theme before the web build, Storybook, and watch, and
import its generated CSS after the legacy variables in the theme layer
so the generated PatternFly variables take precedence.

* web/theme: fix inverted PatternFly light/dark text colors

PatternFly names text colors by the color of the text itself:
--pf-global--Color--dark-100 is dark text (#151515) for light surfaces,
and --pf-global--Color--light-100 is light text for dark surfaces. The
bridge mapped them the other way around, so components that set
--pf-global--Color--100 from dark-100 (Page, Alert, Table, and others)
rendered white text in light mode.

* web/theme: add a muted ink for light surfaces

Add ink.pin-light.muted (#6a6e73) and map --pf-global--Color--dark-200
to it. PatternFly uses dark-200 for helper and placeholder text on
light surfaces; it was mapped to full-strength ink.

* web: commit the generated theme stylesheet

Building web in the container only installs the web workspace, so it
can't build packages/theme, which belongs to the root workspace and has
its own dependencies. Commit the theme's generated CSS instead, the same
way the API client is committed, and drop the theme build from the web
build graph.

`pnpm run build:theme` regenerates it; `pnpm run lint:theme` fails when
the committed copy is out of date.

* web/theme: convert the build scripts to TypeScript

Node runs TypeScript directly now, so replace build.mjs, build-demo.mjs,
lint-bridge.mjs, reference.css.js, and stylelint.config.mjs with .ts
equivalents. JSDoc typedefs become interfaces.

lint-bridge's array and CSS branches returned a bare string instead of a
[kind, value] pair, and its ref branch passed an extra argument that
shifted every parameter; both are fixed. Its output is unchanged for the
current tokens.

The generated header also names the current source directory; it still
pointed at the old src/tokens/.

* Format.

* web: move ak-drawer onto the generated theme tokens

Replaces the drawer's --ak-v2-global--* references with the
--ak-global--* tokens from the generated theme, and gives the drawer its
own directional shadows and RTL inverse multiplier. The multiplier was
previously read from --ak-v2-global--inverse--multiplier, which nothing
defined.

Co-Authored-By: Ken Sternberg <[email protected]>

* Fix overflow.

* packages/fonts: declare RedHatText's full weight range

The variable face covers 300-700, but the @font-face rules declared
400 500, so light text rendered at 400 and bold was capped at 500.

* website: copy docusaurus-config into the image instead of mounting it

pnpm can place workspace links in a package's own node_modules (for
example `@goauthentik/fonts` under packages/docusaurus-config), and a
read-only bind mount of the package source over that directory hides
them from the docs build. Copy docusaurus-config and fonts into the
image before the root install instead, so those links survive.

* website: load the docs fonts from @goauthentik/fonts

Replaces docusaurus-config's hand-written @font-face rules and the
modified RedHat copies in website/static/fonts with the faces from
@goauthentik/fonts, so the docs and the web UI share one set of fonts.

* packages/theme: bump to 2.0.0

* Remove development comments

Drops file headers, restated JSDoc, commented-out reference values, and
exploratory notes added on this branch, keeping only comments that
explain something surprising.

---------

Co-authored-by: Ken Sternberg <[email protected]>
Co-authored-by: authentik-automation[bot] <135050075+authentik-automation[bot]@users.noreply.github.com>
2026-09-25 13:55:35 +01:00

6.8 KiB

Project Overview

This is the authentik WebUI — the default web interface for the authentik identity server. It is a TypeScript monorepo using Lit web components and PatternFly 4 design system.

There are three distinct UI applications, each with its own base URL and router:

  • Flow (/if/flow/) — Form orchestration for login, signup, password reset, etc.
  • User (/if/user/) — End-user portal for applications and profile settings
  • Admin (/if/admin/) — Server administration and configuration

All three share three core context objects:

  • Config — Server configuration and user permissions
  • CurrentTenant/Brand — Theme, logos, favicon, default flows
  • SessionUser — Logged-in user with impersonation support

Commands

Development

npm run watch          # Build + watch locales and bundler (main dev workflow)
npm run storybook      # Storybook dev server on port 6006

Build

npm run build          # Production build to dist/
npm run build-locales  # Compile i18n translations

Testing

npm test               # Vitest: unit tests (Node) + browser tests (Chromium/Playwright)
npm run test:e2e       # Playwright E2E tests against a running authentik instance
npm run test:visual    # Screenshot diffs against the base branch (see test/visual/AGENTS.md)

To run a single test file:

npx vitest run path/to/file.test.ts

Linting & Formatting

npm run lint           # Oxlint with --fix
npm run lint:check     # Oxlint, no fixes (CI mode, max-warnings: 0)
npm run build:types    # TypeScript type checking (tsc --noEmit)
npm run format         # Oxfmt with auto-fixes
npm run format:check   # Oxfmt in check-only mode
npm run precommit      # Full pre-commit check (format, lint, types, etc.)

Architecture

Directory Structure

src/
  admin/        # Admin interface application
  user/         # User portal application
  flow/         # Flow execution interface + FlowExecutor
  components/   # UI components that use context (depend on app state)
  elements/     # Reusable UI elements without context (portable)
  common/       # Non-UI shared libraries (API helpers, global state, utils)
  styles/       # Global CSS (PatternFly, authentik tokens, locales)
  standalone/   # Third-party apps (loading screen, API browser)
  rac/          # Remote Access Components (Guacamole-based)
  locales/      # Auto-generated i18n (do not edit manually)

packages/
  core/         # Monorepo utilities (paths, environment, version)
  sfe/          # Standalone Frontend Engine (Rollup-based)

test/
  unit/         # Node.js unit tests (*.test.ts)
  browser/      # Playwright browser tests (*.browser.test.ts)
  lit/          # Lit test helpers (renderLit, setup.js)

e2e/            # E2E test fixtures, selectors, auth utilities
bundler/        # Custom ESBuild/Vite plugins
scripts/        # Build scripts (esbuild config, localization)

Key Files

  • src/elements/Base.ts — AKElement: base class for all components
  • src/elements/Interface.ts — Base interface class with context management
  • src/common/global.ts — Global authentik config and state
  • src/flow/FlowExecutor.ts — Flow execution engine
  • scripts/build-web.ts — Main ESBuild configuration

Conventions

  • Custom element prefix: ak- (e.g., <ak-command-palette>)
  • Context: Lit Context API via ContextControllerRegistry
  • components/ depends on app context; elements/ must not
  • Import aliases: #elements/*, #components/*, #common/*, #admin/*, #user/*, #flow/*, etc. (mapped in package.json)

NEVER call the authentik API in a different way than using the @goauthentik/api package. In no case are you to use Fetch, Axios, or other methods.

Tech Stack

Concern Library
UI components Lit 3.x + Web Components
Design system PatternFly 4
Build ESBuild + Vite 7
Tests Vitest 4 + Playwright
i18n Lit Localize (runtime mode, 18 languages)
API client @goauthentik/api (generated)
Linting ESLint 9 + @goauthentik/eslint-config
Task orchestration Wireit

TypeScript Notes

  • tsconfig.json uses "useDefineForClassFields": false — required for Lit decorators and Storybook; do not change.
  • "moduleResolution": "bundler" — path aliases resolved at build time via package.json#imports.
  • Decorators are enabled with "experimentalDecorators": true.
  • Use unknown instead of any where possible, and prefer more specific types to both. Avoid as any casts.
  • When importing a module, prefer an import alias as defined in package.json (#flow/…, #elements/…, #common/…) over relative paths into src/. This ensures the import will work from any location, including tests.

i18n

Translatable strings use msg() from @lit/localize. To add new strings, use msg() and run:

npm run extract-locales   # Extract new strings to XLIFF files
npm run pseudolocalize    # Generate pseudo-locales for layout testing

Never edit files in src/locales/ directly — they are auto-generated.

Message ID conventions

Always provide an explicit id to msg(); do not rely on auto-generated hashes. IDs follow <feature>.<subfeature>.<role>[.<modifier>] with kebab-case in every segment.

  • Feature-first, not component-first. Use captcha.*, command-palette.*, used-by.* — not ak-secret-text-input.* or other element/class names. IDs must survive component renames.
  • Kebab-case in every segment. No camelCase (usedBy, ariaLabel, emailInAngleBrackets), no snake_case. used-by.count.one, wizard.aria-label.default, user.display.email-in-angle-brackets.
  • Trailing segment is the semantic role, not the surface wording: .label, .placeholder, .description, .tooltip, .aria-label, .alt-text, .error, .success. This lets translators filter by role.
  • CLDR plural suffixes for counts: .zero, .one, .two, .few, .many, .other.
  • Composable fragments that get concatenated go under .prefix.* / .suffix.* (see command-palette.prefix.*).
  • Shared strings go under a top-level namespace like common.actions.* or forms.validation.* rather than being duplicated per feature.
  • No flat kebab IDs like command-palette-placeholder or drawer-toggle-button-notifications for new strings. Use the dotted hierarchy: command-palette.placeholder, drawer.toggle-button.notifications. Migrate legacy flat IDs opportunistically when touching surrounding code; do not do bulk renames.