Templates, bound and unbound
What a template is, and how the project’s one differs from the rest.
Shipped templates #
Barnark ships a catalogue of five: Domain Driven Design, Feature Based Architecture, Model View Controller, Library and Package App. They are read-only, and only a new Barnark changes them. The next page says what each is for.
Clone and copy #
Two commands turn a shipped template into yours, and both copy:
- Clone copies a template under a name you give and makes the project’s folder to it, so the copy becomes the project’s template.
- Copy only makes a new template of your own. It makes no folder. A shipped template or one of yours can be copied; nothing is copied out of an ark.
Either way the copy is tied to nothing. Changing it never changes the template it came from, and a later Barnark that changes a shipped template never reaches it. The name can’t be one the project already has, or a shipped template’s name, ignoring case.
$ vendor/bin/barnark template:copy Hotel "domain driven design"
Barn: …/hotel
[ERROR] 'domain driven design' can't name a template: a shipped template is
called 'Domain Driven Design'.
Bound and unbound #
A project has arks, as many as it needs. An ark is a named folder and the template that follows it. That
template is the bound template, made together with its folder by template:clone from a template of your own: a copy named after the ark. Each ark has a name, unique in the
project, and its folder can be anywhere on your computer, in the project or beside it. Barnark records each ark and its folder in
.barn/barnark/tracked-folders.json, and keeps each of the project’s templates, with its revisions, in
.barn/barnark/catalogue/. The ark’s folder holds a small .barn-ark.json that points back to the project.
The project’s other templates are unbound: ones you made by copying. An unbound template isn’t attached to any folder. It can make another ark, or be deleted. A shipped template makes no ark until you copy it. An ark’s name can’t be one the project already has, ignoring case.
$ vendor/bin/barnark template:clone "My Library" HOTEL ./lib
Barn: …/hotel
[ERROR] 'HOTEL' cannot name an ark: the project has an ark called 'Hotel'
already.
The Keep templates of your own page shows copying, listing and deleting.
What is in a template #
A template is a tree of folders. Each folder in it is one of these:
- Fixed folder. A folder the template names itself, such as
Kernelin Domain Driven Design orApiin Library. Every folder made to the template has it. - Collection. A folder that holds only members, all of one member type, such as
Contextin Domain Driven Design. - Member. A folder you add to a collection and name, such as
ReservationinContext. - Member type. What the template says once about every member of a collection: what a member is, and which folders it holds.
Context’s member type is a bounded context, which holdsApplication,Domain,InfrastructureandPublicApi.
Each folder and each member type has a meaning, in words, that says what it is for. A folder with no folders of its own is a leaf: it is where the template stops and your code begins.
Adding a member copies its member type’s shape into the template as folders of the member’s own, so adding one is a change to the template and makes a revision. Because every member has the same shape as its member type, Barnark doesn’t let you add a folder inside a member, or change one member alone.

Tags #
A template can tag its folders, to say what part each plays. Domain Driven Design tags its layers: Application,
Domain, Infrastructure and Transport. Package App tags each context’s Application and
Infrastructure. A tag has a meaning, and a folder carries the tags of its kind of folder, so every context you add brings its
layers’ tags. A folder the template has no place for carries none.
You can tag the folders of your own templates too (template:tag), and an ark can say which files the folders of a tag
may hold: see file rules.
The browser app shows tags as coloured labels beside a folder’s name, and can pick one out so that you see only the folders that
carry it and the folders above them, every context’s Application together, for instance.