Files
mizan/frontends/mizan-react
Ryth Azhur e00b3a177e Docs carry the shape of the system, not its status
MIZAN.md's phase-numbered implementation order, PRODUCT_ARCHITECTURE's
"Deferred until Render revenue funds it" and "Shipped in", PSR_VS_EDGE's
current-state section, and the READMEs' passing-test counts were all reporting
where the work stood rather than what the system is. OWED_SURFACE keeps its
subject — surface that is specified but unbuilt — stated as the shape each unit
owes.

The channel sections follow the renamed slots: Params / ClientMessage /
ServerMessage, and Channel as the base class on both backends.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-07-27 14:03:29 -04:00
..
2026-06-04 03:38:26 -04:00

@rythazhur/mizan (TypeScript)

React client for the mizan framework. See the monorepo root for full documentation.

Install

npm install @rythazhur/mizan@git+https://git.impactsoundworks.com/isw/mizan.git#workspace=react

Usage

You don't use this package directly. You use the generated hooks.

This React adapter ships its own MizanProvider (src/context.tsx) that owns HTTP/WebSocket/CSRF/session/context state directly, rather than subscribing to the @mizan/base kernel.

1. Configure

# mizan.toml
output = "src/api"
targets = ["react"]

[source.django]
manage_path = "../backend/manage.py"
command = ["uv", "run", "python"]

2. Generate

The codegen is the mizan-generate Rust binary (source at protocol/mizan-codegen/; protocol/mizan-generate/ is the npm launcher):

mizan-generate --config mizan.toml

3. Wrap your app

import { MizanProvider } from '@rythazhur/mizan'

<MizanProvider>
    <App />
</MizanProvider>

MizanProvider is the only provider you need. It handles HTTP, WebSocket, CSRF, session init, context auto-fetching, and channel connections.

4. Use generated hooks

import { useCurrentUser, useEcho, useContactForm, useChatChannel } from '@/api'

// Context (SSR-hydrated, auto-refreshed)
const user = useCurrentUser()

// Server function
const echo = useEcho()
const result = await echo({ text: 'hello' })

// Form (Zod + server validation)
const form = useContactForm()
form.set('email', 'test@example.com')
await form.submit()

// Channel (WebSocket)
const chat = useChatChannel({ room: 'general' })
chat.send({ text: 'hello' })
chat.messages  // typed, reactive

Generated Files

The Rust codegen emits per-target files into the configured output directory:

File Contents
types.ts Pydantic types
contexts/<name>.ts Per-context fetchXxx bundles
react.tsx <MizanContext> provider + typed use{Hook}() hooks
channels.ts / channels.hooks.tsx Channel types + hooks (when the schema carries channels)
index.ts Re-export root

Sub-exports

Import When to use
@rythazhur/mizan Core: MizanProvider, hooks, forms, errors
@rythazhur/mizan/channels WebSocket channels
@rythazhur/mizan/jwt JWT token management
@rythazhur/mizan/client HTTP clients (CSR/SSR)

These are library internals used by the generated code. You should import from @/api (your generated index), not from the library directly.

Running Tests

# Unit tests (Vitest, jsdom)
npm test

# E2E tests (Playwright, real browser)
# Requires Docker backend running
npx playwright test