Architecture
The toolkit is a monorepo of 40 @ailura/alpinejs-* packages sharing a single controller
canon and Alpine bridge. This page is the reference for that canon: the principles
behind it, the layer rules, the controller lifecycle, the plugin factory shape, and how
a new package gets scaffolded and validated.
The five core ideas
Section titled “The five core ideas”- Controllers own state; Alpine owns reactivity. A framework-agnostic
BaseControlleremits typedchangeevents; a thinplugin.tsshadows them into an Alpine store or magic. - One canon per package. Every package ships
package.json,vite.config.ts,tsconfig.json,.size-limit.json, andsrc/{index,types,controller,plugin}.ts. - Guards prevent silent collisions.
guardStore/guardMagic/guardDirectivethrow aRegistrationErrorwhen two packages claim the same name. - SSR-safe by default. No package reads
window/documentat import time — onlysafeWindow()/safeDocument()/safeMatchMedia(). - Build and size are enforced.
vp pack→ one ESM bundle + types, withpublint/attwand per-package size budgets.
Layers
Section titled “Layers”Layers flow downward — a layer only imports from layers below it. core has zero
toolkit peers, which is what makes it safe to depend on from anywhere.
Foundation core · ui · state-machine · testing · plugin-templatePrimitives env · media · notify · selection · collection · child · scroll · calendar form · gesture · keyboard · history · timer · toast · transfer · permissions · geo · langFeatures accordion · tabs · dialog · menu · tooltip · overlay · attention theme · sidebar · carousel · command · virtualData query · query-adapter-alpine · query-adapter-zustand · query-adapter-nanostores · json-apiThe home page has the same map as browsable cards, one per layer.
The Data layer has an adapter family, not a single adapter
Section titled “The Data layer has an adapter family, not a single adapter”@ailura/alpinejs-query owns the QueryStateAdapter contract — { create(initial) → { get, set, destroy } } — and the controller publishes a fresh devtools snapshot into the handle
on every change. Three packages implement that contract, and all three register the key
"query", so you can swap one for the other and rename nothing:
query-adapter-alpinekeeps the snapshot in anAlpine.reactivebox.query-adapter-zustandkeeps it in onezustand/vanillastore per handle, and an injected store creator makes that store reachable for subscription from outside Alpine.query-adapter-nanostoreskeeps it in onenanostoresatomper handle, and an injected store creator makes that atom reachable the same way.
All three are sinks, not sources: none reads a cache entry back out, and none changes
the registered $store.query. What separates them is the store, and therefore what a host
can observe. Alpine’s box is the only one a template can bind to, because Alpine.reactive
is Alpine’s own graph. Between the other two, zustand’s subscribe hands you the whole
{ value } slot to unwrap, while nanostores’ atom holds the snapshot itself — no
wrapper, a subscribe that also fires once on attach, and the smallest peer dependency of
the three.
Migration facts
Section titled “Migration facts”Two things about the old @ailuracode packages are worth stating plainly, because the prose
that used to describe them is no longer true:
-
@ailuracode/alpine-query-kitis retired and is not being re-created. It was described as the single remainingQueryStateAdapterimplementation; that sentence is false, and the retirement is finished rather than pending — both surfaces the old package owned now have a home here, and neither came back as the old package:Old alpine-query-kitsurfaceNew home State The devtools panel @ailura/alpinejs-query/devtools—queryDevtoolsPlugin,mountQueryDevtoolsShipped as a real subpath export The snapshot contract the panel read QueryDevtoolsApiat$store.query.devtoolsShipped — getSnapshot(),subscribe(cb)The nanostores state backend @ailura/alpinejs-query-adapter-nanostoresShipped as a peer package, not a re-export The NanoStores/$nano/x-nanore-exportsNothing — @nanostores/alpineowns those namesNot carried over, deliberately The panel is a port, not a copy: it is rewritten to be SSR-safe through
safeDocument()/safeWindow()/isBrowser()from@ailura/alpinejs-core/envinstead of the old raw DOM access,queryDevtoolsPlugindefers toalpine:initializedwith a listener it can remove again, it reads the cache only throughQueryDevtoolsApi, and its Edit tab turns on only when the source it is mounted with exposessetData—QueryDevtoolsApiitself is read-only, so a bare{ devtools }source gets a disabled tab with the reason printed instead of a button that does nothing. It ships from its own subpath, so a production bundle that never imports it carries none of it.What was not carried over is the dependency shape, and that is the point. This repo has zero runtime
dependenciesin all 40 packages — every third-party runtime is apeerDependencyplus a devDependency, aneverBundleentry, and a.size-limit.jsonignore, exactly ascarouseldoes withembla-carousel, and as the two other query adapters do withzustandandnanostores. Sonanostoreswas not pulled intoquery: it became a separate package in the same adapter family, and every named Alpine surface the old package used to register is now either owned byqueryor deliberately left to your app. -
state-machineis the successor of the oldalpine-toggle, andalpine-toggleis not being re-created. That is a migration fact, not a feature claim:state-machineis an N-stateMachineControllerin the tree, and the tree supports no mapping from analpine-togglesource to it beyond the migration itself. Anything the old package did thatMachineControllerdoes not, is not ported.
Controller lifecycle
Section titled “Controller lifecycle”[*] --> idle : new Controller()idle --> mounted : mount() — runs setup()mounted --> destroyed : destroy() — drains cleanups LIFOdestroyed --> [*] : frozen — all mutations are silent no-opsmount() is idempotent and only runs once from idle. destroy() is idempotent and
final.
The plugin factory
Section titled “The plugin factory”Every feature package exports a factory that returns an Alpine.plugin callback:
const packageName = "@ailura/alpinejs-my"; // required: guard ownership
export function myPlugin(options: CreateMyOptions = {}) { const storeKey = options.storeKey ?? DEFAULT_MY_STORE_KEY; const magicKey = options.magicKey ?? options.storeKey ?? DEFAULT_MY_MAGIC_KEY;
return function registerMy(alpine: Alpine) { const controller = new MyController(options.id); const store = createMyStore(controller);
const sync = () => { /* shadow controller state into alpine.store(storeKey) */ }; const unsubscribe = controller.on("change", sync);
guardStore(alpine, storeKey, store, packageName); if (magicKey) guardMagic(alpine, magicKey, () => alpine.store(storeKey), packageName); };}Magic follows store — renaming storeKey renames both.
Key surfaces by kind
Section titled “Key surfaces by kind”| Kind | Example | Notes |
|---|---|---|
| Store | $store.accordion, $store.theme |
Reactive snapshot synced from the controller |
| Magic | $timer.create(...), $machine(...) |
Built per evaluation, isolated instances |
| Directive | x-child, x-gesture |
Registered via guardDirective, kebab-cased |
Adding a package
Section titled “Adding a package”pnpm run new:plugin -- my-pluginThis scaffolds from plugin-template, renames the tokens, and adds the tsconfig
reference. The plugin-template page has the full
canon checklist to land a package.
Validation
Section titled “Validation”pnpm typecheck # tsc + vp run --recursive typecheckpnpm build # vp run --recursive build (vp pack per package)pnpm test # vitest + happy-dompnpm check # lint + typecheck + testspnpm size # size-limit per package