
Engine configuration
Theiii-config.yaml defines the engine modules:
iii-config.yaml
| Module | Port | Purpose |
|---|---|---|
| WorkerModule | 49134 | Internal port. The API worker connects here to register functions. |
| WorkerModule (RBAC) | 3111 | Public-facing port. The browser connects here. RBAC controls which functions are exposed and runs an auth function on every new connection. |
| ExecModule | — | Runs pnpm dev to start the API worker process. |
| StreamModule | 3112 | Manages stream state with a file-based KvStore adapter. The engine routes stream::get, stream::set, stream::delete, and stream::list to this module. |
3111 references todo-project::auth-function and explicitly lists the five functions the browser is allowed to call. See Worker RBAC for the full reference.
Backend
Worker setup
The API worker connects to the engine’s internal port and exports a shared logger:src/iii.ts
Auth function (RBAC)
The auth function runs on every new WebSocket connection to the RBAC port. It creates a session ID and usesfunction_registration_prefix so each browser session gets its own namespace — the engine automatically prefixes function IDs registered by that session, preventing collisions.
src/lib/rbac.ts
Stream wrapper
TheTodoStream class provides a typed interface over the engine’s built-in stream operations. Each method triggers the corresponding stream::* function:
src/routes/todos.stream.ts
Functions
All functions are registered withfn(), a thin wrapper around iii.registerFunction. There are no HTTP routes — the browser calls these functions directly over the WebSocket connection.
- create
- list
- get
- toggle
- delete
src/routes/todos.create.ts
Frontend
Connection
The browser connects to the RBAC port usingiii-browser-sdk. This single connection is used for both triggering functions and receiving real-time stream updates:
src/lib/iii.ts
Real-time hook
TheuseTodos hook manages the full lifecycle — initial fetch, live updates, and CRUD operations — all through the same WebSocket connection:
src/hooks/use-todos.ts
- Fetches the current list by triggering
todos::list. - Subscribes to real-time changes by registering a local function (
ui::on-todo-change) and binding it to astreamtrigger on thetodostream. The engine pushesStreamChangeEventpayloads (create, update, delete) whenever the stream changes. - Cleans up by unregistering both the function and the trigger on unmount.
addTodo, toggleTodo, deleteTodo) call iii.trigger with the corresponding function ID. The response arrives over the same connection, and the stream trigger delivers the update to all connected clients.
Key concepts
- Single connection — The browser opens one WebSocket to the RBAC port. Function calls and real-time stream events flow over the same connection.
- No HTTP routes — The API worker registers plain iii functions. The browser invokes them directly via
iii.trigger. There is no REST layer. - RBAC — The engine’s WorkerModule supports auth functions, expose lists, and middleware. This example uses a simple auth function that creates a session. See Worker RBAC for the full reference.
- Engine-managed streams — The
StreamModulehandles persistence (file-based KvStore in this example). The API worker reads and writes throughstream::*function triggers — no custom stream implementation required. - Session isolation — The auth function returns a
function_registration_prefix. The engine prefixes every function registered by that browser session, so multiple clients can registerui::on-todo-changewithout colliding.