# Getting started

> Install @zwire/core in TypeScript or zwire in Rust and run your first scoped reactive graph with rebaseable optimistic layers.

`zwire` ships identical core semantics across **TypeScript (`@zwire/*` on npm)** and **Rust (`zwire*` on crates.io)** with zero runtime dependencies.

## Install & first example

### TypeScript

Install the core package (and optionally a UI adapter for React, Vue, Solid, or Svelte):

```sh
npm install @zwire/core
# Optional UI framework adapters:
# npm install @zwire/react   # or @zwire/vue, @zwire/solid, @zwire/svelte
```

Create a signal, a derived computed, and an auto-rebasing optimistic layer:

```ts
import { atom, batch, computed } from '@zwire/core';
import { createOptimisticLayer } from '@zwire/core/tx';

const balance = atom(1000);
const display = computed(() => `$${balance.get()}`);

const hold = createOptimisticLayer();
hold.update(balance, (b) => b - 150); // UI: $850

// Concurrent authoritative server push -> active optimistic layers auto-rebase!
batch(() => balance.set(1500)); // UI: $1350

// Zero-flicker atomic settle:
hold.settle(() => balance.set(1350));
console.log(display.get()); // "$1350"
```

### Rust

Add the feature-gated `zwire` umbrella crate (or individual zero-dep crates such as `zwire-core`, `zwire-tx`, `zwire-collections`, `zwire-protocol`):

```sh
cargo add zwire
```

Run the identical rebaseable optimistic transaction inside a `Scope`:

```rust
use zwire::prelude::*;

let scope = Scope::new();
let balance = scope.atom(1_000_i64);
let display = scope.computed(move |cx| format!("${}", cx.get(balance)));

let mut hold = OptimisticLayer::new(&scope);
hold.update(balance, |b| b - 150); // UI: $850

// Concurrent authoritative server push -> active optimistic layers auto-rebase!
scope.set(balance, 1_500);
assert_eq!(scope.get(display), "$1350");

// Zero-flicker atomic settle:
hold.settle_with(|| scope.set(balance, 1_350));
```

## UI framework adapters

Every adapter package peer-depends on `@zwire/core` and mirrors its subpaths 1:1 (`/tx`, `/collections`, `/resource`, `/protocol`):

- [`@zwire/react`](/typescript/react/) — React 18/19 Compiler-safe hooks + concurrent-abort-safe `SelectorStabilizer`
- [`@zwire/vue`](/typescript/vue/) — Vue 3.5+ read-through `customRef` + `v-model` atoms
- [`@zwire/solid`](/typescript/solid/) — Solid 2 read-through accessors + owner-scoped subscriptions
- [`@zwire/svelte`](/typescript/svelte/) — Svelte 5.7+ `createSubscriber` refs + store contract

## Next steps

- [Why zwire](/why-zwire/) — design goals, honest trade-offs, and what CI verifies.
- [Scopes, SSR & Ownership](/guides/scopes-and-ssr/) — per-request isolation and `scoped()` definitions.
- [Optimistic Layers & STM Drafts](/guides/optimistic-tx/) — interactive rebase demo and STM conflict verification.
- [Incremental Top-K Collections](/guides/collections/) — interactive 50k-row collection demo.
- [Wire Protocol v3](/protocol/specification/) — canonical RFC-8259 JSON hydration and 64-bit integers.
- [API Reference](/reference/ts-core/) — complete TypeScript, Rust, and conformance API surface.
