Where your data lives

Plain JSON in a folder you commit.

Every Barn tool keeps its files in one .barn/ folder at the project’s root. Barntree’s are in .barn/barntree/. Commit .barn/ with the rest of the project.

$ find .barn -type f | sed … | sort -u
.barn/barntree/template-history/catalogue.barntree.json
.barn/barntree/template-history/save.lock
.barn/barntree/trees/Allotment.barntree.json
.barn/barntree/workspace/construction/<sha256>/<sha256>.barntree.json
.barn/barntree/workspace/construction/<sha256>/current.barntree.json
.barn/barntree/workspace/construction/<sha256>/save.lock
WhereWhat it holds
trees/The Templates, one .barntree.json file each, named after the Template. A subfolder is fine.
template-history/The Templates’ revisions: one catalogue file holding every immutable revision, with the Templates’ identities, and a save.lock.
workspace/construction/One folder per Construction: a file for each revision, current.barntree.json, and a save.lock.

A Template’s identity is its name, not its path. A Template is found by the name inside its file. The folder is made when the first Template is saved.

The Template document #

This is the Allotment Template exactly as Barntree saved it, after the steps in this documentation. You can write one by hand and drop it into trees/; leave the tree out and the skeleton is built for you. Once it is there, change it through the tools.

{
    "formatVersion": 1,
    "name": "Allotment",
    "description": "A plot of ground, rented to grow food on, with a path to every bed.",
    "root": "Allotment",
    "tags": {
        "Watered": {
            "meaning": "Needs watering in dry weather."
        }
    },
    "types": {
        "Allotment": {
            "name": "Allotment",
            "meaning": "The whole plot, from the gate to the far fence.",
            "kind": "map",
            "of": [
                "Beds",
                "Compost",
                "Greenhouse",
                "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"
        },
        "Greenhouse": {
            "name": "Greenhouse",
            "meaning": "Where seedlings start.",
            "kind": "leaf"
        }
    },
    "tree": {
        "root": "611a24099c919a13",
        "items": {
            "611a24099c919a13": {
                "type": "Allotment",
                "name": "Allotment",
                "containing": {
                    "Beds": "84fc43d1a40986ec",
                    "Compost": "b22180b6376092de",
                    "Greenhouse": "66ef45a6aafa094e",
                    "Shed": "e0581a7c83808a45"
                }
            },
            "84fc43d1a40986ec": {
                "type": "Beds",
                "containing": []
            },
            "b22180b6376092de": {
                "type": "Compost"
            },
            "e0581a7c83808a45": {
                "type": "Shed"
            },
            "66ef45a6aafa094e": {
                "type": "Greenhouse"
            }
        }
    }
}
FieldMeaning
formatVersionThe only version there is is 1. Any other is refused.
name, descriptionThe Template’s name, and what it is for. Neither can be blank.
rootThe identifier of the root type.
tagsOptional. The tags a type may carry, each with its meaning.
typesAt least one, by identifier. Each has a name, a meaning and a kind (leaf, list or map); of is a list’s one type or a map’s types, and left out for a leaf; tags are declared tags, each once.
treeOptional. root is the root item’s id; each entry of items has its type, a name (the root and members only) and containing: an object of type to id for a map, a list of ids for a list, left out for a leaf.

Map entries and references are written in alphabetical order, and Barntree puts them in order whenever it reads, edits or writes a Tree, without changing any id or any list’s sequence.

How it is written #

A save locks the catalogue and compares a SHA-256 token of the exact current file, so a stale draft can’t overwrite an outside edit. The new file is written next to the old one and swapped in atomically. If a save is interrupted, the next operation recovers it. This protects against a partial file; it is not a promise against power loss, a network file system, or an outside writer that ignores the lock.

A broken, unreadable or unnameable file is reported, with its path. See when something goes wrong.