Why zwire
Modern interactive applications increasingly span more than one runtime: a TypeScript frontend (React, Vue, Solid, or Svelte) talking to an SSR edge worker, a Rust backend, or a Rust WebAssembly engine in the browser. Most state libraries force you to maintain separate mental models, ad-hoc optimistic rollback logic, brittle list sorting, and custom JSON sync glue across each boundary.
zwire implements one 3-layer star-topology reactive architecture identically in TypeScript (@zwire/*) and Rust (zwire), bound together by a language-neutral JSON wire specification (spec/protocol.md) and shared conformance suite (spec/conformance.json).
What makes zwire different
Section titled “What makes zwire different”- Zero-global per-request scopes (
core) — There is no module-level mutable reactive state. Every graph runs inside an isolatedReactiveScope(TypeScript) orScope/SyncScope(Rust). Concurrent SSR requests (createScope({ mode: 'ssr' })/Scope::ssr()) can never leak listeners or batch depth across requests, and unwatchedcomputednodes use forward-only dependency links so abandoned derived values are garbage-collected (64/64WeakRefverified in V8 and JSC). - Rebaseable optimistic layers & STM drafts (
tx) — Overlapping optimistic mutations stack in creation order and automatically rebase when authoritative server pushes arrive mid-flight. You get surgical single-layerrevert(), zero-flicker atomicsettle()/try_settle(), and read-set verified STMDrafts. - Exact incremental Top-K collections (
collections) — A 2-level Chunked Sorted Block Index (BLOCK_TARGET = 128) with deterministic key tie-breaking andO(1)boundary pruning keeps sorted Top-K views fast under heavy churn (0.51 ms/406 KBbuild and0.038 µs/updateon 50k rows in V8;171.9 ns/opin RustPureReactiveCollection). - Strict 2-tier star topology (0B unused extension cost) — Core (
@zwire/core,zwire-core) never imports companion subpaths, UI adapters, or companion crates, and companions never import each other. Cross-feature composition happens solely through five lazy extension slots, keeping tree-shaken bundles tiny and Rust crates#![forbid(unsafe_code)],#, and zero-dependency. - One open wire protocol across languages (
protocol) — Deterministic RFC-8259 hydration (hydratable/dehydrate/hydratewith out-of-order delete-on-consume buffering and lossless 64-bit integer safe-integer boundaries), coalesced echo-safeSyncBridge, plus optionalzwire-wasmandzwire-serdebridges.
When another tool is a better fit
Section titled “When another tool is a better fit”zwire is engineered for correctness, scope isolation, transactional optimistic UX, sorted collections, and cross-language parity. Be honest about trade-offs (full benchmark report):
- Simple client-only app state with zero SSR/optimistic/collection needs: A minimal single-file signal or Zustand/Jotai store may be all you need if you never require per-request isolation, rebaseable transactions, or incremental Top-K.
- Full HTTP cache & query-key orchestration:
@zwire/core/resourceprovides a leanNotReady-aware async primitive, not a full server-cache suite with pagination plugins, background refetch policies, or mutation caches like TanStack Query. - Legacy deeply-nested mutable drafts:
@zwire/core/storeprovidescreateDeepStoreandreconcilefor opt-in ergonomics, but flat normalized atoms,createObjectStore, andcreateCollectionare dramatically faster (see ADR-001 and Benchmarks).
What automated verification proves
Section titled “What automated verification proves”Every pull request and release in zwire runs:
- Cross-language conformance: Both TypeScript (
Node 26V8 +Bun 1.3JSC) and Rust (1.100.0, Edition 2024) execute the exact same test vectors inspec/conformance.jsoncovering optimistic rebase, STM read-set conflicts, Top-K pruning, and RFC-8259 64-bit integer wire round-trips. - Correctness & GC regression gates: 15 engine gates including diamond glitch-freedom, early cutoff, exception-safe batch flushing, SSR multi-scope isolation, and
WeakRefunwatched-computed garbage collection. - Producer & consumer declaration parity:
tsrsand stocktscemit matching.d.tssurfaces across all 5 packages, verified under bothNodeNextandBundlerconsumers on Node 20, 22, 24, 26, and Bun. - Rust safety & portability:
#![forbid(unsafe_code)], Clippy pedantic/nursery/cargo (-D warnings),#![no_std]+wasm32-unknown-unknowncompilation, offline crate packaging, and live cross-process Rust ↔ TypeScript sync (examples/rust-ts-sync).