Skip to content

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.

examples/hello-alpyne.ts
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.

  • App: a unit of application code. It receives an AppBuilder and declares everything below through it. Every App names itself with configure, and the root App imports other Apps with addDependency.
  • 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> and current.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, sudo and system.

Handlers never write storage-specific queries. A handler that reads item.properties.title runs unchanged on PostgreSQL, SQLite and the test Runtime.

The tutorial builds one App and runs it against the test Runtime. It needs:

  • A checkout of the Alpyne repository with Node 24, as .nvmrc declares, and pnpm 11, as package.json declares. Run pnpm install at the repository root once.
  • The public types under alpynehq/alpyne/packages/platform/types: @alpynehq/alpyne-types/builder for AppSpec and the Builder interfaces, @alpynehq/alpyne-types/definition for handler contracts, and @alpynehq/alpyne-types/runtime for Items, contexts and selectors.
  • The harness packages: @pyn-backend/platform-harness-public exports createHarnessInstance. @pyn-backend/platform-service-test, @pyn-backend/service-cron-test, @pyn-backend/service-system-test and @pyn-backend/test-services-logger supply 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.

  • 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.