Quick start

From an empty project to a Template and a Construction that follows it.

You need PHP 8.5 or later with the ds and mbstring extensions, and Composer. Every command on this page was run in a new folder, with an allotment as the example, and the output shown is what it printed. It takes about ten minutes.

Install #

Barntree is a few Composer packages. barntree-cli provides the vendor/bin/barntree command and brings the library, barntree, with it. barntree-gui adds the browser app. From your project’s root:

$ composer require --dev rmb32/barntree-cli rmb32/barntree-gui

Make a barn #

Barntree keeps its records in a folder called .barn/ at the root of the project. init makes it.

$ vendor/bin/barntree init
Made a barn: …/allotment
Trees live in: …/allotment/.barn/barntree/trees

Commit .barn/ with the rest of the project. Barntree finds it from any folder inside the project, and refuses to work outside one.

Write a Template #

A Template says what types of thing there are in one subject. This one is an allotment: a plot that holds beds, a compost heap and a shed. A bed is a leaf, which holds nothing; the beds are a list of beds; the plot itself is a map of the three things it holds. Save this as allotment.json:

{
    "formatVersion": 1,
    "name": "Allotment",
    "description": "A plot of ground, rented to grow food on.",
    "root": "Allotment",
    "types": {
        "Allotment": {
            "name": "Allotment",
            "meaning": "The whole plot, from the gate to the far fence.",
            "kind": "map",
            "of": [
                "Beds",
                "Compost",
                "Shed"
            ]
        },
        "Beds": {
            "name": "Beds",
            "meaning": "The raised beds, each growing one crop at a time.",
            "kind": "list",
            "of": "Bed"
        },
        "Bed": {
            "name": "Bed",
            "meaning": "One raised bed.",
            "kind": "leaf",
            "tags": [
                "Watered"
            ]
        },
        "Compost": {
            "name": "Compost",
            "meaning": "Where waste becomes next year's soil.",
            "kind": "leaf",
            "tags": [
                "Watered"
            ]
        },
        "Shed": {
            "name": "Shed",
            "meaning": "Where the tools are kept dry.",
            "kind": "leaf"
        }
    },
    "tags": {
        "Watered": {
            "meaning": "Needs watering in dry weather."
        }
    }
}

Then give it to Barntree:

$ vendor/bin/barntree template:create --from-file=allotment.json
Saved: Allotment
$ vendor/bin/barntree template:list
Barn: …/allotment
+-----------+----------------------------------+----------+-----------------+
| Name      | Document ID                      | Revision | Source Template |
+-----------+----------------------------------+----------+-----------------+
| Allotment | bd3708f38810ec991ef9a2470b5abe52 | 1        |                 |
+-----------+----------------------------------+----------+-----------------+
$ vendor/bin/barntree template:show Allotment
Allotment
Revision: 1 (3c46bfb7e7251ee4a668cf2dd6a79557)
File token: 5f075e17e9f96751d733594974e8696b748ec2aeafa09d1342c5a0f819e70106
Allotment [Allotment, map]
  Beds [Beds, list]
    Bed [Bed, leaf]
  Compost [Compost, leaf]
  Shed [Shed, leaf]

The tree has no Bed under Beds yet. A list starts empty, and holds the members you add to it later. Trees: types and items explains how.

Check it #

$ vendor/bin/barntree check
Barn: …/allotment
Checking the trees in …/allotment/.barn/barntree/trees
Allotment: valid

The check reads every Template in the project and says whether each keeps its rules. It exits with status 1 when any does not, so it can run in a build.

Make a Construction #

A Template is the rules. A Construction is one real thing that follows them: a particular plot, with its own beds. It starts from the Template’s skeleton, the plot, its compost heap and its shed, with the beds empty.

$ vendor/bin/barntree construction:create Allotment --name="Plot 12"
Saved: Plot 12
Construction: 3207a1c11fb74907574c9158b2fa812f
Revision: 1 (3ead1efb447667fabc3edc3520dc4d39)
Barn: …/allotment
$ vendor/bin/barntree construction:show 3207a1c11fb74907574c9158b2fa812f
Plot 12
Revision: 1 (3ead1efb447667fabc3edc3520dc4d39)
Allotment [Allotment, map] id=a6613e89bc389b77
  Beds [Beds, list] id=dc06e11b23467d1a
  Compost [Compost, leaf] id=2b278038cbdda93e
  Shed [Shed, leaf] id=c3c827fbf214f947

The id= on each line is how you point at an item. Add two beds to the Beds list, using its id. Each change is saved at once, as a new revision:

$ vendor/bin/barntree member:add 3207a1c11fb74907574c9158b2fa812f --list=dc06e11b23467d1a --name="Beans"
Saved: Plot 12
Construction: 3207a1c11fb74907574c9158b2fa812f
Revision: 2 (372bbb6fad1f6bde9869042c7fcfcb29)
Barn: …/allotment
$ vendor/bin/barntree member:add 3207a1c11fb74907574c9158b2fa812f --list=dc06e11b23467d1a --name="Carrots"
Saved: Plot 12
Construction: 3207a1c11fb74907574c9158b2fa812f
Revision: 3 (f3d1bd75b615327c68370767096738d8)
Barn: …/allotment
$ vendor/bin/barntree construction:show 3207a1c11fb74907574c9158b2fa812f
Plot 12
Revision: 3 (f3d1bd75b615327c68370767096738d8)
Allotment [Allotment, map] id=a6613e89bc389b77
  Beds [Beds, list] id=dc06e11b23467d1a
    Beans [Bed, leaf] id=67186afc688414fe
    Carrots [Bed, leaf] id=7c49afd08c65dd98
  Compost [Compost, leaf] id=2b278038cbdda93e
  Shed [Shed, leaf] id=c3c827fbf214f947

Be refused #

Barntree will not keep a tree that breaks the Template’s rules. Two beds of one list can’t share a name:

$ vendor/bin/barntree member:add 3207a1c11fb74907574c9158b2fa812f --list=dc06e11b23467d1a --name="Beans"
List item 'dc06e11b23467d1a' has two members named 'Beans'.

See what changed #

$ vendor/bin/barntree construction:history 3207a1c11fb74907574c9158b2fa812f
+----------+----------------------------------+----------------------------------+----------------------+----------------------------+
| Revision | GUID                             | Recorded at                      | Event                | Identifier                 |
+----------+----------------------------------+----------------------------------+----------------------+----------------------------+
| 5        | 99459a8719ba0fb2f78c9342ba13a818 | 2026-11-11T16:21:25.484955+00:00 | Member deleted       | Bed — Courgettes           |
| 4        | 774a0ce3377400ef1a4a0d2edd23c570 | 2026-11-11T16:21:25.216984+00:00 | Member renamed       | Bed — Carrots → Courgettes |
| 3        | f3d1bd75b615327c68370767096738d8 | 2026-11-11T16:21:24.809730+00:00 | Member added         | Bed — Carrots              |
| 2        | 372bbb6fad1f6bde9869042c7fcfcb29 | 2026-11-11T16:21:24.672595+00:00 | Member added         | Bed — Beans                |
…

The full table lists every revision, newest first, with the date and what changed. Revisions and history explains them.

Read it another way #

A Template can be shown as a tree, a document, a Mermaid diagram, or folders. A folder export without --to writes nothing and shows what it would make:

$ vendor/bin/barntree export Allotment --as=folder
Allotment/
├── README.md
├── Beds/
│   └── README.md
├── Compost/
│   └── README.md
└── Shed/
    └── README.md

Open the browser app #

$ vendor/bin/barntree gui

This serves the barn on your own machine and opens it in your browser, on port 8082 or the next free one. Stop it with Ctrl-C. Your Constructions and Templates are listed on the left. The browser app page covers the rest.

Let your AI agent help #

If you work with an AI agent, copy Barntree’s agent skills into the project:

$ vendor/bin/barntree skills:install
barntree-designing-a-tree: 1 written, 0 up to date, 0 left as you changed them
barntree-getting-started: 2 written, 0 up to date, 0 left as you changed them
barntree-php-api: 2 written, 0 up to date, 0 left as you changed them
Skills are in …/garden/.claude/skills

These are three skills in .claude/skills/, the folder Claude Code reads (--dir=<folder> for another agent’s). They teach your agent what a Tree is, the commands that read and the ones that write, how to model something as a Tree, and how to use Barntree’s PHP library. Ask it to model something for you or explain why a change was refused: it reads what exists first, shows you a draft, and writes through the commands only once you agree.

Run the command again after updating Barntree: files you have changed are kept unless you pass --force.

Where next #

Used in Barn: in a barn, Barntree keeps its records in .barn/barntree/. barntree init makes any project a barn so Barntree can work on its own.