# App manifests

> Write an app as a manifest: entities, fields, lifecycles, access, pipelines and pages. Validate, publish and install it with the CLI.

Source: https://docs.ligament.ai/developers/app-spec/

An app manifest describes a whole app in one file: its record types and fields, their lifecycles and access rules, its automation and its pages. You keep the file in version control, validate it locally, publish it as a numbered version and install that version in a workspace. Use a manifest when an app should be reviewed like code, installed in several workspaces, or upgraded over time; for a one-off app in one workspace, [Build › Apps](https://docs.ligament.ai/get-started/first-app/index.md) is quicker.

The example below is a small Office moves app for a facilities team. Every field the manifest accepts is listed in the [App manifest reference](https://docs.ligament.ai/reference/app-manifest/index.md).

## Set up

Install the [CLI](https://docs.ligament.ai/developers/cli/index.md) and work in a folder for your app. The CLI reads two settings, from the environment or from a `.env` file in the current folder:

| Variable | Value |
| --- | --- |
| `LIGAMENT_URL` | Your workspace’s address, for example `https://app.ligament.ai` |
| `LIGAMENT_API_KEY` | An API key. Publishing needs the `apps:write` scope and installing needs `apps:install`. These are admin scopes: only a workspace admin can create a key with them. |

`ligament app validate` works without a key.

Scaffold a manifest:

```bash
ligament app init
```

```text
✓ Created app.ts and .env

Next: set LIGAMENT_API_KEY (or ligament login), then ligament app publish.
```

`app.ts` holds a small example app to replace with your own. Fill in `.env`: set `LIGAMENT_API_KEY`, and set `LIGAMENT_URL` to your workspace’s address (the scaffold puts a local development address there).

## Write the manifest

The manifest is a TypeScript (or JavaScript) module whose default export is the app, wrapped in `defineApp` from `@ligament/sdk` for type checking:

*app.ts*

```ts
import { defineApp } from '@ligament/sdk'

export default defineApp({
  key: 'office_moves',
  version: '1.0.0',
  releaseNotes: '1.0: first release: move requests, a three-step lifecycle and a moves overview page.',
  editPolicy: 'full',

  store: {
    name: 'Office moves',
    summary: 'Request, schedule and complete desk moves.',
    description: 'Facilities track every desk move from request to done: who moves, from which desk to which, on what date and how many crates.',
    category: 'Facilities',
    icon: 'truck',
    plans: [{ key: 'standard', name: 'Standard', isDefault: true }],
  },

  nav: {
    label: 'Office moves',
    icon: 'truck',
    items: [
      { label: 'Moves', to: '/r/office_move', icon: 'list' },
      { label: 'New move', to: '/r/office_move/new', icon: 'plus' },
    ],
  },

  entities: [
    {
      key: 'office_move',
      label: 'Office move',
      description: 'One person moving from one desk to another.',
      icon: 'truck',
      backingTable: 'records',
      fields: [
        { key: 'name', label: 'Summary', type: 'string', storage: 'ext', required: true, order: 0 },
        { key: 'employee', label: 'Employee', type: 'reference', storage: 'ext', order: 1, referenceEntityKey: 'person', referenceDisplayField: 'name' },
        { key: 'from_desk', label: 'From desk', type: 'string', storage: 'ext', order: 2 },
        { key: 'to_desk', label: 'To desk', type: 'string', storage: 'ext', required: true, order: 3 },
        { key: 'move_date', label: 'Move date', type: 'date', storage: 'ext', order: 4 },
        { key: 'crates', label: 'Crates', type: 'number', storage: 'ext', order: 5 },
        { key: 'scheduled_on', label: 'Scheduled on', type: 'date', storage: 'ext', order: 6 },
      ],
      states: [
        { key: 'requested', label: 'Requested', color: 'yellow', isInitial: true, order: 0 },
        { key: 'scheduled', label: 'Scheduled', color: 'blue', order: 1 },
        { key: 'done', label: 'Done', color: 'green', isTerminal: true, order: 2 },
      ],
      transitions: [
        { from: 'requested', to: 'scheduled', label: 'Schedule', runWorkflow: 'stamp-scheduled' },
        { from: 'scheduled', to: 'done', label: 'Complete' },
      ],
      acls: [
        { operation: 'read', role: 'member' },
        { operation: 'create', role: 'member' },
        { operation: 'update', role: 'member' },
        { operation: 'transition', role: 'admin' },
      ],
    },
  ],

  pipelines: [
    {
      key: 'stamp-scheduled',
      name: 'Stamp the scheduling date',
      trigger: { type: 'manual', entity: 'office_move' },
      nodes: [
        { id: 'stamp', kind: 'action', action: 'record.update',
          params: { entity: 'office_move', id: '{{trigger.record.id}}', values: { scheduled_on: '{{now}}' } } },
      ],
    },
  ],

  pages: [
    {
      specVersion: 1,
      key: 'office_moves_home',
      title: 'Office moves',
      description: 'Moves waiting to be scheduled and the ones coming up.',
      blocks: [
        { id: 'intro', type: 'heading', props: { text: 'Desk moves' } },
        { id: 'waiting', type: 'metric', span: 4,
          props: { entity: 'office_move', metric: 'count', caption: 'Waiting to be scheduled',
                   filters: [{ field: 'state', op: 'eq', value: 'requested' }] } },
        { id: 'upcoming', type: 'list', span: 12, title: 'Upcoming moves',
          props: { entity: 'office_move', columns: ['name', 'employee', 'to_desk', 'move_date'],
                   sort: [{ field: 'move_date', dir: 'asc' }], limit: 10 } },
      ],
    },
  ],
})
```

### The app

| Field | What it is |
| --- | --- |
| `key` | The app’s permanent key, in lower\_snake\_case. It namespaces everything the app installs. |
| `version` | A semantic version (`1.0.0`). Each published version is immutable. |
| `releaseNotes` | Shown in the App Store and in the upgrade summary. |
| `editPolicy` | How much installers may change what the app ships: `full` (default), `additive` or `locked`. See [Upgrades and your customisations](https://docs.ligament.ai/guides/building-apps/upgrades/index.md#how-much-installers-may-change). |
| `store` | The App Store listing: name, summary, description, category, icon and plans. |
| `nav` | The app’s section in the navigation. |
| `dependsOn` | Keys of apps that must be installed first. Installing from the App Store names them and installs them first. |

### Entities and fields

Each entity is a record type. `backingTable: 'records'` stores its records in the workspace’s shared record store, so installing it needs no database change; give its fields `storage: 'ext'`. A field has a `key`, a `label`, a `type` (`string`, `number`, `money`, `decimal`, `boolean`, `date`, `url`, `email`, `image_url`, `enum` or `reference`; `currency` is the older float type that `money` replaces), its position (`order`) and optional settings such as `required`, `enumOptions` (`[{ value, color, label? }]`: `label` is what people see, else the value is humanized), for a reference `referenceEntityKey` and `referenceDisplayField`, or for money and decimal fields `currency`, `currencyField`, `scale` and `rounding` (see [Money in the API](https://docs.ligament.ai/developers/money/index.md#manifests)). A reference can point at an entity of another app or module, such as `person` from People.

`seed` on an entity (or `seedRecords` on the app) creates starter records on install.

### Lifecycle

`states` lists the states in order; one has `isInitial: true` and terminal states have `isTerminal: true`. Each transition names its `from` and `to` states and an action `label`, and can require a role (`requiresRole`) or run one of the app’s pipelines (`runWorkflow`). Mark a transition that ends or undoes something (Retire, Cancel, Revoke) `destructive: true`: the record page never makes it the accent button and asks before running it, with your `confirm` question if you give one. Every state a transition names must be declared.

### Access

`acls` says which roles may `read`, `create`, `update`, `delete` or `transition` the entity’s records. A rule can also deny (`effect: 'deny'`), cover one field (`fieldKey`) or only rows matching `rowFilters`. Owners and admins always pass, so `{ operation: 'transition', role: 'admin' }` keeps transitions to admins and owners.

On install, each role’s rules become a permission set in the workspace’s spec store, named `<app>.<role>`. For this app:

```json
{
  "key": "office_moves.member",
  "origin": "app",
  "role": "member",
  "grants": [ { "entity": "office_move", "ops": ["read", "create", "update"] } ],
  "app": "office_moves"
}
```

Admins can see and adjust them in **Settings › Access**; see [Roles and permission sets](https://docs.ligament.ai/guides/access/roles-and-permission-sets/index.md).

For a full access model (your own roles and permission sets, restrictions such as “pay is masked except on your own record”, and the role that administers the app), ship it under the manifest’s `access` key instead. The install creates it, upgrades keep the workspace’s changes and never widen access without an admin’s approval, and uninstalling removes it. See [Access in the manifest](https://docs.ligament.ai/guides/building-apps/access-in-the-manifest/index.md).

### Pipelines

`pipelines` are the app’s automation, declared as data: a trigger and a list of nodes. In the example, the Schedule transition runs `stamp-scheduled`, which writes the date into `scheduled_on`. Inside a pipeline, `{{trigger.record.id}}` is the record that triggered it and `{{now}}` the current time. The published manifest carries pipelines in its `workflows` field.

A `wait` node can pause a pipeline until an event arrives: `{ id: 'answer', kind: 'wait', for: { event: 'ticket.answered', match: { recordId: '{{trigger.record.id}}' }, timeout: '3d' } }`. Its output is the event, or empty when the timeout passes first. By default it waits for the next matching event. If the step before it sends a request that someone can answer at once, add `lookback: true`, so an answer that arrives before the wait starts still counts. `lookback` needs a `match`, and it counts any matching event since the pipeline started (never the event that started it). Don’t use it on a wait that means “the next update”, or an earlier update would end the wait.

### Pages

`pages` are page documents, the same format the [page builder](https://docs.ligament.ai/guides/building-apps/page-builder/index.md) edits and its JSON tab shows. They install as the app’s shipped pages, which workspaces can customise and keep across your upgrades.

## Validate

```bash
ligament app validate
```

```text
✔ App "office_moves" v1.0.0 is valid (1 entity, 1 pipeline(s), 0 grant(s))
```

Validation checks the shape of every field and the consistency between them, and exits with code 1 on any problem:

```text
✖ Manifest invalid
  ✗ version: must be semver (e.g. 1.0.0)
```

```text
✖ Manifest failed validation
  ✗ entity "office_move": transition.to "closed" is not a declared state
```

## Publish

```bash
ligament app publish
```

```text
✔ Published office_moves v1.0.0

Install it with ligament app install office_moves
```

A published version can’t be changed or published again:

```text
✖ Publish failed (409)
{"error":"Version 1.0.0 already published for \"office_moves\""}
```

To ship a change, raise `version` (`1.1.0`) and publish again, or pass `--version 1.1.0` to `app publish`. Write `releaseNotes` for each version: installers see them before they upgrade.

**Release notes: every version bump adds a line.** Start `releaseNotes` with an entry for the new version, the version and a colon, and keep the older entries after it, newest first: `'1.1.1: fixes the moves overview total. 1.1: floor changes. 1.0: first release.'` For a `x.y.0` version, `x.y:` is enough (`1.1:` for `1.1.0`); a patch version needs the full number (`1.1.1:`). The apps in the Ligament repository are checked for this rule by a test (`release-notes-lint`), so a version bump without its line fails the build. Because a published version can’t change, fixing forgotten notes means a new patch version with its own line.

## Install and upgrade

```bash
ligament app install office_moves
```

```text
✔ Installed office_moves v1.0.0
```

`ligament app install office_moves@1.0.0` installs a specific version. The app’s entities, fields, lifecycle, permission sets, pipelines and pages are created, and its section appears in the navigation.

`ligament app list` shows your apps with the latest published version and the version installed in this workspace:

```text
  office_moves (latest v1.2.0) installed v1.2.0
```

Workspaces that have the app installed upgrade from the App Store (**Updates available**) or with `POST /api/apps/upgrade`. Their changes to your pages are kept and merged with your new version; see [Upgrades and your customisations](https://docs.ligament.ai/guides/building-apps/upgrades/index.md). `ligament app uninstall office_moves` disables the app in a workspace.

All the `app` commands are in the [CLI reference](https://docs.ligament.ai/reference/cli/index.md).
