Skip to content

Apps and Definitions

An application is one root App and the Apps it imports. The Builder evaluates the composition into a Definition, and a Runtime executes the Definition inside a Workspace. This chapter defines composition, resource naming and the contents of a Definition.

  • Every Definition has exactly one root App. RuntimeDefinition.root names it.
  • An App declares its canonical name with configure. The canonical name identifies the App within the Definition, appears in every PRN the App owns and keys ctx.apps.
  • An importer adds an App with addDependency(key, spec). The dependency key is local to the importer; the imported App keeps its canonical name.
  • Two imports that resolve to the same canonical name resolve to one App in the Definition. The Definition holds one copy of that App’s Templates, Events, Roles and operations, and Items of those Templates form one population per Workspace.
  • RuntimeDefinition.resolution lists canonical names in dependency order. An App appears after every App it imports.
  • Every Definition carries a Workspace Template. Its Items anchor each Workspace’s hierarchy.

A PRN names a Definition entity. An App PRN is prn::<app>, where <app> is the canonical name of the App. Every other entity nests below its App:

prn::<app>:<type>/<key>
  • <type> is the entity kind: template, union, mutation, query, role, search, metric or dimension.
  • <key> is the entity’s key within the App.
  • An App Event has the form prn::<app>:app/event/<key>.
  • A Template PRN extends with /property/<key>, /relation/<key>, /event/<key>, /role/<key> or /state/<key>. A state PRN extends with /transition/<key>.
  • A Union PRN extends with /event/<key>.
  • An Event PRN extends with /listener/<key> or /schedule/<key>.

The tutorial’s Template is prn::tutorialTasks:template/task; its completed Event is prn::tutorialTasks:template/task/event/completed.

Every key inside a PRN is a Definition key: 1 to 64 characters matching ^[a-z][a-zA-Z0-9]*$ and not a reserved key. A PRN identifies a Definition entity, never an Item. An Item carries an Identifier and, optionally, a key relative to its parent.

A Definition is immutable once built. RuntimeDefinition holds:

  • root: the canonical name of the root App.
  • apps: every resolved App, keyed by canonical name.
  • resolution: canonical names in dependency order.
  • workspaceTemplate: the Workspace Template.

Each AppDefinition holds the App’s key, prn, description and isRoot, plus its dependencies, templates, unions, events, hooks, mutations, queries, roles, searches, metrics and metricDimensions. A Template holds its Properties, states, fromRelations and toRelations, Roles, Grants, Events, parent Listeners and Union memberships. A Metric’s events map is keyed by Event PRN; every other map in a Definition is keyed by key.

A Definition has structural content and executable content.

  • Structural content is data: keys, PRNs, descriptions, Property types, Relation cardinalities, states and transitions, Role declarations and Union memberships. It serializes to JSON. The Alpyne compiler emits it as definition.json. That file holds the Workspace Template and, for each App, its key, PRN, description, isRoot and Templates; for each Template it holds Properties, states, Relations, Roles, Union memberships and extensibility. Events, Grants, hooks, Listeners, parent Listeners, operations, Metrics, Dimensions, searches and dependency maps are absent from that file.
  • Executable content is code: Query and Mutation handlers, Listeners, parent Listeners, App Hooks, Template Role callbacks, Metric calculation and Dimension handlers. It is packaged as code. A Runtime executes the built RuntimeDefinition object, never the JSON file. JSON.stringify on a Definition produces structural content only.
  • Definition access provides strict and safe lookups over a built Definition by key or PRN.