Introducing a new way to review your PRs.

Read the announcement

spartan-ng / spartan

Cutting-edge tools powering Angular full-stack development.

View on GitHub

18 documents · Updated Nov 23, 2026

docs / cli-ui-library-generation

CLI UI library generation

The UI generator adds selected Spartan UI primitives to an Angular workspace. It turns a primitive choice into local Helm source, connects that source to the workspace, records its package needs, and applies the selected design style so the application can use and own the result.

For the wider command flow, see CLI and generators. For the related workspace setup flow, see Workspace maintenance generators. The generated layers are described in Brain primitives and Helm components.

System model

The UI generator joins two UI layers. Brain provides headless behavior and accessibility through package imports. Helm provides the styled Angular source that the generator copies into the workspace. The shared utils primitive provides class merging and class coordination used by that local source.

Each public primitive name represents a UI capability such as button, dialog, code-block, or trace. The catalog also states the packages that the selected source needs. The generator therefore creates local application-owned source while keeping behavior packages and external tools as workspace dependencies.

Utility class coordination

The generated utility layer gives Helm components one shared way to combine Tailwind class values and resolve conflicting classes. It also lets a component update classes on its host without replacing class values owned by other bindings.

This shared contract keeps visual state in generated Helm components separate from the Brain behavior that those components wrap. The utils primitive is therefore a base dependency for generated source that uses either direct class merging or managed host classes.

References: libs/…/hlm.ts.template• L1-27

Generation flow

The flow starts with workspace settings and a primitive choice. It resolves the choice and its local requirements before it writes source and returns the workspace tasks.

flowchart LR
    A[UI generator request] --> B[Read or create components.json]
    B --> C[Resolve workspace mode and style]
    C --> D[Select supported primitives]
    D --> E[Expand local primitive dependencies]
    E --> F[Generate Helm and utility source]
    F --> G[Apply style classes]
    G --> H[Register aliases and packages]
    H --> I[Angular workspace uses local libraries]

Workspace configuration

The generator reads components.json, or creates it for a new workspace. This configuration sets the component directory, import alias, design style, and workspace generation mode. Angular CLI and Nx use the same primitive model but differ in how the generated source is connected to the workspace.

If an existing configuration has no style, the generator adds the default vega style before it continues. Invalid configuration stops the run with the fields that need correction. The workspace mode changes the output layout and registration rules, not the set of UI capabilities.

References: libs/…/generator.ts• L16-22 libs/…/config.ts• L8-36 libs/…/config.ts• L85-164 libs/…/schema.json• L7-24

Primitive selection

The supported primitive catalog is the source of truth for names that the UI generator can create. A valid name selects one primitive. The all value selects the full catalog. Without a valid name, the CLI asks the user to select one or more entries.

The catalog maps each public name to its local Helm generator and lists its package requirements. Brain-backed entries now require Brain 1.10.0, while Helm source remains local source rather than an npm package. The catalog also captures extra needs for primitives such as tabs, whose generated paginated list uses Angular CDK observation, icon packages, RxJS, and shared class utilities.

Registry checks keep the public primitive names aligned with the type list, dependency map, catalog, and local generator adapters. This alignment lets selection lead to a generator that can create the requested output.

References: libs/…/generator.ts• L24-47 libs/…/primitives.ts• L1-67 libs/…/supported-ui-libraries.json• L2-10 libs/…/supported-ui-libraries.json• L195-225 libs/…/supported-ui-libraries.json• L514-584 libs/…/schema.d.ts• L1-8 libs/…/hlm-tabs-paginated-list.ts.template• L1-19

Primitive dependencies

Some primitives are built from other generated primitives. The dependency graph describes these local relationships so a higher-level choice produces all the Helm source that its generated imports need.

The graph gives every generated primitive the shared utils layer and adds the local pieces required by composite controls. For example, tabs also needs the generated button primitive, while code blocks need button and trace needs only utils.

For a partial selection, dependency installation is enabled by default. The generator expands the selection through the graph and avoids entries that are already selected. The caller can disable this behavior and take responsibility for adding the required primitives. Selecting all needs no expansion because the catalog is already complete.

References: libs/…/primitive-deps.ts• L3-70 libs/…/primitive-deps.ts• L72-89 libs/…/generator.ts• L70-82

Helm source generation

Each selected primitive becomes local Angular source under the configured component directory. A small primitive adapter passes the request to the shared generation flow, which writes the public entry point and the primitive's styled directives or components. The generator uses the same path for ordinary controls and special entries such as code-block and trace.

The generated Helm layer keeps Brain behavior at the boundary where a primitive needs it. For example, an accordion wraps Brain accordion behavior, while autocomplete combines Brain autocomplete and popover behavior. Interactive Helm primitives expose Brain state through their styled host elements, so open state, placement, direction, and value behavior remain part of the shared contract. Form controls also carry value, disabled, invalid, and label state through this boundary when the primitive supports Angular forms. Other primitives can be style-only Helm source. All of them use the shared utility layer for class handling.

The generated source also covers compound controls that need a stable visual contract around shared behavior. Date picker inputs accept application-defined parse and format rules, pagination offers either in-page actions or route links, and mobile sidebars share their open state with the sheet layer. These features stay behind the Helm entry points so consumers use one public surface for each primitive.

The tabs entry point exposes its tab parts through one stable import surface. Its paginated list adds the visual controls and class inputs needed for scrollable tab headers while retaining the Brain tab-list behavior.

The questionnaire actions source assigns its layout classes without setting a minimum height in the generated component. That visual rule stays with the selected theme so generated applications and source-served documentation use the same style contract.

References: libs/…/generator.ts• L102-125 libs/…/generator.ts• L1-7 libs/…/index.ts.template• L1-22 libs/…/hlm-tabs-paginated-list.ts.template• L14-102 libs/…/hlm-accordion-trigger.ts.template• L1-41 libs/…/hlm-button.ts.template• L1-62 libs/…/hlm-checkbox.ts.template• L14-77 libs/…/hlm-date-picker-input.ts.template• L1-112 libs/…/hlm-date-picker-trigger.ts.template• L1-89 libs/…/hlm-dialog-overlay.ts.template• L1-26 libs/…/hlm-input-otp.ts.template• L1-59 libs/…/hlm-native-select.ts.template• L1-155 libs/…/hlm-numbered-pagination.ts.template• L30-241 libs/…/hlm-numbered-pagination-query-params.ts.template• L26-237 libs/…/hlm-sidebar.service.ts.template• L16-115 libs/…/hlm-sidebar.ts.template• L9-138 libs/…/hlm-switch.ts.template• L25-122 libs/…/hlm-trace-collapsible-content.ts.template• L6-34

Style application

The generator applies the selected style after it writes the Helm source. A style maps the source's internal class names to Tailwind classes for the chosen design system. This keeps the generated primitive API stable while allowing the workspace's visual result to vary by style.

References: libs/…/generator.ts• L32-47 libs/…/generator.ts• L233-245 libs/…/create-style-map.ts• L5-53 libs/…/transform.ts• L11-34

Workspace integration

After source generation, the generator makes each local library visible to Angular and records packages that the source needs. Angular CLI receives the path and source rules needed for generated code outside the application source directory. Nx uses either separate libraries or one shared entry-point library based on the workspace configuration.

Package registration adds only packages that the workspace does not already manage. The package set comes from the selected catalog entries after Helm-only requirements are removed. Existing workspace versions take priority when a matching package is already installed.

The generator prepares primitive work together and returns tasks that run in sequence after the workspace tree is updated. This keeps source creation, library setup, alias registration, and package registration in one generator operation.

References: libs/…/generator.ts• L84-125 libs/…/generator.ts• L197-208 libs/…/generator.ts• L210-252 libs/…/build-dependency-array.ts• L7-40 libs/…/initialize-angular-library.ts• L118-176

Generated library use

The generated Helm libraries are the application-facing styled layer. Applications import a primitive through the configured alias and use its public entry point. The copied source remains available for application-specific visual changes without changing Brain behavior.

Use Helm when the application needs the Spartan visual layer. Use Brain directly when it needs the behavior and accessibility contract without generated Helm styling. A generated primitive is useful only when its local dependencies and package requirements are present in the workspace.

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the primitive type, catalog keys, dependency graph, local generator directories, and public names aligned. The registry checks rely on this contract.
  • Keep every local primitive imported by a generated template in that primitive's transitive dependency graph. A template import must not depend on an undeclared generated library.
  • Keep catalog package requirements compatible with dependency registration. Brain-backed entries must use the released Brain version expected by generated source. Helm source must remain local source and must not become an npm dependency by accident.
  • Keep the utils catalog requirements aligned with the generated utility source. Its Brain class helper and cn merge function must remain installable in generated workspaces.
  • Preserve the import alias and workspace-layout contract when changing Angular CLI or Nx setup. Generated imports and TypeScript paths must resolve to the same target.
  • Keep Brain host bindings, overlay composition, form state, and shared utility imports aligned when changing templates for interactive controls.
  • Keep the public entry point aligned with every primitive part and its Angular imports collection. This is especially important for multi-part primitives such as tabs, code-block, and trace.
  • Keep paired package requirements together when a primitive consumes an external engine and its Angular adapter.
  • Keep CLI style names aligned with the style definitions used by the base generator. A catalog change alone does not create a usable style.

Important failure modes

TriggerConsequenceGuard
A catalog name has no matching local generatorDynamic loading fails after selectionKeep catalog names, adapter directories, and adapter names in sync.
A generated template imports a local primitive that is absent from its transitive dependenciesGenerated source can import a library that was never createdKeep template imports and the dependency graph aligned.
A required local primitive is omitted while dependency installation is disabledGenerated source can import a library that does not existEnable dependency installation or select the required primitives explicitly.
components.json has an invalid style, alias, or workspace optionValidation stops generation before a usable workspace is producedFix the reported configuration fields before rerunning the generator.
Generated source has no matching TypeScript aliasAngular cannot resolve the local Helm importKeep generation mode, target path, and alias registration aligned.
A style name has no matching style mapGenerated classes do not receive the intended visual styleUpdate the CLI style list and its matching style definition together.
A Brain or overlay host binding changes without a matching generated template contractA generated primitive can lose behavior or expose a mismatched Angular interfaceTreat Brain imports and Helm templates as one contract.
The public entry point omits a generated primitive partConsumers cannot use the part even though its source existsKeep entry-point exports and imports collections complete.
A catalog entry omits a package used by a generated templateThe generated workspace can fail to build or run at the first use of that primitiveCompare catalog requirements with template imports, especially for date picker, pagination, tabs, and icon support.
A catalog entry points Brain-backed source at an incompatible Brain versionGenerated primitives can install a version that does not match their behavior contractKeep the catalog Brain version aligned with the released Brain package used by the CLI.
The utils catalog entry omits a package used by the generated class helperGenerated Helm source can fail to build or lose class merge behaviorTreat hlm.ts.template imports as part of the utils package contract.

Key files

FileWhy to read it
libs/…/generator.tsMain flow from configuration and selection to primitive generation tasks
libs/…/supported-ui-libraries.jsonSupported primitive catalog and package requirements
libs/…/primitives.tsType-level list of supported primitive names
libs/…/primitive-deps.tsLocal composition graph and dependency expansion
libs/…/schema.jsonUser-facing generator inputs for primitive name, output directory, and tags
libs/…/generator.tsShared source generation, style application, workspace registration, and package flow
libs/…/config.tsConfiguration defaults, prompts, style backfill, and validation
libs/cli/src/generators/ui/libs/utils/files/lib/hlm.ts.templateGenerated class merge and class coordination used by Helm source
libs/…/generator.ts, libs/cli/src/generators/ui/libs/tabs/files/index.ts.templateExample of a multi-part primitive and its public entry point
libs/cli/src/generators/ui/libs/tabs/files/lib/hlm-tabs-paginated-list.ts.templateExample of a generated Helm primitive that combines Brain behavior with CDK observation, icons, and styled controls
libs/cli/src/generators/ui/libs/date-picker/files/lib/hlm-date-picker-input.ts.template, libs/cli/src/generators/ui/libs/date-picker/files/lib/hlm-date-picker-trigger.ts.templateExample of a form-aware date control with application-defined parsing and formatting
libs/cli/src/generators/ui/libs/pagination/files/lib/hlm-numbered-pagination.ts.template, libs/cli/src/generators/ui/libs/pagination/files/lib/hlm-numbered-pagination-query-params.ts.templateExamples of local pagination and route-backed pagination
libs/cli/src/generators/ui/libs/sidebar/files/lib/hlm-sidebar.service.ts.template, libs/cli/src/generators/ui/libs/sidebar/files/lib/hlm-sidebar.ts.templateExample of responsive state shared between a sidebar and a sheet
libs/cli/src/generators/ui/libs/autocomplete/files/lib/hlm-autocomplete.ts.templateExample of a Helm boundary that combines Brain behavior with styled output
libs/cli/src/generators/ui/libs/dialog/files/lib/hlm-dialog-content.ts.template, libs/cli/src/generators/ui/libs/popover/files/lib/hlm-popover.ts.templateExamples of generated overlays that preserve Brain state and expose styled content
libs/cli/src/generators/ui/libs/input-otp/files/lib/hlm-input-otp.ts.templateExample of a generated control that forwards behavior while adding a stable styled surface
libs/cli/src/generators/ui/libs/questionnaire/files/lib/hlm-questionnaire-actions.ts.templateExample of generated layout classes that leave a visual size rule to the selected theme
libs/cli/src/generators/ui/libs/typography/files/lib/hlm-h1.ts.templateExample of a style-focused primitive that uses the shared utility layer