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

Contents

Example apps

The 12 small apps the guide quotes, from packages/authoring/guide/examples/. Each is a whole definition that passes oad validate with no error and no warning; oad guide --example <name> prints one.

water: Water today#

Counts the glasses of water you drink today against a daily goal.

The definition, water.oad.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" } } }
            ]
          }
        }
      }
    }
  }
}

reading: Reading list#

Keeps the books you want to read, are reading and have read, and lets an agent add to the list.

The definition, reading.oad.json
{
  "oad": "0.2",
  "id": "com.example.reading",
  "version": "1.0.0",
  "meta": {
    "name": "Reading list",
    "description": "Keeps the books you want to read, are reading and have read, and lets an agent add to the list."
  },
  "uses": {
    "catalogs": {
      "core": { "id": "org.openappdefinition.core", "version": "^0.2.0" }
    }
  },
  "types": {
    "Book": {
      "type": "object",
      "properties": {
        "id": { "type": "string" },
        "title": { "type": "string", "minLength": 1 },
        "author": { "type": "string" },
        "status": { "type": "string", "enum": ["toRead", "reading", "read"] },
        "addedOn": { "type": "string", "format": "date" }
      },
      "required": ["id", "title", "author", "status", "addedOn"],
      "additionalProperties": false
    }
  },
  "state": {
    "books": { "type": "Book[]", "initial": [], "description": "Every book on your list." },
    "toRead": { "type": "integer", "derive": "state.books.count(b, b.status == 'toRead')", "description": "Books not started yet." },
    "finished": { "type": "integer", "derive": "state.books.count(b, b.status == 'read')", "description": "Books you have read." },
    "heading": {
      "type": "string",
      "internal": true,
      "derive": "state.toRead == 0 ? 'Nothing to read' : `${state.toRead} to read`",
      "description": "The title of the home screen, for the screen only."
    }
  },
  "actions": {
    "addBook": {
      "description": "Put a book on your list, to read later.",
      "input": {
        "title": { "type": "string", "description": "The book's title." },
        "author": { "type": "string", "description": "Who wrote it.", "default": "" }
      },
      "output": "string",
      "require": [
        { "that": "size(trim(input.title)) > 0", "message": "Give the book a title." }
      ],
      "steps": [
        { "let": "id", "to": "=uuid()" },
        { "append": "state.books", "value": { "id": "=id", "title": "=trim(input.title)", "author": "=trim(input.author)", "status": "toRead", "addedOn": "=env.today" } },
        { "return": "=id" }
      ]
    },
    "setStatus": {
      "description": "Say whether you have not started a book, are reading it, or have read it.",
      "input": {
        "id": { "type": "string", "description": "Which book." },
        "status": { "type": { "type": "string", "enum": ["toRead", "reading", "read"] }, "description": "toRead, reading or read." }
      },
      "require": [ { "that": "state.books.exists(b, b.id == input.id)", "message": "That book is not on your list." } ],
      "steps": [ { "set": "state.books[id=input.id].status", "to": "=input.status" } ]
    },
    "editBook": {
      "description": "Change the title or the author of a book on your list.",
      "input": { "id": { "type": "string", "description": "Which book." }, "title": { "type": "string", "description": "The title." }, "author": { "type": "string", "description": "Who wrote it.", "default": "" } },
      "require": [ { "that": "state.books.exists(b, b.id == input.id)", "message": "That book is not on your list." }, { "that": "size(trim(input.title)) > 0", "message": "Give the book a title." } ],
      "steps": [ { "patch": "state.books", "where": "item.id == input.id", "with": { "title": "=trim(input.title)", "author": "=trim(input.author)" } } ]
    },
    "removeBook": {
      "description": "Take a book off your list.",
      "input": { "id": { "type": "string", "description": "Which book." } },
      "confirm": { "message": "=`${state.books.find(b, b.id == input.id).title} is taken off your list.`" },
      "steps": [ { "remove": "state.books", "where": "item.id == input.id" } ]
    }
  },
  "rules": {
    "allRead": {
      "description": "When every book on the list has been read, let your agents know.",
      "when": { "becomes": "size(state.books) > 0 && state.finished == size(state.books)" },
      "do": [ { "emit": "allRead" } ]
    }
  },
  "surfaces": {
    "agent": {
      "instructions": "Use addBook once per book, with the author when the person gives one. Read books to say what is on the list. removeBook asks the person to confirm.",
      "tools": {
        "include": ["addBook", "setStatus", "removeBook"],
        "describe": { "setStatus": "Say whether the person has not started a book, is reading it, or has read it. Take its id from the books resource." }
      },
      "resources": { "include": ["books", "toRead"] },
      "events": { "include": ["allRead"] }
    },
    "visual": {
      "start": "home",
      "views": {
        "home": {
          "title": "=state.heading",
          "body": {
            "control": "core:stack",
            "children": [
              {
                "control": "core:grid",
                "props": { "columns": 2 },
                "children": [
                  { "control": "core:stat", "props": { "label": "To read", "value": "=state.toRead" } },
                  { "control": "core:stat", "props": { "label": "Read", "value": "=state.finished" } }
                ]
              },
              { "control": "core:button", "props": { "label": "Add a book", "icon": "add", "emphasis": "high" }, "on": { "press": { "navigate": "addBook" } } },
              {
                "control": "core:table",
                "props": {
                  "label": "Books",
                  "items": "=state.books",
                  "columns": [
                    { "field": "title", "label": "Title", "sortable": true },
                    { "field": "author", "label": "Author", "sortable": true },
                    { "field": "status", "label": "Status", "format": "custom" }
                  ],
                  "empty": "No books yet. Add the first one."
                },
                "slots": {
                  "cell": { "control": "core:badge", "props": { "label": "=value == 'read' ? 'Read' : (value == 'reading' ? 'Reading' : 'To read')", "tone": "=value == 'read' ? 'success' : 'neutral'" } }
                },
                "on": { "select": { "navigate": "book", "with": { "id": "=event.item.id" } } }
              }
            ]
          }
        },
        "addBook": {
          "title": "Add a book",
          "state": {
            "title": { "type": "string?", "description": "The title being typed." },
            "author": { "type": "string?", "description": "The author being typed." }
          },
          "body": {
            "control": "core:form",
            "props": { "submitLabel": "Add", "cancelLabel": "Cancel" },
            "on": {
              "submit": [
                { "run": "addBook", "with": { "title": "=default(view.title, '')", "author": "=default(view.author, '')" } },
                { "navigate": "back" }
              ],
              "cancel": { "navigate": "back" }
            },
            "children": [ { "control": "core:textInput", "props": { "label": "Title", "required": true }, "bind": { "value": "view.title" } }, { "control": "core:textInput", "props": { "label": "Author" }, "bind": { "value": "view.author" } } ]
          }
        },
        "book": {
          "title": "=default(state.books.find(b, b.id == view.id).title, 'Book')",
          "input": { "id": { "type": "string", "description": "Which book to show." } },
          "body": {
            "control": "core:stack",
            "children": [
              { "control": "core:text", "when": "!state.books.exists(b, b.id == view.id)", "props": { "value": "This book is no longer on your list." } },
              {
                "control": "core:stack",
                "each": { "in": "state.books.filter(b, b.id == view.id)", "as": "book", "key": "book.id" },
                "children": [
                  { "control": "core:text", "props": { "value": "=book.author == '' ? 'Author not given' : `By ${book.author}`" } },
                  { "control": "core:text", "props": { "value": "=`Added ${formatDate(book.addedOn, 'long')}`", "style": "caption" } },
                  {
                    "control": "core:choice",
                    "props": {
                      "label": "Status",
                      "value": "=book.status",
                      "options": [ { "value": "toRead", "label": "To read" }, { "value": "reading", "label": "Reading" }, { "value": "read", "label": "Read" } ]
                    },
                    "on": { "change": { "run": "setStatus", "with": { "id": "=book.id", "status": "=event.value" } } }
                  },
                  { "control": "core:button", "props": { "label": "Change", "icon": "edit" }, "on": { "press": { "navigate": "editBook", "with": { "id": "=book.id" } } } },
                  {
                    "control": "core:button",
                    "props": { "label": "Remove", "icon": "delete", "destructive": true },
                    "on": { "press": [ { "run": "removeBook", "with": { "id": "=book.id" } }, { "navigate": "back" } ] }
                  }
                ]
              }
            ]
          }
        },
        "editBook": {
          "title": "Change the book",
          "input": { "id": { "type": "string", "description": "Which book to change." } },
          "state": {
            "title": { "type": "string?", "initial": "=state.books.find(b, b.id == view.id).title", "description": "The title being typed." },
            "author": { "type": "string?", "initial": "=state.books.find(b, b.id == view.id).author", "description": "The author being typed." }
          },
          "body": {
            "control": "core:form",
            "props": { "submitLabel": "Save", "cancelLabel": "Cancel" },
            "on": {
              "submit": [ { "run": "editBook", "with": { "id": "=view.id", "title": "=default(view.title, '')", "author": "=default(view.author, '')" } }, { "navigate": "back" } ],
              "cancel": { "navigate": "back" }
            },
            "children": [ { "control": "core:textInput", "props": { "label": "Title", "required": true }, "bind": { "value": "view.title" } }, { "control": "core:textInput", "props": { "label": "Author" }, "bind": { "value": "view.author" } } ]
          }
        }
      }
    }
  }
}

timeoff: Time off#

A team asks for days off, and an approver approves or declines each request.

The definition, timeoff.oad.json
{
  "oad": "0.2",
  "id": "com.example.timeoff",
  "version": "1.0.0",
  "meta": {
    "name": "Time off",
    "description": "A team asks for days off, and an approver approves or declines each request."
  },
  "uses": {
    "catalogs": {
      "core": { "id": "org.openappdefinition.core", "version": "^0.2.0" }
    }
  },
  "types": {
    "Request": {
      "type": "object",
      "properties": {
        "id": { "type": "string" },
        "personId": { "type": "string" },
        "personName": { "type": "string" },
        "from": { "type": "string", "format": "date" },
        "to": { "type": "string", "format": "date" },
        "note": { "type": "string" },
        "status": { "type": "string", "enum": ["pending", "approved", "declined", "cancelled"] },
        "decidedBy": { "type": "string" }
      },
      "required": ["id", "personId", "personName", "from", "to", "note", "status", "decidedBy"],
      "additionalProperties": false
    }
  },
  "roles": {
    "approver": { "description": "Approves or declines other people's time off." }
  },
  "state": {
    "requests": {
      "type": "Request[]",
      "initial": [],
      "scope": "shared",
      "conflict": "merge",
      "key": "id",
      "description": "Every time off request of the team."
    }
  },
  "actions": {
    "askForTimeOff": {
      "description": "Ask for days off, from the first day to the last day.",
      "input": {
        "from": { "type": "date", "description": "The first day off." },
        "to": { "type": "date", "description": "The last day off." },
        "note": { "type": "string", "description": "Anything the approver should know.", "default": "" }
      },
      "output": "string",
      "require": [
        { "that": "input.from >= env.today", "message": "Time off cannot start in the past." },
        { "that": "input.to >= input.from", "message": "The last day cannot be before the first day." }
      ],
      "done": { "message": "Request sent." },
      "steps": [
        { "let": "id", "to": "=uuid()" },
        { "append": "state.requests", "value": { "id": "=id", "personId": "=user.person.id", "personName": "=user.person.name", "from": "=input.from", "to": "=input.to", "note": "=input.note", "decidedBy": "" } },
        { "return": "=id" }
      ]
    },
    "approve": {
      "description": "Approve someone's time off request.",
      "input": { "id": { "type": "string", "description": "Which request." } },
      "require": [
        { "that": "'approver' in user.roles", "message": "Only an approver can decide time off." },
        { "that": "state.requests.exists(r, r.id == input.id && r.status == 'pending' && r.personId != user.person.id)", "message": "This request is not waiting for your decision." }
      ],
      "steps": [ { "send": "approve", "to": "approval", "key": "=input.id" } ]
    },
    "decline": {
      "description": "Decline someone's time off request.",
      "input": { "id": { "type": "string", "description": "Which request." } },
      "confirm": { "message": "The person is told their request is declined." },
      "require": [
        { "that": "'approver' in user.roles", "message": "Only an approver can decide time off." },
        { "that": "state.requests.exists(r, r.id == input.id && r.status == 'pending' && r.personId != user.person.id)", "message": "This request is not waiting for your decision." }
      ],
      "steps": [ { "send": "decline", "to": "approval", "key": "=input.id" } ]
    },
    "cancel": {
      "description": "Take back a request of yours that is still waiting.",
      "input": { "id": { "type": "string", "description": "Which request." } },
      "require": [
        { "that": "state.requests.exists(r, r.id == input.id && r.status == 'pending' && r.personId == user.person.id)", "message": "Only a waiting request of yours can be taken back." }
      ],
      "steps": [ { "send": "cancel", "to": "approval", "key": "=input.id" } ]
    }
  },
  "flows": {
    "approval": {
      "description": "A request waits for an approver, who approves or declines it; the person who asked can take it back while it waits.",
      "over": { "collection": "state.requests", "key": "id", "field": "status" },
      "initial": "pending",
      "states": {
        "pending": {
          "on": {
            "approve": { "to": "approved", "allow": "'approver' in user.roles && user.person.id != item.personId", "do": [ { "patch": "item", "with": { "decidedBy": "=user.person.name" } } ] },
            "decline": { "to": "declined", "allow": "'approver' in user.roles && user.person.id != item.personId", "do": [ { "patch": "item", "with": { "decidedBy": "=user.person.name" } } ] },
            "cancel": { "to": "cancelled", "allow": "user.person.id == item.personId" }
          }
        },
        "approved": { "final": true },
        "declined": { "final": true },
        "cancelled": { "final": true }
      }
    }
  },
  "surfaces": {
    "visual": {
      "start": "mine",
      "navigation": [
        { "view": "mine", "label": "My time off", "icon": "calendar" },
        { "view": "decide", "label": "To decide", "icon": "check", "when": "'approver' in user.roles" }
      ],
      "views": {
        "mine": {
          "title": "My time off",
          "body": {
            "control": "core:stack",
            "children": [
              { "control": "core:button", "props": { "label": "Ask for time off", "emphasis": "high" }, "on": { "press": { "navigate": "ask" } } },
              {
                "control": "core:table",
                "props": {
                  "label": "My requests",
                  "items": "=state.requests.filter(r, r.personId == user.person.id).map(r, merge(r, {stage: {pending: 'Waiting', approved: 'Approved', declined: 'Declined', cancelled: 'Taken back'}[r.status]}))",
                  "columns": [
                    { "field": "from", "label": "From", "format": "date", "sortable": true },
                    { "field": "to", "label": "To", "format": "date" },
                    { "field": "stage", "label": "Status" }
                  ],
                  "empty": "You have not asked for time off yet."
                },
                "on": { "select": { "navigate": "request", "with": { "id": "=event.item.id" } } }
              }
            ]
          }
        },
        "decide": {
          "title": "To decide",
          "body": {
            "control": "core:table",
            "props": {
              "label": "Waiting for a decision",
              "items": "=state.requests.filter(r, r.status == 'pending' && r.personId != user.person.id)",
              "columns": [ { "field": "personName", "label": "Who" }, { "field": "from", "label": "From", "format": "date", "sortable": true }, { "field": "to", "label": "To", "format": "date" } ],
              "empty": "Nothing is waiting for you."
            },
            "on": { "select": { "navigate": "request", "with": { "id": "=event.item.id" } } }
          }
        },
        "ask": {
          "title": "Ask for time off",
          "state": {
            "from": { "type": "date?", "description": "The first day being chosen." },
            "to": { "type": "date?", "description": "The last day being chosen." },
            "note": { "type": "string?", "description": "The note being typed." }
          },
          "body": {
            "control": "core:form",
            "props": { "submitLabel": "Ask", "cancelLabel": "Cancel" },
            "on": {
              "submit": [
                { "run": "askForTimeOff", "with": { "from": "=view.from", "to": "=view.to", "note": "=default(view.note, '')" } },
                { "navigate": "back" }
              ],
              "cancel": { "navigate": "back" }
            },
            "children": [
              { "control": "core:dateInput", "props": { "label": "First day off", "required": true, "min": "=env.today" }, "bind": { "value": "view.from" } },
              { "control": "core:dateInput", "props": { "label": "Last day off", "required": true, "min": "=default(view.from, env.today)" }, "bind": { "value": "view.to" } },
              { "control": "core:textInput", "props": { "label": "Note for the approver", "multiline": true }, "bind": { "value": "view.note" } }
            ]
          }
        },
        "request": {
          "title": "Time off request",
          "input": { "id": { "type": "string", "description": "Which request to show." } },
          "body": {
            "control": "core:stack",
            "each": { "in": "state.requests.filter(r, r.id == view.id)", "as": "request", "key": "request.id" },
            "children": [
              { "control": "core:heading", "props": { "value": "=`${request.personName}: ${formatDate(request.from, 'long')} to ${formatDate(request.to, 'long')}`" } },
              { "control": "core:badge", "props": { "label": "={pending: 'Waiting', approved: 'Approved', declined: 'Declined', cancelled: 'Taken back'}[request.status]", "tone": "=default({approved: 'success', declined: 'danger'}[request.status], 'neutral')" } },
              { "control": "core:text", "when": "request.note != ''", "props": { "value": "=request.note" } },
              { "control": "core:text", "when": "request.decidedBy != ''", "props": { "value": "=`Decided by ${request.decidedBy}`", "style": "caption" } },
              {
                "control": "core:stack",
                "props": { "direction": "horizontal" },
                "children": [
                  { "control": "core:button", "when": "canSend('approval', 'approve', request.id)", "props": { "label": "Approve", "emphasis": "high" }, "on": { "press": { "run": "approve", "with": { "id": "=request.id" } } } },
                  { "control": "core:button", "when": "canSend('approval', 'decline', request.id)", "props": { "label": "Decline", "destructive": true }, "on": { "press": { "run": "decline", "with": { "id": "=request.id" } } } },
                  { "control": "core:button", "when": "canSend('approval', 'cancel', request.id)", "props": { "label": "Take back" }, "on": { "press": { "run": "cancel", "with": { "id": "=request.id" } } } }
                ]
              }
            ]
          }
        }
      }
    }
  }
}

weather: Weather#

Shows the weather now and for the next days in a city you choose, from a weather service.

The definition, weather.oad.json
{
  "oad": "0.2",
  "id": "com.example.weather",
  "version": "1.0.0",
  "meta": {
    "name": "Weather",
    "description": "Shows the weather now and for the next days in a city you choose, from a weather service."
  },
  "uses": {
    "catalogs": {
      "core": { "id": "org.openappdefinition.core", "version": "^0.2.0" }
    }
  },
  "types": {
    "Day": {
      "type": "object",
      "properties": {
        "date": { "type": "string", "format": "date" },
        "high": { "type": "number" },
        "low": { "type": "number" },
        "summary": { "type": "string" }
      },
      "required": ["date", "high", "low", "summary"]
    }
  },
  "capabilities": {
    "weather": {
      "contract": "core:http",
      "description": "The weather service the forecast comes from.",
      "config": { "origin": "https://weather.example.com" }
    }
  },
  "grants": {
    "readForecast": {
      "capability": "weather",
      "scopes": ["http.read"],
      "reason": "Read the forecast for the city you choose. Only the city's name is sent.",
      "where": "input.path == '/v1/forecast'",
      "rate": { "count": 48, "per": "P1D" }
    }
  },
  "state": {
    "city": { "type": "string", "initial": "Lisbon", "description": "The city whose weather is shown." },
    "forecast": {
      "type": "core:HttpResponse",
      "sensitive": false,
      "description": "The weather service's answer for the city.",
      "source": {
        "call": "weather.get",
        "with": { "path": "/v1/forecast", "query": { "city": "=state.city" } },
        "refresh": { "every": "PT1H" }
      }
    },
    "found": {
      "type": "boolean",
      "derive": "state.forecast != null && state.forecast.status == 200",
      "description": "Whether the service knew the city."
    },
    "days": {
      "type": "Day[]",
      "derive": "state.found ? default(state.forecast.body.days, []) : []",
      "description": "The forecast for the next days."
    }
  },
  "actions": {
    "chooseCity": {
      "description": "Show the weather for another city.",
      "input": { "city": { "type": "string", "description": "The city's name, such as Lisbon." } },
      "require": [ { "that": "size(trim(input.city)) > 0", "message": "Type the name of a city." } ],
      "steps": [ { "set": "state.city", "to": "=trim(input.city)" } ]
    }
  },
  "surfaces": {
    "visual": {
      "start": "home",
      "views": {
        "home": {
          "title": "=`Weather in ${state.city}`",
          "state": { "city": { "type": "string?", "initial": "=state.city", "description": "The city being typed." } },
          "body": {
            "control": "core:stack",
            "children": [
              { "control": "core:progress", "when": "sources.forecast.status == 'loading'", "props": { "label": "Asking the weather service" } },
              {
                "control": "core:alert",
                "when": "sources.forecast.status == 'error'",
                "props": { "title": "The weather service did not answer", "message": "=default(sources.forecast.error.message, '')", "tone": "warning" }
              },
              {
                "control": "core:alert",
                "when": "state.forecast != null && !state.found",
                "props": { "title": "=`No forecast for ${state.city}`", "message": "Check the name of the city.", "tone": "info" }
              },
              { "control": "core:stat", "when": "state.found", "props": { "label": "Now", "value": "=`${default(state.forecast.body.now, '')}°`" } },
              {
                "control": "core:list",
                "props": { "label": "Next days", "items": "=state.days", "itemKey": "date", "empty": "No forecast yet." },
                "slots": {
                  "item": { "control": "core:text", "props": { "value": "=`${formatDate(item.date, 'medium')}: ${item.summary}, ${item.low}° to ${item.high}°`" } },
                  "actions": { "control": "core:button", "props": { "label": "Refresh the forecast", "icon": "refresh", "iconOnly": true, "emphasis": "low" }, "on": { "press": { "refresh": "state.forecast" } } }
                }
              },
              {
                "control": "core:form",
                "props": { "submitLabel": "Show" },
                "on": { "submit": { "run": "chooseCity", "with": { "city": "=default(view.city, '')" } } },
                "children": [
                  { "control": "core:textInput", "props": { "label": "City", "required": true }, "bind": { "value": "view.city" } }
                ]
              }
            ]
          }
        }
      }
    }
  }
}
Its sample document
{
  "weather": {
    "get": {
      "status": 200,
      "headers": { "content-type": "application/json" },
      "body": {
        "city": "Lisbon",
        "now": 18,
        "days": [
          { "date": "2026-11-13", "high": 19, "low": 12, "summary": "Sunny" },
          { "date": "2026-11-14", "high": 17, "low": 11, "summary": "Showers" },
          { "date": "2026-11-15", "high": 16, "low": 10, "summary": "Cloudy" }
        ]
      }
    }
  }
}

plants: Plant care#

Reminds you to water each of your plants when it is due.

The definition, plants.oad.json
{
  "oad": "0.2",
  "id": "com.example.plants",
  "version": "1.0.0",
  "meta": {
    "name": "Plant care",
    "description": "Reminds you to water each of your plants when it is due."
  },
  "uses": {
    "catalogs": {
      "core": { "id": "org.openappdefinition.core", "version": "^0.2.0" }
    }
  },
  "types": {
    "Plant": {
      "type": "object",
      "properties": {
        "id": { "type": "string" },
        "name": { "type": "string" },
        "everyDays": { "type": "integer", "minimum": 1 },
        "wateredOn": { "type": "string", "format": "date" }
      },
      "required": ["id", "name", "everyDays", "wateredOn"],
      "additionalProperties": false
    }
  },
  "capabilities": {
    "clock": { "contract": "core:scheduler", "description": "Wakes the app on the morning a plant needs water, even when it is closed." },
    "notify": { "contract": "core:notify", "description": "Tells you which plant needs water." }
  },
  "grants": {
    "wakeUp": {
      "capability": "clock",
      "scopes": ["scheduler.background"],
      "reason": "Wake the app on the morning a plant is due, so the reminder comes even when the app is closed.",
      "required": false
    },
    "reminders": {
      "capability": "notify",
      "scopes": ["notify.self"],
      "reason": "Tell you when a plant needs water, at most a few times a day.",
      "rate": { "count": 10, "per": "P1D" },
      "required": false
    }
  },
  "state": {
    "plants": { "type": "Plant[]", "initial": [], "description": "Your plants and when each was last watered." },
    "due": {
      "type": "Plant[]",
      "derive": "state.plants.filter(p, daysBetween(p.wateredOn, env.today) >= p.everyDays)",
      "description": "Plants that need water today."
    }
  },
  "actions": {
    "addPlant": {
      "description": "Add a plant, watered today, that needs water every few days.",
      "input": {
        "name": { "type": "string", "description": "What you call the plant." },
        "everyDays": { "type": "integer", "description": "How many days between waterings.", "default": 7 }
      },
      "require": [
        { "that": "size(trim(input.name)) > 0", "message": "Give the plant a name." },
        { "that": "input.everyDays >= 1", "message": "Water it at least every day: use 1 or more." }
      ],
      "steps": [
        { "let": "id", "to": "=uuid()" },
        { "append": "state.plants", "value": { "id": "=id", "name": "=trim(input.name)", "everyDays": "=input.everyDays", "wateredOn": "=env.today" } },
        { "call": "clock.wakeAt", "with": { "key": "=id", "at": "=atTime(addDays(env.today, input.everyDays), '09:00')" }, "onError": [] }
      ]
    },
    "water": {
      "description": "Say that you watered a plant today.",
      "input": { "id": { "type": "string", "description": "Which plant." } },
      "require": [ { "that": "state.plants.exists(p, p.id == input.id)", "message": "That plant is not in your list." } ],
      "steps": [
        { "patch": "state.plants", "where": "item.id == input.id", "with": { "wateredOn": "=env.today" } },
        { "let": "plant", "to": "=state.plants.find(p, p.id == input.id)" },
        { "call": "clock.wakeAt", "with": { "key": "=input.id", "at": "=atTime(addDays(env.today, plant.everyDays), '09:00')" }, "onError": [] }
      ]
    },
    "removePlant": {
      "description": "Take a plant off your list.",
      "input": { "id": { "type": "string", "description": "Which plant." } },
      "steps": [
        { "remove": "state.plants", "where": "item.id == input.id" },
        { "call": "clock.cancel", "with": { "key": "=input.id" }, "onError": [] }
      ]
    },
    "turnOnReminders": {
      "description": "Send a first notification, so that reminders can reach you.",
      "steps": [
        { "call": "notify.send", "with": { "title": "Reminders are on", "body": "You will hear from Plant care when a plant needs water." } }
      ]
    }
  },
  "rules": {
    "remind": {
      "description": "On the morning a plant is due, tell you to water it.",
      "when": { "event": "clock.wake" },
      "do": [
        { "let": "plant", "to": "=state.plants.find(p, p.id == event.key)" },
        {
          "if": "plant != null",
          "then": [
            { "call": "notify.send", "once": "=`water:${event.key}:${event.at}`", "with": { "title": "=`Water ${plant.name}`", "body": "=`${plant.name} needs water today.`", "view": "home" }, "onError": [] }
          ]
        }
      ]
    }
  },
  "surfaces": {
    "visual": {
      "start": "home",
      "views": {
        "home": {
          "title": "Plant care",
          "state": {
            "name": { "type": "string?", "description": "The name being typed." },
            "everyDays": { "type": "integer?", "initial": 7, "description": "The days between waterings being chosen." }
          },
          "body": {
            "control": "core:stack",
            "children": [
              { "control": "core:alert", "when": "size(state.due) > 0", "props": { "title": "=`${size(state.due)} ${plural(size(state.due), {one: 'plant needs', other: 'plants need'})} water`", "tone": "warning" } },
              {
                "control": "core:button",
                "when": "!grants.reminders.held && !grants.reminders.declined",
                "props": { "label": "Turn on reminders", "icon": "notification" },
                "on": { "press": { "run": "turnOnReminders" } }
              },
              { "control": "core:text", "when": "!grants.reminders.held", "props": { "value": "=grants.reminders.declined ? 'Reminders are off. You can turn them on in the permissions of the app.' : 'Reminders are off until you turn them on.'", "style": "caption" } },
              {
                "control": "core:list",
                "props": { "label": "Your plants", "items": "=state.plants", "empty": "No plants yet." },
                "slots": {
                  "item": {
                    "control": "core:stack",
                    "props": { "direction": "horizontal" },
                    "children": [
                      { "control": "core:text", "props": { "value": "=`${item.name}: watered ${relativeTime(item.wateredOn)}, every ${item.everyDays} days`" } },
                      { "control": "core:button", "props": { "label": "Watered" }, "on": { "press": { "run": "water", "with": { "id": "=item.id" } } } },
                      { "control": "core:button", "props": { "label": "Remove", "destructive": true, "emphasis": "low" }, "on": { "press": { "run": "removePlant", "with": { "id": "=item.id" } } } }
                    ]
                  }
                }
              },
              {
                "control": "core:form",
                "props": { "label": "Add a plant", "submitLabel": "Add" },
                "on": {
                  "submit": [
                    { "run": "addPlant", "with": { "name": "=default(view.name, '')", "everyDays": "=default(view.everyDays, 7)" } },
                    { "set": "view.name", "to": null }
                  ]
                },
                "children": [
                  { "control": "core:textInput", "props": { "label": "Name", "required": true }, "bind": { "value": "view.name" } },
                  { "control": "core:numberInput", "props": { "label": "Water every how many days?", "min": 1, "step": 1, "required": true }, "bind": { "value": "view.everyDays" } }
                ]
              }
            ]
          }
        }
      }
    }
  }
}

groceries: Groceries#

A shopping list the whole household shares: add what to buy, tick it off, take it off.

The definition, groceries.oad.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" } } }
            ]
          }
        }
      }
    }
  }
}

booking: Room booking#

Book a meeting room in three steps: the day and how many come, the room, then a last look before booking.

The definition, booking.oad.json
{
  "oad": "0.2",
  "id": "com.example.booking",
  "version": "1.0.0",
  "meta": {
    "name": "Room booking",
    "description": "Book a meeting room in three steps: the day and how many come, the room, then a last look before booking."
  },
  "uses": {
    "catalogs": {
      "core": { "id": "org.openappdefinition.core", "version": "^0.2.0" }
    }
  },
  "types": {
    "Booking": {
      "type": "object",
      "properties": {
        "id": { "type": "string" },
        "day": { "type": "string", "format": "date" },
        "room": { "type": "string" },
        "people": { "type": "integer" },
        "note": { "type": "string" }
      },
      "required": ["id", "day", "room", "people", "note"],
      "additionalProperties": false
    }
  },
  "state": {
    "bookings": { "type": "Booking[]", "initial": [], "description": "The rooms you booked." }
  },
  "actions": {
    "book": {
      "description": "Book a meeting room for a day.",
      "input": {
        "day": { "type": "date", "description": "The day of the meeting." },
        "room": { "type": "string", "description": "Which room." },
        "people": { "type": "integer", "description": "How many people come." },
        "note": { "type": "string", "description": "What the meeting is about.", "default": "" }
      },
      "require": [
        { "that": "input.day >= env.today", "message": "A room cannot be booked for a day that has passed." },
        { "that": "input.people >= 1", "message": "At least one person comes." }
      ],
      "steps": [
        { "append": "state.bookings", "value": { "id": "=uuid()", "day": "=input.day", "room": "=input.room", "people": "=input.people", "note": "=input.note" } }
      ]
    }
  },
  "surfaces": {
    "visual": {
      "start": "home",
      "views": {
        "home": {
          "title": "Bookings",
          "body": {
            "control": "core:stack",
            "children": [
              { "control": "core:button", "props": { "label": "Book a room", "emphasis": "high" }, "on": { "press": { "navigate": "book" } } },
              {
                "control": "core:tabs",
                "children": [
                  { "control": "core:group", "props": { "title": "Coming up" }, "children": [ { "control": "core:table", "props": { "label": "Coming up", "items": "=state.bookings.filter(b, b.day >= env.today)", "columns": [ { "field": "day", "label": "Day", "format": "date", "sortable": true }, { "field": "room", "label": "Room" } ], "empty": "Nothing booked." } } ] },
                  { "control": "core:group", "props": { "title": "Past" }, "children": [ { "control": "core:table", "props": { "label": "Past", "items": "=state.bookings.filter(b, b.day < env.today)", "columns": [ { "field": "day", "label": "Day", "format": "date", "sortable": true }, { "field": "room", "label": "Room" } ], "empty": "No past bookings." } } ] }
                ]
              }
            ]
          }
        },
        "book": {
          "title": "Book a room",
          "state": {
            "step": { "type": "integer", "initial": 1, "description": "The step being shown, from 1 to 3." },
            "day": { "type": "date?", "description": "The day being chosen." },
            "people": { "type": "integer?", "initial": 2, "description": "How many people come." },
            "room": { "type": "string?", "description": "The room being chosen." },
            "note": { "type": "string?", "description": "The note being typed." }
          },
          "body": {
            "control": "core:stack",
            "children": [
              { "control": "core:text", "props": { "value": "=`Step ${view.step} of 3`", "style": "caption" } },
              {
                "control": "core:form",
                "when": "view.step == 1",
                "props": { "submitLabel": "Next", "cancelLabel": "Cancel" },
                "on": { "submit": { "set": "view.step", "to": 2 }, "cancel": { "navigate": "back" } },
                "children": [
                  { "control": "core:dateInput", "props": { "label": "Day", "required": true, "min": "=env.today" }, "bind": { "value": "view.day" } },
                  { "control": "core:numberInput", "props": { "label": "People", "required": true, "min": 1, "max": 12, "step": 1 }, "bind": { "value": "view.people" } }
                ]
              },
              {
                "control": "core:form",
                "when": "view.step == 2",
                "props": { "submitLabel": "Next", "cancelLabel": "Back" },
                "on": { "submit": { "set": "view.step", "to": 3 }, "cancel": { "set": "view.step", "to": 1 } },
                "children": [
                  { "control": "core:choice", "props": { "label": "Room", "required": true, "options": [ { "value": "Harbor", "label": "Harbor, 4 seats" }, { "value": "Garden", "label": "Garden, 8 seats" }, { "value": "Hall", "label": "Hall, 12 seats" } ] }, "bind": { "value": "view.room" } }
                ]
              },
              {
                "control": "core:form",
                "when": "view.step == 3",
                "props": { "submitLabel": "Book", "cancelLabel": "Back" },
                "on": {
                  "submit": [
                    { "run": "book", "with": { "day": "=view.day", "room": "=view.room", "people": "=view.people", "note": "=default(view.note, '')" } },
                    { "navigate": "back" }
                  ],
                  "cancel": { "set": "view.step", "to": 2 }
                },
                "children": [
                  { "control": "core:text", "props": { "value": "=`${view.room} on ${formatDate(view.day, 'long')}, for ${view.people} ${plural(view.people, {one: 'person', other: 'people'})}`", "style": "emphasis" } },
                  { "control": "core:textInput", "props": { "label": "What the meeting is about", "multiline": true }, "bind": { "value": "view.note" } }
                ]
              }
            ]
          }
        }
      }
    }
  }
}

notes: Notes#

Notes kept in notebooks: each notebook is a main section, with the number of its notes beside it.

The definition, notes.oad.json
{
  "oad": "0.2",
  "id": "com.example.notes",
  "version": "1.0.0",
  "meta": {
    "name": "Notes",
    "description": "Notes kept in notebooks: each notebook is a main section, with the number of its notes beside it.",
    "icon": "edit"
  },
  "uses": { "catalogs": { "core": { "id": "org.openappdefinition.core", "version": "^0.2.0" } } },
  "types": {
    "Notebook": {
      "type": "object",
      "required": ["id", "name"],
      "properties": { "id": { "type": "string" }, "name": { "type": "string" } }
    },
    "Note": {
      "type": "object",
      "required": ["id", "notebook", "text"],
      "properties": { "id": { "type": "string" }, "notebook": { "type": "string" }, "text": { "type": "string" } }
    }
  },
  "state": {
    "notebooks": {
      "type": "Notebook[]",
      "description": "The notebooks, in the order they were made.",
      "initial": [
        { "id": "work", "name": "Work" },
        { "id": "home", "name": "Home" }
      ]
    },
    "notes": {
      "type": "Note[]",
      "description": "Every note, each in one notebook.",
      "initial": [
        { "id": "n1", "notebook": "work", "text": "Send the slides to Sam" },
        { "id": "n2", "notebook": "home", "text": "Call the plumber" }
      ]
    }
  },
  "actions": {
    "addNotebook": {
      "description": "Make a new, empty notebook.",
      "input": { "name": { "type": "string", "description": "The notebook's name." } },
      "output": "string",
      "require": [{ "that": "size(trim(input.name)) > 0", "message": "Give the notebook a name." }],
      "steps": [
        { "let": "id", "to": "=uuid()" },
        { "append": "state.notebooks", "value": { "id": "=id", "name": "=trim(input.name)" } },
        { "return": "=id" }
      ]
    },
    "addNote": {
      "description": "Write a note in a notebook.",
      "input": {
        "notebook": { "type": "string", "description": "Which notebook it goes in." },
        "text": { "type": "string", "description": "What the note says." }
      },
      "require": [
        { "that": "state.notebooks.exists(b, b.id == input.notebook)", "message": "That notebook is gone." },
        { "that": "size(trim(input.text)) > 0", "message": "Write something first." }
      ],
      "steps": [{ "append": "state.notes", "value": { "id": "=uuid()", "notebook": "=input.notebook", "text": "=trim(input.text)" } }]
    },
    "removeNote": {
      "description": "Throw a note away.",
      "input": { "id": { "type": "string", "description": "Which note." } },
      "steps": [{ "remove": "state.notes", "where": "item.id == input.id" }]
    }
  },
  "surfaces": {
    "visual": {
      "start": "all",
      "navigation": [
        { "view": "all", "label": "All notes", "icon": "home" },
        {
          "group": "Notebooks",
          "sections": [
            {
              "each": { "in": "state.notebooks", "as": "book", "key": "book.id" },
              "view": "notebook",
              "with": { "id": "=book.id" },
              "label": "=book.name",
              "icon": "file",
              "count": "=size(state.notes.filter(n, n.notebook == book.id))"
            },
            { "view": "newNotebook", "label": "New notebook", "icon": "add" }
          ]
        }
      ],
      "views": {
        "all": {
          "title": "All notes",
          "body": {
            "control": "core:list",
            "props": { "label": "Every note", "items": "=state.notes", "empty": "No notes yet. Open a notebook to write one." },
            "slots": { "item": { "control": "core:text", "props": { "value": "=item.text" } } }
          }
        },
        "notebook": {
          "title": "=default(state.notebooks.find(b, b.id == view.id).name, 'Notebook')",
          "input": { "id": { "type": "string", "description": "Which notebook to show." } },
          "state": { "text": { "type": "string?", "description": "The note being written." } },
          "body": {
            "control": "core:stack",
            "children": [
              {
                "control": "core:form",
                "props": { "submitLabel": "Add note" },
                "on": { "submit": [{ "run": "addNote", "with": { "notebook": "=view.id", "text": "=default(view.text, '')" } }, { "set": "view.text", "to": null }] },
                "children": [{ "control": "core:textInput", "props": { "label": "New note", "required": true }, "bind": { "value": "view.text" } }]
              },
              {
                "control": "core:list",
                "props": { "label": "Notes", "items": "=state.notes.filter(n, n.notebook == view.id)", "empty": "This notebook is empty." },
                "slots": {
                  "item": {
                    "control": "core:stack",
                    "props": { "direction": "horizontal" },
                    "children": [
                      { "control": "core:text", "props": { "value": "=item.text" } },
                      { "control": "core:button", "props": { "label": "Remove", "destructive": true, "emphasis": "low" }, "on": { "press": { "run": "removeNote", "with": { "id": "=item.id" } } } }
                    ]
                  }
                }
              }
            ]
          }
        },
        "newNotebook": {
          "title": "New notebook",
          "state": { "name": { "type": "string?", "description": "The name being typed." } },
          "body": {
            "control": "core:form",
            "props": { "submitLabel": "Make it" },
            "on": { "submit": [{ "run": "addNotebook", "with": { "name": "=default(view.name, '')" }, "as": "id" }, { "navigate": "notebook", "with": { "id": "=id" } }] },
            "children": [{ "control": "core:textInput", "props": { "label": "Name", "required": true }, "bind": { "value": "view.name" } }]
          }
        }
      }
    }
  }
}

jar: Savings jar#

Money put aside toward a goal: what is saved, what is left, and a word when the goal is reached.

The definition, jar.oad.json
{
  "oad": "0.2",
  "id": "com.example.jar",
  "version": "1.0.0",
  "meta": {
    "name": "Savings jar",
    "description": "Money put aside toward a goal: what is saved, what is left, and a word when the goal is reached."
  },
  "uses": {
    "catalogs": {
      "core": { "id": "org.openappdefinition.core", "version": "^0.2.0" }
    }
  },
  "capabilities": {
    "notify": { "contract": "core:notify", "description": "Tells you when the jar reaches its goal.", "required": false }
  },
  "grants": {
    "goalNotice": { "capability": "notify", "scopes": ["notify.self"], "reason": "Tell you when the jar reaches its goal.", "rate": { "count": 3, "per": "P1D" }, "required": false }
  },
  "state": {
    "goal": { "type": "number", "initial": 100, "description": "How much to save, in US dollars." },
    "saved": { "type": "number", "initial": 0, "description": "How much is in the jar, in US dollars." },
    "remaining": { "type": "number", "derive": "max(state.goal - state.saved, 0)", "description": "How much is still to save." }
  },
  "actions": {
    "putIn": {
      "description": "Put money in the jar.",
      "input": { "amount": { "type": "number", "description": "How much, in US dollars." } },
      "steps": [
        { "set": "state.saved", "to": "=state.saved + input.amount" },
        {
          "if": "state.saved >= state.goal && state.saved - input.amount < state.goal",
          "then": [
            { "emit": "goalReached", "with": { "saved": "=state.saved" } },
            { "call": "notify.send", "with": { "title": "Goal reached", "body": "=`The jar holds ${state.saved} dollars.`" }, "onError": [] }
          ]
        }
      ]
    },
    "setGoal": {
      "description": "Change how much to save.",
      "input": { "goal": { "type": "number", "description": "The new goal, in US dollars." } },
      "steps": [ { "set": "state.goal", "to": "=input.goal" } ]
    },
    "empty": {
      "description": "Take everything out of the jar.",
      "confirm": { "message": "=`The ${state.saved} dollars in the jar are taken out.`" },
      "steps": [ { "set": "state.saved", "to": 0 } ]
    }
  },
  "exports": {
    "inputs": { "goal": "state.goal" },
    "state": ["saved", "remaining"],
    "actions": ["putIn"],
    "events": ["goalReached"],
    "views": ["summary"]
  },
  "surfaces": {
    "visual": {
      "start": "home",
      "views": {
        "home": {
          "title": "Savings jar",
          "state": { "goal": { "type": "number?", "description": "The goal being typed." } },
          "body": {
            "control": "core:stack",
            "children": [
              { "control": "core:progress", "props": { "label": "Saved", "value": "=state.saved", "max": "=state.goal", "format": "currency", "currency": "USD" } },
              { "control": "core:button", "props": { "label": "Put in 10 dollars", "emphasis": "high" }, "on": { "press": { "run": "putIn", "with": { "amount": 10 } } } },
              {
                "control": "core:form",
                "props": { "submitLabel": "Set the goal" },
                "on": { "submit": [ { "run": "setGoal", "with": { "goal": "=default(view.goal, state.goal)" } }, { "set": "view.goal", "to": null } ] },
                "children": [ { "control": "core:numberInput", "props": { "label": "Goal in dollars", "min": 1, "required": true }, "bind": { "value": "view.goal" } } ]
              },
              { "control": "core:button", "props": { "label": "Empty the jar", "emphasis": "low", "destructive": true }, "on": { "press": { "run": "empty" } } }
            ]
          }
        },
        "summary": {
          "title": "Savings jar",
          "body": {
            "control": "core:stack",
            "children": [
              { "control": "core:progress", "props": { "label": "Saved", "value": "=state.saved", "max": "=state.goal", "format": "currency", "currency": "USD" } },
              { "control": "core:text", "props": { "value": "=state.remaining == 0 ? 'The goal is reached.' : `${state.remaining} dollars to go.`" } }
            ]
          }
        }
      }
    }
  }
}

gift: Gift fund#

Saving for one gift with a savings jar: the gift's price is the jar's goal, and the app notes the day enough is saved.

The definition, gift.oad.json
{
  "oad": "0.2",
  "id": "com.example.gift",
  "version": "1.0.0",
  "meta": {
    "name": "Gift fund",
    "description": "Saving for one gift with a savings jar: the gift's price is the jar's goal, and the app notes the day enough is saved."
  },
  "uses": {
    "catalogs": {
      "core": { "id": "org.openappdefinition.core", "version": "^0.2.0" }
    },
    "definitions": {
      "jarApp": { "id": "com.example.jar", "version": "^1.0.0" }
    }
  },
  "parts": {
    "jar": {
      "definition": "jarApp",
      "with": { "goal": "=state.price" },
      "capabilities": { "notify": "notify" },
      "grants": { "goalNotice": { "rate": { "count": 1, "per": "P1D" } } }
    }
  },
  "capabilities": {
    "notify": { "contract": "core:notify", "description": "Passed to the savings jar, so it can tell you when the gift is paid for.", "required": false }
  },
  "state": {
    "gift": { "type": "string", "initial": "A new bike", "description": "The gift to save for." },
    "price": { "type": "number", "initial": 240, "description": "What the gift costs, in US dollars." },
    "savedOn": { "type": "date?", "initial": null, "description": "The day the jar reached the price." },
    "weeksLeft": { "type": "integer", "derive": "ceil(parts.jar.state.remaining / 20)", "description": "Weeks to go at 20 dollars a week." }
  },
  "actions": {
    "saveWeek": {
      "description": "Put this week's 20 dollars in the jar.",
      "steps": [ { "run": "jar.putIn", "with": { "amount": 20 } } ]
    },
    "setPrice": {
      "description": "Change what the gift costs.",
      "input": { "price": { "type": "number", "description": "The new price, in US dollars." } },
      "steps": [ { "set": "state.price", "to": "=input.price" }, { "set": "state.savedOn", "to": null } ]
    }
  },
  "rules": {
    "noteTheDay": {
      "description": "When the jar reaches the price, note the day.",
      "when": { "event": "jar.goalReached" },
      "do": [ { "set": "state.savedOn", "to": "=env.today" } ]
    }
  },
  "surfaces": {
    "visual": {
      "start": "home",
      "views": {
        "home": {
          "title": "=state.gift",
          "state": { "price": { "type": "number?", "description": "The price being typed." } },
          "body": {
            "control": "core:stack",
            "children": [
              { "control": "core:text", "props": { "value": "=state.savedOn != null ? `Enough was saved on ${formatDate(state.savedOn, 'long')}.` : (state.weeksLeft == 0 ? 'Enough is saved.' : `${state.weeksLeft} weeks to go at 20 dollars a week.`)" } },
              { "part": "jar", "view": "summary" },
              { "control": "core:button", "props": { "label": "Save this week's 20 dollars", "emphasis": "high" }, "on": { "press": { "run": "saveWeek" } } },
              {
                "control": "core:form",
                "props": { "submitLabel": "Set the price" },
                "on": { "submit": [ { "run": "setPrice", "with": { "price": "=default(view.price, state.price)" } }, { "set": "view.price", "to": null } ] },
                "children": [ { "control": "core:numberInput", "props": { "label": "Price in dollars", "min": 1, "required": true }, "bind": { "value": "view.price" } } ]
              }
            ]
          }
        }
      }
    }
  }
}

guests: Guest book#

Guests sign with their name, and everyone sees who signed and how many.

The definition, guests.oad.json
{
  "oad": "0.2",
  "id": "com.example.guests",
  "version": "1.0.0",
  "meta": {
    "name": "=t('appName')",
    "description": "=t('appDescription')"
  },
  "uses": {
    "catalogs": {
      "core": { "id": "org.openappdefinition.core", "version": "^0.2.0" }
    }
  },
  "localization": {
    "default": "en",
    "strings": {
      "en": {
        "appName": "Guest book",
        "appDescription": "Guests sign with their name, and everyone sees who signed and how many.",
        "signedDescription": "The names of everyone who signed.",
        "lastDescription": "The name of the guest who signed last.",
        "signDescription": "Sign the guest book with a name.",
        "nameDescription": "The name to sign with.",
        "nameMissing": "Write your name first.",
        "yourName": "Your name",
        "sign": "Sign",
        "welcome": "Welcome, {name}!",
        "signatures": "Signatures",
        "empty": "Nobody has signed yet.",
        "count": { "by": "count", "forms": { "=0": "No guests yet.", "one": "{count} guest has signed.", "other": "{count} guests have signed." } }
      },
      "ar": {
        "appName": "دفتر الزوار",
        "appDescription": "يوقّع الضيوف بأسمائهم، ويرى الجميع من وقّع وكم عددهم.",
        "signedDescription": "أسماء كل من وقّع.",
        "lastDescription": "اسم آخر ضيف وقّع.",
        "signDescription": "التوقيع في دفتر الزوار باسم.",
        "nameDescription": "الاسم الذي يُوقَّع به.",
        "nameMissing": "اكتب اسمك أولًا.",
        "yourName": "اسمك",
        "sign": "وقّع",
        "welcome": "أهلًا بك يا {name}!",
        "signatures": "التوقيعات",
        "empty": "لم يوقّع أحد بعد.",
        "count": { "by": "count", "forms": { "=0": "لا ضيوف بعد.", "one": "وقّع ضيف واحد.", "two": "وقّع ضيفان.", "few": "وقّع {count} ضيوف.", "many": "وقّع {count} ضيفًا.", "other": "وقّع {count} ضيف." } }
      },
      "ja": {
        "appName": "ゲストブック",
        "appDescription": "ゲストが名前を書いて記帳し、誰が何人記帳したかを全員が見られます。",
        "signedDescription": "記帳した全員の名前。",
        "lastDescription": "最後に記帳したゲストの名前。",
        "signDescription": "名前を書いてゲストブックに記帳します。",
        "nameDescription": "記帳する名前。",
        "nameMissing": "先に名前を書いてください。",
        "yourName": "お名前",
        "sign": "記帳する",
        "welcome": "ようこそ、{name}さん!",
        "signatures": "記帳した人",
        "empty": "まだ誰も記帳していません。",
        "count": { "by": "count", "forms": { "=0": "まだゲストはいません。", "other": "{count}人のゲストが記帳しました。" } }
      }
    },
    "notes": {
      "welcome": "Shown after a guest signs. {name} is the name they wrote.",
      "count": "Below the list. {count} is how many guests signed."
    }
  },
  "state": {
    "signed": { "type": "string[]", "initial": [], "description": "=t('signedDescription')" },
    "last": { "type": "string?", "initial": null, "description": "=t('lastDescription')" }
  },
  "actions": {
    "sign": {
      "description": "=t('signDescription')",
      "input": { "name": { "type": "string", "description": "=t('nameDescription')" } },
      "require": [ { "that": "size(trim(input.name)) > 0", "message": "=t('nameMissing')" } ],
      "steps": [
        { "append": "state.signed", "value": "=trim(input.name)" },
        { "set": "state.last", "to": "=trim(input.name)" }
      ]
    }
  },
  "surfaces": {
    "visual": {
      "start": "home",
      "views": {
        "home": {
          "title": "=t('appName')",
          "state": { "name": { "type": "string?", "description": "=t('nameDescription')" } },
          "body": {
            "control": "core:stack",
            "children": [
              { "control": "core:text", "when": "state.last != null", "props": { "value": "=t('welcome', { name: state.last })" } },
              {
                "control": "core:form",
                "props": { "submitLabel": "=t('sign')" },
                "on": { "submit": [ { "run": "sign", "with": { "name": "=default(view.name, '')" } }, { "set": "view.name", "to": null } ] },
                "children": [ { "control": "core:textInput", "props": { "label": "=t('yourName')", "required": true }, "bind": { "value": "view.name" } } ]
              },
              {
                "control": "core:list",
                "props": { "label": "=t('signatures')", "items": "=state.signed", "empty": "=t('empty')" },
                "slots": { "item": { "control": "core:text", "props": { "value": "=item" } } }
              },
              { "control": "core:text", "props": { "value": "=t('count', { count: size(state.signed) })" } }
            ]
          }
        }
      }
    }
  }
}

postage: Postage#

Works out the fewest of your stamps that pay the postage of a letter or a parcel.

The definition, postage.oad.json
{
  "oad": "0.2",
  "id": "com.example.postage",
  "version": "1.0.0",
  "meta": {
    "name": "Postage",
    "description": "Works out the fewest of your stamps that pay the postage of a letter or a parcel."
  },
  "uses": {
    "catalogs": {
      "core": { "id": "org.openappdefinition.core", "version": "^0.2.0" }
    }
  },
  "types": {
    "Plan": {
      "type": "object",
      "properties": {
        "item": { "type": "string" },
        "postage": { "type": "integer" },
        "stamps": { "type": ["array", "null"], "items": { "type": "integer" } }
      },
      "required": ["item", "postage", "stamps"],
      "additionalProperties": false
    }
  },
  "state": {
    "stamps": { "type": "integer[]", "initial": [20, 30, 50], "description": "The values of the stamps you keep, in cents." },
    "letterPostage": { "type": "integer", "initial": 60, "description": "The postage of a letter, in cents." },
    "last": { "type": "Plan?", "initial": null, "description": "The stamps worked out last, and what for." },
    "said": {
      "type": "string",
      "derive": "state.last == null ? 'Press a button to see which stamps to use.' : state.last.stamps == null ? `${state.last.item}: the stamps could not be worked out here.` : size(state.last.stamps) == 0 ? `${state.last.item}: no mix of your stamps makes ${state.last.postage} cents.` : `${state.last.item}: ${state.last.postage} cents in ${size(state.last.stamps)} ${plural(size(state.last.stamps), {one: 'stamp', other: 'stamps'})}, ${join(state.last.stamps.map(s, string(s)), ' + ')}.`",
      "description": "What the screen says of the stamps worked out last."
    }
  },
  "code": {
    "fewestStamps": {
      "description": "Finds the fewest stamps whose values add up to the postage exactly, largest first, trying every mix of the values given. It fails when no mix makes the postage.",
      "runtime": "js",
      "input": {
        "postage": { "type": "integer", "description": "The postage to pay, in cents." },
        "values": { "type": "integer[]", "description": "The values of the stamps to choose from, in cents." }
      },
      "output": "integer[]",
      "source": "export default function ({ postage, values }) { const best = [[]]; for (let a = 1; a <= postage; a++) { for (const v of values) { const rest = best[a - v]; if (v > 0 && v <= a && rest !== undefined && (best[a] === undefined || rest.length + 1 < best[a].length)) best[a] = [...rest, v]; } } if (best[postage] === undefined) throw new Error(`no mix of these stamps makes ${postage}`); return best[postage].sort((x, y) => y - x); }",
      "limits": { "timeMs": 50, "memoryMb": 16 }
    }
  },
  "grants": {
    "stampMath": { "code": "fewestStamps", "reason": "Works out which of your stamps to use. It runs inside the app and reaches nothing else." }
  },
  "actions": {
    "stampLetter": {
      "description": "Work out the stamps for a letter.",
      "steps": [
        { "code": "fewestStamps", "with": { "postage": "=state.letterPostage", "values": "=state.stamps" }, "as": "picked", "orElse": "=error.code == 'code.failed' ? [] : null" },
        { "set": "state.last", "to": { "item": "A letter", "postage": "=state.letterPostage", "stamps": "=picked" } }
      ]
    },
    "stampParcel": {
      "description": "Work out the stamps for a parcel of the given weight.",
      "input": {
        "grams": { "type": "integer", "description": "The parcel's weight in grams." }
      },
      "require": [
        { "that": "input.grams >= 1 && input.grams <= 20000", "message": "A parcel weighs from 1 to 20000 grams." }
      ],
      "steps": [
        { "let": "postage", "to": "=150 + 40 * ceil(input.grams / 500)" },
        { "code": "fewestStamps", "with": { "postage": "=postage", "values": "=state.stamps" }, "as": "picked", "orElse": "=error.code == 'code.failed' ? [] : null" },
        { "set": "state.last", "to": { "item": "=`A parcel of ${input.grams} g`", "postage": "=postage", "stamps": "=picked" } }
      ]
    }
  },
  "surfaces": {
    "visual": {
      "start": "home",
      "views": {
        "home": {
          "title": "Postage",
          "state": {
            "grams": { "type": "integer", "initial": 1200, "description": "The weight of the parcel being stamped." }
          },
          "body": {
            "control": "core:stack",
            "children": [
              { "control": "core:text", "props": { "value": "=`Your stamps: ${join(state.stamps.map(s, string(s)), ', ')} cents`" } },
              { "control": "core:button", "props": { "label": "Stamp a letter", "emphasis": "high" }, "on": { "press": { "run": "stampLetter" } } },
              { "control": "core:numberInput", "props": { "label": "Parcel weight in grams", "min": 1, "max": 20000 }, "bind": { "value": "view.grams" } },
              { "control": "core:button", "props": { "label": "Stamp a parcel" }, "on": { "press": { "run": "stampParcel", "with": { "grams": "=view.grams" } } } },
              { "control": "core:text", "props": { "value": "=state.said" } }
            ]
          }
        }
      }
    }
  }
}