How It Works
Idyllic connects TypeScript classes to React frontends through WebSockets, with automatic state synchronization and type safety. This page explains the architecture.The Big Picture
When you write an Idyllic application, you work with three pieces:- Your system class - a TypeScript class defining state and behavior
- The Idyllic runtime - infrastructure that persists state and handles connections
- Your React frontend - components that subscribe to state and call actions
The Transform Pipeline
When you runidyllic dev or idyllic deploy, your TypeScript class transforms into runtime code:
The transform:
- Extracts
@fielddeclarations to generate state schema - Extracts
@action()methods to generate action interface - Generates a Cloudflare Worker hosting your Durable Object
- Generates client types for full
useSystem<T>()type safety
WebSocket Connection Flow
When a React component mounts withuseSystem(), a WebSocket connection establishes:
Key behaviors:
- Initial sync: On connect, client receives complete current state
- Delta updates: After that, only changed fields transmit
- Streaming:
stream<T>fields send incremental chunks as appended - Multi-client: All connected clients receive same updates
- Reconnection: On disconnect, client reconnects and re-syncs
State Synchronization
When you assign to a@field property, the framework detects the change and broadcasts it:
@fieldwraps the property in a proxy intercepting assignments- The proxy captures old and new values
- New value persists to SQLite in the Durable Object
- Delta message broadcasts to all connected WebSocket clients
- React hook applies delta and triggers re-render
append() broadcasts the chunk:
The Durable Object Actor
Each system instance runs as a Cloudflare Durable Object—a single-threaded, globally-addressable actor with persistent storage. Properties of Durable Objects:- Single-threaded: One method runs at a time—no race conditions
- Globally unique: Each instance ID maps to exactly one object worldwide
- Hibernation: Between requests, the object hibernates using no resources
- Durability: State persists through restarts and deployments
- Colocated storage: SQLite runs in same location as object
What Idyllic Adds
You could build on raw Durable Objects, but you’d write substantial code:- WebSocket connection handling and reconnection
- State serialization and delta synchronization
- Client-side state management and re-rendering
- Type generation for client-server contract
- Streaming primitives with lifecycle management
Multi-Client Synchronization
Multiple clients connecting to the same instance see identical state: This enables collaborative applications where multiple users observe the same AI workflow.Scheduling and Autonomy
Systems can schedule future execution:Local Development
idyllic dev runs a local server mimicking production:
State persists across restarts. WebSockets work identically. Your code runs unmodified.