bodega

bodega is a schema-first component store inspired by ZagJS, powered by TanStack Store and alien-signals. Describe a component's props, state, derived, and actions once — get back one hook that handles context, controllable state, and slice-level subscriptions.

Why it exists

It splits a component's concerns. The schema is the brain — you read the contract first, the implementation second:

  • The brain, up top. An easy-to-read schema is the contract; implementation comes second.
  • Less boilerplate in the parts. No context wiring, no controlled/uncontrolled branching.
  • Fine-grained. A part subscribes to one slice and re-renders only when that slice changes.
  • Practically free. In any repo already on TanStack, this is a near-zero-cost dep.
  • LLM-friendly. Typesafe conventions a model can follow without inventing its own.

Core concepts

A store is four buckets, resolved in order:

One store, two modes — the root owns, the leaves inherit:

A taste of the API

Recommended structure — index says what's public, Root is the only part that initiates the store, store is the brain, the rest are leaves:

store.ts — schema in, hook out. Nothing else leaves the file:

Leaves inherit and subscribe to just their slice:

index.ts decides the public surface — two shapes from the same parts.

FlattenedRoot composes the leaves itself; the consumer just drops it in. Most common for a component local to one route:

Compound — leaves are exposed so the consumer arranges them; Root is just the boundary. Most common for a design-system component: