Introduction
Alpyne runs applications declared in TypeScript. You write an App that declares what it stores, what it does and who may do it. A Runtime stores the Items, runs the operations and Listeners and keeps the Event history, one Workspace at a time.
import type { AppSpec } from '@alpynehq/alpyne-types/builder';
interface ApproveInput { readonly id: string;}
export const leaveApp: AppSpec = (app) => { app.configure('leave');
const leaveRequest = app.addTemplate('leaveRequest'); leaveRequest.addProperty('reason', 'string');
const pending = leaveRequest.addState('pending').setDefault(); const approved = leaveRequest.addState('approved'); pending.addTransition('approve', approved);
const approve = app.addMutation('approve', async (input: ApproveInput, current, ctx) => { const item = await current.templates.leaveRequest.getItem(input.id); if (item === undefined || item.state?.value !== 'pending') throw new Error('Leave request is not pending'); const updated = await item.state.transitions.approve.execute({}); ctx.log(`${updated.id} is now ${updated.state?.value}`); // => "<id> is now approved" }); approve.input.addProperty('id', 'id').mandatory(); approve.output.void();};The file declares a Template with one Property, two states, a transition and a Mutation that executes the transition. The Mutation runs inside a write execution, so the state change and everything else the handler writes commit together.
The parts of an App
Section titled “The parts of an App”- App: a unit of application code. It receives an
AppBuilderand declares everything below through it. Every App names itself withconfigure, and the root App imports other Apps withaddDependency. - Template: a kind of persisted Item. A Template declares typed Properties, Relations to other Templates, states and transitions, Events, Roles and Grants.
- Item: one instance of a Template inside a Workspace. Items form a hierarchy below the Workspace Item, carry an optional key relative to their parent and expose their state as
item.state?.value. - operation: a Query or a Mutation. A Query runs in a read execution and returns declared output. A Mutation runs in a write execution, where it changes Items, executes transitions and publishes Events.
- Event: a named occurrence appended to the Workspace’s Event history with a payload. Listeners run after an Event commits, and Metrics count or sum the Events they select.
- Runtime: the implementation that executes a Definition. Three exist, PostgreSQL, SQLite and test, and a handler sees the same interfaces on each.
- Workspace: the tenant and execution boundary. Every Item, Event and Metric belongs to one Workspace, and every execution acts as one principal inside it.
The Builder evaluates your App and produces a Definition, which the Runtime loads and executes. Application model explains how the two connect.
What you write and what the Runtime supplies
Section titled “What you write and what the Runtime supplies”You write two kinds of code. Declarations name the Templates, Properties, states, Events, operations, Roles and Metrics of an App. Handlers implement Mutations, Queries and Listeners as async functions. Each handler receives parsed input, the current App and an execution context.
The Runtime supplies everything a handler touches:
- Storage for Items, their Properties, keys and states, and the Relations between them.
- The execution context, typed for read or write access:
ctx.getItem(id),ctx.getWorkspaceItem(),current.templates.<key>andcurrent.mutations.<key>. - A transaction around each write execution, so the Items a Mutation writes and the Events it publishes commit or roll back together.
- The reactor, which claims committed Events and runs their Listeners, and the projector, which turns selected Events into Metric rows.
- Authorization: Roles, Grants and the four auth contexts
principal,masquerade,sudoandsystem.
Handlers never write storage-specific queries. A handler that reads item.properties.title runs unchanged on PostgreSQL, SQLite and the test Runtime.
What you need
Section titled “What you need”The tutorial builds one App and runs it against the test Runtime. It needs:
- A checkout of the Alpyne repository with Node 24, as
.nvmrcdeclares, and pnpm 11, aspackage.jsondeclares. Runpnpm installat the repository root once. - The public types under
alpynehq/alpyne/packages/platform/types:@alpynehq/alpyne-types/builderforAppSpecand the Builder interfaces,@alpynehq/alpyne-types/definitionfor handler contracts, and@alpynehq/alpyne-types/runtimefor Items, contexts and selectors. - The harness packages:
@pyn-backend/platform-harness-publicexportscreateHarnessInstance.@pyn-backend/platform-service-test,@pyn-backend/service-cron-test,@pyn-backend/service-system-testand@pyn-backend/test-services-loggersupply the services it takes. - The test command:
pnpm run cli test <path>runs one Vitest file from the repository root.
The Builder implementation, the three Runtimes and the harness live in the repository under @pyn-backend. The applications under apps/*/alpyne declare themselves the same way the tutorial does.
Next steps
Section titled “Next steps”Related
Section titled “Related”- API reference for the Builder, Definition and Runtime interfaces the tutorial calls.
- Scope and conformance for the contract every conforming Runtime meets.
- Data model for Templates, Items, Properties and hierarchy in depth.
- Execution model for read and write executions and the Event lifecycle.

