Introducing a new way to review your PRs.

Read the announcement

chakra-ui / zag

Build your design system in React, Solid, Vue, Svelte or Vanilla. Powered by finite state machines

View on GitHub

19 documents · Updated Sep 21, 2026

overview

Knowledge Base updated: 2026-09-20

Zag knowledge base

Orientation

Zag is a framework-neutral, accessibility-focused UI interaction library. Its component packages model behavior as state machines, then expose connect APIs that adapters use to produce framework-ready props and state.

The repository is organized around a reusable machine runtime (@zag-js/core), a catalog of component machines (@zag-js/* packages), framework adapters, and browser utilities. Shared stores, types, anatomy metadata, and icons provide consistent public API foundations across those layers.

Critical interaction state lives in machine service snapshots: a current state value, context, computed values, and effects. Component packages define the contracts; framework bindings own lifecycle integration and reactive rendering; DOM utilities coordinate browser concerns such as focus, dismissal, placement, portals, and scrolling.

Architecture

flowchart TD
  App[Application]
  Core[@zag-js/core]
  MachineDefs[Component machine definitions]
  Service[Machine service and snapshot]
  Connect[connect API]
  Stores[Store and shared types]
  Anatomy[Anatomy and icons]
  Utilities[DOM and interaction utilities]
  Collections[Collections and geometry utilities]
  React[React and Preact adapters]
  Vue[Vue and Solid adapters]
  Svelte[Svelte and vanilla adapters]
  DOM[Rendered DOM]

  App --> React
  App --> Vue
  App --> Svelte
  MachineDefs --> Core
  Core --> Service
  Service --> Connect
  Connect --> React
  Connect --> Vue
  Connect --> Svelte
  Stores --> Core
  Stores --> MachineDefs
  Anatomy --> MachineDefs
  Utilities --> MachineDefs
  Collections --> MachineDefs
  React --> DOM
  Vue --> DOM
  Svelte --> DOM
flowchart LR
  Definition[Machine definition] --> Start[Start service]
  Start --> Snapshot[State/context snapshot]
  Event[User or program event] --> Transition[Guarded transition]
  Snapshot --> Transition
  Transition --> Actions[Actions and effects]
  Actions --> Snapshot
  Snapshot --> Connect[connect API]
  Connect --> Props[Adapter props and state]

Glossary

  • Machine — a declarative interaction model containing states, events, context, guards, actions, effects, and computed values.
  • Service — the running core-runtime interpreter for a machine, responsible for events, transitions, effects, subscriptions, and snapshots.
  • Connect API — a package-level function that turns a machine service snapshot and send capability into public state and prop getters.
  • Anatomy — stable named component parts used to coordinate styling, attributes, and prop composition.
  • Collection — a normalized representation of ordered or hierarchical items used by selection, navigation, and spatial interactions.

Codebase-wide invariants

  • Machine behavior remains framework-neutral: component packages define machines and connect contracts, while framework lifecycle work belongs in adapter packages (packages/core/**, component packages, and packages/react/**, packages/vue/**, packages/solid/**, packages/svelte/**).
  • Consumers interact with a running machine through snapshots and event dispatch rather than mutating runtime state directly; the core service owns transition processing (packages/core/src/**).
  • Public component parts use anatomy names rather than ad hoc string literals, preserving stable styling and prop-composition contracts (packages/anatomy/src/** and component anatomy usage).
  • Overlay behavior must compose browser coordination utilities for focus, dismissal, positioning, and scroll/portal concerns instead of duplicating those mechanisms per component (packages/dom-query/src/**, packages/utils/src/**, and overlay machine packages).
  • Framework adapters normalize machine-generated props at the rendering boundary; component machine APIs remain independent of JSX, templates, or framework reactivity (packages/…/connect.ts, packages/react/src/**, packages/vue/src/**, packages/solid/src/**, packages/svelte/src/**).

Routing table