ui ARCHITECTURE.md
4.9 kB 48 lines
Markdown
at main

Architecture #

jfalava's shared UI, one source of design for every site, CLI and app: the brand's CSS, tokens and fonts come first, and each surface (Astro docs, Effect web apps, share cards, Effect and clap terminals, Rune apps) reads them and adds its own components. It is a Bun workspace of npm packages, a Cargo workspace with one published crate, and a second Cargo workspace for the Rune theme.

Packages #

  • brand/ (@jfalava/ui-brand): the brand in plain CSS with no dependencies, plus a Tailwind v4 theme. brand/tokens.css is the single source of its values; brand/tokens.json and brand/tailwind-merge.json are generated from it by brand/scripts/tokens.ts for consumers that cannot read CSS. It also owns the fonts (brand/fonts.css, brand/ttf/). It depends on no other package here.
  • astro/ (@jfalava/ui-astro): Nimbus docs components for Astro sites. astro/nimbus/ is Cloudflare's Nimbus code, copied unchanged by astro/scripts/sync-nimbus.ts and never edited by hand; astro/theme.css is jfalava's own layer, which imports the brand's fonts and tokens and points Nimbus's theme at them. Depends on brand/.
  • effect-ui/ (@jfalava/ui-effect-ui): web components for Effect UI apps, in effect-ui/src/: Omnibar search (omnibar.ts), the Vellum and Folio writers (vellum.ts, folio.ts, with blocks.ts and history.ts) and Hotkeys (hotkeys.ts). effect-ui/src/parts.ts holds the view functions they share, and effect-ui/theme.css is the Tailwind theme they are drawn with. Depends on brand/.
  • og/ (@jfalava/ui-og): share cards (OG images) for any site or framework. og/src/index.ts draws a 1200 × 630 PNG with Satori and resvg from the brand's tokens and fonts, og/src/paths.ts maps a page's address to its card, and og/src/vite.ts is the Vite plugin that emits the cards with a build's assets. Depends on brand/.
  • effect-cli/ (@jfalava/ui-effect-cli): terminal UI for Effect CLIs, one module per export in effect-cli/src/: styles and glyphs (style.ts), OSC 7501 status (status.ts), progress, prompts, tables, help and Listr output. It reads nothing from the other packages.
  • clap/ (jfalava-ui-clap, a crate on crates.io): terminal UI for clap CLIs, the Rust counterpart of effect-cli/. It takes effect-cli/'s glyph sets and status lines, and clap/tests/parity.rs fails when the two drift. Member of the root Cargo workspace in Cargo.toml.
  • rune/ (jfalava-ui-rune, a crate that is publish = false and used from git): the brand for Rune apps, a rune-kit theme with an update badge, callouts and other components. rune/src/lib.rs embeds brand/tokens.json and the fonts in brand/ttf/ at compile time. It is a Cargo workspace of its own, excluded from the root one, so Rune's wgpu and winit stay out of clap/'s lockfile and Linux build.
brand/ ──► astro/
   │  ├───► effect-ui/
   │  ├───► og/
   │  └───► rune/      (compile-time include of tokens and fonts)
effect-cli/ ◄── parity ──► clap/

Flow #

A brand change reaches every surface by one path:

  1. Edit a value in brand/tokens.css.
  2. bun run tokens in brand/ rewrites brand/tokens.json and brand/tailwind-merge.json; tokens:check fails when either is stale.
  3. The web packages pick the CSS up through @jfalava/ui-brand, og/src/index.ts reads the JSON and the TTFs, and rune/src/lib.rs embeds them.

State #

The repo keeps no runtime state. Generated files are tracked and have one writer each: brand/scripts/tokens.ts writes brand/tokens.json and brand/tailwind-merge.json, and astro/scripts/sync-nimbus.ts writes astro/nimbus/.

Entry points #

  • Each npm package's exports in its package.json: brand/ and the themes are CSS, effect-cli/, effect-ui/ and og/ are modules built into a dist folder by build:npm.
  • .github/workflows/ci.yml: the changes job decides which of check (Bun gate), rust (clap/ crate gate) and rune (macOS gate and gallery renders) run.
  • .github/workflows/release.yml: on a push to main that changes a package.json or Cargo.toml, publishes each package to npm and each crate to crates.io whose version is not on its registry yet. Each package has its own version.
  • rune/examples/gallery.rs: opens the Rune gallery, or renders its scenes to PNGs headless.

Invariants #

  • brand/ depends on nothing here; every other package may depend on it, and none on a sibling other than brand/.
  • Nothing in astro/nimbus/ is edited by hand; changes go in astro/theme.css or the sync script.
  • brand/tokens.json and brand/tailwind-merge.json are never edited by hand.
  • clap/ and effect-cli/ share glyphs and status lines only through clap/tests/parity.rs and effect-cli/test/fixtures/lines.json, not through a shared package.
  • rune/ never joins the root Cargo workspace.