Skip to main content

This is an exploration of how to prototype the GOV.UK app, not something to build on yet.

Get started

Run the viewer, and write a first prototype.

Run the viewer

You need Node 22 or later, and access to the component library’s repository on GitHub, as npm installs the library from there.

cd exploration-3
npm install
npm start

The viewer is then at http://localhost:8000/. It opens the app prototype, prototypes/app.json. Open another with ?prototype=, by its file name, and on any of its screens with ?screen=:

http://localhost:8000/viewer/?prototype=app&screen=postcode

The viewer draws the prototype inside the library’s iPhone. On a window as narrow as a phone, the prototype fills it instead. Tap anywhere that does nothing and everything that does something is highlighted for a moment.

Write a prototype

A prototype is a JSON file in prototypes/, named after its id. This one has two screens: a button on the first goes to the second, which the navigation bar’s back button leaves.

{
  "version": "0",
  "id": "first",
  "title": "My first prototype",
  "start": "welcome",
  "screens": {
    "welcome": {
      "components": [
        { "type": "nav-bar", "attributes": { "title": "Welcome", "large-title": true } },
        { "type": "text", "text": "Tap the button to go on." },
        {
          "type": "button-stack",
          "slot": "footer",
          "children": [
            { "type": "button", "text": "Continue", "action": { "go": "done" } }
          ]
        }
      ]
    },
    "done": {
      "components": [
        { "type": "nav-bar", "attributes": { "back": true } },
        { "type": "heading", "attributes": { "level": "1", "size": "large-title" }, "text": "You’re done" }
      ]
    }
  }
}

Save it as prototypes/first.json and open http://localhost:8000/viewer/?prototype=first.

  • version is the version of the schema it’s written to. There is only "0".
  • start is the screen it opens on.
  • Each screen’s components are what is on it, top to bottom. Each is one of the component library’s, written as JSON: see components.
  • slot puts a component in a slot of the screen, such as its footer, which stays at the bottom.

When something’s wrong

The viewer checks a prototype against the schema before running it. If it doesn’t match, the viewer lists what’s wrong, and where, instead of running it.

An editor that knows JSON Schema can check it as you type, too. Tell it that files in prototypes/ follow schema/0/prototype.schema.json, as VS Code’s json.schemas setting does:

"json.schemas": [
  { "fileMatch": ["exploration-3/prototypes/*.json"], "url": "./exploration-3/schema/0/prototype.schema.json" }
]

The tests

npm test

runs everything, including checking every prototype against the schema. See AGENTS.md for how the code is built.