For a person or a model about to write an app; a model gets the same text from oad guide.

Contents

Writing your first app#

An Open App Definition (OAD) app is one JSON document, its definition. It names the values the app keeps (state), the things it can do (actions), what happens on its own (rules and flows), what it needs from outside (capabilities) and the permissions it asks for (grants). Screens and agents are views of the same app: a screen shows state and runs actions, and an agent calls the same actions as tools. A host loads the definition, asks a person for the permissions, keeps the state and runs the app. Logic is short expressions inside the JSON, never a program.

The smallest app#

This app counts glasses of water. It is complete: it passes oad validate and runs.

JSON

{
  "oad": "0.2",
  "id": "com.example.water",
  "version": "1.0.0",
  "meta": {
    "name": "Water today",
    "description": "Counts the glasses of water you drink today against a daily goal."
  },
  "uses": {
    "catalogs": {
      "core": { "id": "org.openappdefinition.core", "version": "^0.2.0" }
    }
  },
  "state": {
    "goal": { "type": "integer", "initial": 8, "description": "Glasses to drink each day." },
    "glasses": { "type": "integer", "initial": 0, "description": "Glasses drunk on the day in countedOn." },
    "countedOn": { "type": "date", "initial": "=env.today", "description": "The day the count belongs to." },
    "today": {
      "type": "integer",
      "derive": "state.countedOn == env.today ? state.glasses : 0",
      "description": "Glasses drunk today."
    }
  },
  "actions": {
    "drink": {
      "description": "Count one more glass of water today.",
      "steps": [
        { "set": "state.glasses", "to": "=state.today + 1" },
        { "set": "state.countedOn", "to": "=env.today" }
      ]
    }
  },
  "surfaces": {
    "visual": {
      "start": "home",
      "views": {
        "home": {
          "title": "Water today",
          "body": {
            "control": "core:stack",
            "children": [
              { "control": "core:progress", "props": { "label": "Glasses today", "value": "=state.today", "max": "=state.goal" } },
              { "control": "core:text", "props": { "value": "=`${state.today} of ${state.goal} glasses`" } },
              { "control": "core:button", "props": { "label": "I drank a glass", "emphasis": "high" }, "on": { "press": { "run": "drink" } } }
            ]
          }
        }
      }
    }
  }
}

What each part does:

  • oad ("0.2"), id (reverse-DNS, lowercase, two segments or more), version and meta (with name and description) are required.
  • uses names the core catalog under the alias core, which every core: name needs.
  • state holds the values: goal, glasses and countedOn are stored and start at their initial; today is derived, worked out again when what it reads changes.
  • actions holds what the app can do: drink has a description (required) and steps that write state.
  • surfaces.visual is the screen: start names the first view, whose body is a tree of nodes, each a control with props. The button's on.press runs the action. An app with one view and no navigation, like this one, is drawn as one card headed by the view's title, with no app bar; any other app is a page (see views).

The = rule. In a prop, a step's to, a with or an initial, a string that starts with = is an expression and any other string is text: "=state.today" is a number, "state.today" is the words "state.today". Fields that are always expressions (derive, when, if, allow, where, becomes, a require entry's that) take no =. An input field's default is neither: a plain value, never an expression.

A list you can add to and change#

Most apps keep a list. This one is a shopping list a household shares: add a thing, tick it off, take it off.

JSON

{
  "oad": "0.2",
  "id": "com.example.groceries",
  "version": "1.0.0",
  "meta": {
    "name": "Groceries",
    "description": "A shopping list the whole household shares: add what to buy, tick it off, take it off."
  },
  "uses": {
    "catalogs": {
      "core": { "id": "org.openappdefinition.core", "version": "^0.2.0" }
    }
  },
  "types": {
    "Item": {
      "type": "object",
      "properties": { "id": { "type": "string" }, "name": { "type": "string" }, "bought": { "type": "boolean" } },
      "required": ["id", "name", "bought"],
      "additionalProperties": false
    }
  },
  "state": {
    "items": {
      "type": "Item[]",
      "initial": [],
      "scope": "shared",
      "conflict": "merge",
      "key": "id",
      "description": "Everything on the household's list, bought or not."
    },
    "bought": { "type": "integer", "derive": "state.items.count(i, i.bought)", "description": "How many things are ticked off." }
  },
  "actions": {
    "addItem": {
      "description": "Put something on the shopping list.",
      "input": { "name": { "type": "string", "description": "What to buy, such as milk." } },
      "require": [ { "that": "size(trim(input.name)) > 0", "message": "Say what to buy." } ],
      "steps": [ { "append": "state.items", "value": { "id": "=uuid()", "name": "=trim(input.name)", "bought": false } } ]
    },
    "tick": {
      "description": "Tick something off as bought, or untick it.",
      "input": { "id": { "type": "string", "description": "Which item, by its id." } },
      "steps": [ { "patch": "state.items", "where": "item.id == input.id", "with": { "bought": "=!item.bought" } } ]
    },
    "removeItem": {
      "description": "Take something off the list.",
      "input": { "id": { "type": "string", "description": "Which item, by its id." } },
      "confirm": { "message": "=`${state.items.find(i, i.id == input.id).name} is taken off the list for everyone.`" },
      "steps": [ { "remove": "state.items", "where": "item.id == input.id" } ]
    },
    "clearBought": {
      "description": "Take everything ticked off the list, after a shop.",
      "confirm": { "message": "=`Everything ticked off (${state.bought}) is taken off the list for everyone.`" },
      "steps": [ { "remove": "state.items", "where": "item.bought" } ]
    }
  },
  "surfaces": {
    "visual": {
      "start": "home",
      "views": {
        "home": {
          "title": "Groceries",
          "state": { "name": { "type": "string?", "description": "What is being typed." } },
          "body": {
            "control": "core:stack",
            "children": [
              {
                "control": "core:form",
                "props": { "submitLabel": "Add" },
                "on": { "submit": [ { "run": "addItem", "with": { "name": "=default(view.name, '')" } }, { "set": "view.name", "to": null } ] },
                "children": [ { "control": "core:textInput", "props": { "label": "Add to the list", "required": true }, "bind": { "value": "view.name" } } ]
              },
              {
                "control": "core:list",
                "props": { "label": "Shopping list", "items": "=state.items", "empty": "The list is empty." },
                "slots": {
                  "item": {
                    "control": "core:stack",
                    "props": { "direction": "horizontal" },
                    "children": [
                      { "control": "core:text", "props": { "value": "=item.bought ? `${item.name} (bought)` : item.name" } },
                      { "control": "core:button", "props": { "label": "=item.bought ? 'Undo' : 'Bought'", "icon": "check" }, "on": { "press": { "run": "tick", "with": { "id": "=item.id" } } } },
                      { "control": "core:button", "props": { "label": "Remove", "destructive": true, "emphasis": "low" }, "on": { "press": { "run": "removeItem", "with": { "id": "=item.id" } } } }
                    ]
                  }
                }
              },
              { "control": "core:button", "when": "state.bought > 0", "props": { "label": "Clear ticked off", "emphasis": "low" }, "on": { "press": { "run": "clearBought" } } }
            ]
          }
        }
      }
    }
  }
}

What is new here:

  • types declares a record, Item; state.items is a list of them, Item[]. With "additionalProperties": false the check reports a misspelt field.
  • "scope": "shared" makes one list for everyone, and conflict with key keeps both of two things added at once. Without the three, each person keeps a list of their own.
  • addItem reads input.name; its require refuses an empty name, in words the person reads. uuid() gives the record an id.
  • patch and remove change every element for which where is true, with item the element: tick changes one row, clearBought removes all those ticked off.
  • removeItem asks first (confirm), in words that name the item, since a question is read on its own. The words may read the input and any state.
  • What is typed lives in view state, view.name: bind ties the input to it, required keeps the form from sending it empty, and submit runs the action, then clears it.
  • A core:list draws its item slot for each element of items, with item that element. A button in a row keeps a short label, since the row says which item it is for, and passes item.id to its action.

Fields of a record#

A record type under types is JSON Schema, field by field. Everywhere else a type (of a state entry, an input field, a view's input or state) is a short name such as date, string? or Item[], and the two do not mix: { "type": "date" } inside a record is schema.invalid. A number, an enum, a date, a field that may be null (still in required), a list of dates and a list of other records:

JSON

{
  "type": "object",
  "properties": {
    "id": { "type": "string" }, "minutes": { "type": "number", "minimum": 0 },
    "size": { "type": "string", "enum": ["small", "big"] }, "due": { "type": "string", "format": "date" },
    "doneAt": { "type": ["string", "null"], "format": "date-time" }, "doneOn": { "type": "array", "items": { "type": "string", "format": "date" } },
    "needs": { "type": "array", "items": { "$ref": "#/types/Item" } }
  },
  "required": ["id", "minutes", "size", "due", "doneAt", "doneOn", "needs"],
  "additionalProperties": false
}

A derived entry's type is a short name too, such as Item? or string[] (see state).

Controls#

The controls a first app uses most; controls has every prop of each.

Control Must be given Often given Raises
core:stack nothing children, direction, gap
core:text value style
core:button label emphasis, icon, destructive press
core:form nothing children, submitLabel, cancelLabel submit, cancel
core:textInput label value (bindable), required, multiline change (event.value)
core:numberInput label value (bindable), min, max change (event.value)
core:dateInput label value (bindable), mode, min change (event.value)
core:choice options, label value (bindable), required change (event.value)
core:toggle label value (bindable) change (event.value)
core:list items, slot item itemKey, empty select (event.item, event.index), move
core:table items, columns, label itemKey, empty select (event.item, event.index, event.selected), sort, page
core:chart kind, items, category, series, label format select (event.item, event.series, event.selected)
core:stat label, value format
core:badge label tone
core:alert title message, tone dismiss
  • core:choice: options are maps with value and label, such as state.items.map(i, {value: i.id, label: i.name}); the bound value is the picked value.
  • core:dateInput gives YYYY-MM-DD (mode date), a UTC datetime such as 2026-11-24T09:00:00Z (datetime) or HH:MM on a 24-hour clock (time).
  • A core:list draws its slot for each element, a few words and buttons; a core:table shows columns, sorts and pages, and picking a row raises select with event.item, to open it in a view of its own (see views). Both tell elements apart by itemKey: id unless you name another field.
  • In a core:chart, category and each series' field name fields of the elements of items; they are not labels.
  • Money: "format": "currency" on a core:stat, a table column or a core:numberInput; in text, formatNumber(12.5, {style: 'currency'}). Each uses the person's currency when the host knows it, a plain number when not (see controls).

Working with lists#

Expression (each is true) What it shows
[3, 1, 2].filter(n, n > 1) == [3, 2] filter keeps the elements for which the body is true.
[3, 1, 2].count(n, n > 1) == 2, [3, 1, 2].exists(n, n > 2) count says how many pass, exists whether any does.
[3, 1, 2].find(n, n > 1) == 3, [3, 1, 2].find(n, n > 5) == null find gives the first that passes, or null.
[{n: 'b'}, {n: 'a'}].sortBy(x, x.n) == [{n: 'a'}, {n: 'b'}] sortBy puts the smallest key first.
['a', 'b'].map(s, {value: s, label: upper(s)}) == [{value: 'a', label: 'A'}, {value: 'b', label: 'B'}] map makes a new list, here of maps, such as the options of a choice.
default({a: 1}.b, 0) == 0, has({a: 1}.a) default gives its second value when the first is missing or null; has says whether a member is there.

In each macro the first argument names the element, as you choose; expressions has every function.

Where to start#

Each example is a whole app, read by its name with the guide tool or oad guide --example <name>; one close to the request is the fastest start.

Example What it shows Nearest start for Read too
groceries The list above A list several people use people
reading A table whose row opens one book, which a form changes A list with a view for one record views
plants A reminder per plant, permissions asked when needed Reminders, or work done by itself at a time rules, capabilities
timeoff Roles, a flow, a section for approvers Records that move through stages and are decided by someone people, flows
weather A web service and its sample document Something read from the web capabilities, sample-data
gift The app jar inside it as a part An app that uses another whole app parts

A time of day has no type: keep it as text HH:MM, as a time input gives it. To act at that time every day, schedule a wake whose rule schedules the next (see rules). A sample-data.json beside the definition is used without being named (see sample-data).

Keys and names#

meta may also hold icon, tags, authors and license. parts covers the keys parts and exports; no topic covers code yet.

Names of things (state entries, actions, views, fields) start with a lowercase letter and hold only letters and digits, such as countedOn: no spaces, dashes or underscores. Type names start with a capital letter. Unknown keys are an error everywhere.

How to work#

Write the whole definition in one file, from the closest example. Check it and look at it with the tools you were given or, at a terminal, oad validate, oad look and oad run, and fix every error and warning (see mistakes); a new app the tools refused for its checks is kept unfinished, to mend with small patches. Look after every change; when several people use the app, look as each kind of person; when it does something by a time, move the look's clock. Change one thing at a time; changing shows how to edit an app in use.

Rules of thumb#

  • Put logic in actions, not in views. A handler is usually one run, perhaps then a navigate, so an agent can do the same.
  • Describe, and handle what can fail. description is required on actions, rules, flows and capabilities, reason on grant requests: the person reads them. Give a call that may fail an onError (see actions).

Mistakes every newcomer makes#

Mistake What you see Fix
A prop meant as an expression without its =: "value": "state.today" The words "state.today" on the screen, and no diagnostic Write "=state.today".
A = in a field that is always an expression, such as "derive": "=state.glasses" expression.syntax Drop the =.
Joining text and a number with + expression.typeMismatch Use a template: "=`${state.today} glasses`".
A key the format does not have, or a missing description schema.invalid Use the keys of this guide; describe every action.
A core: control with no uses.catalogs entry for core contract.unknown Add the uses block of the smallest app.
A state entry that does not exist, often a typo reference.unknownState Use the name declared under state.
Calling a capability with no grant request for its scope grant.uncovered Add a grant request (capabilities).
Writing a shared list straight from a screen write.sharedDirect Run an action that writes it.
Reading an optional input that was left out, such as input.note expression.error when the action runs Give the field a plain default, or read it with default(input.note, '').
An expression as an input field's default: "=env.today" value.typeMismatch Type date? with "default": null, and default(input.day, env.today) in the step.
uuid() or random() in a derive, a guard or a prop expression.effectNotAllowed Call them in a step, and store the result.

Next#