Quick start
From an empty project to a checked architecture.
You need PHP 8.5 or later and Composer. Every command on this page was run in a new folder, with a hotel as the example, and the output shown is what it printed. It takes about ten minutes.
Install #
Barnark is a few Composer packages. barnark-cli
provides the vendor/bin/barnark command and brings the library, barnark,
with it. barnark-gui adds the browser app. From your project’s root:
$ composer require --dev rmb32/barnark-cli rmb32/barnark-gui
Make a barn #
Barnark keeps its records in a folder called .barn/ at the root of the project. init makes it.
$ vendor/bin/barnark init
Made a barn: …/hotel
Barnark keeps its records in: …/hotel/.barn/barnark
Commit .barn/ with your code. Barnark finds it from any folder inside the project, and refuses to work outside one.
See the templates #
Barnark ships a catalogue of architecture templates. They are read-only.
$ vendor/bin/barnark template:list
Barn: …/hotel
---------------------------- ------------
Name What it is
---------------------------- ------------
Domain Driven Design Shipped
Feature Based Architecture Shipped
Model View Controller Shipped
Library Shipped
Package App Shipped
Blank project Shipped
Copy one, then make an ark from your copy #
An ark is made only from a template of your own, so first copy a shipped one under a name you give it. The copy is yours: nothing ties it to the template it came from.
$ vendor/bin/barnark template:copy "Domain Driven Design" "My DDD"
Barn: …/hotel
[OK] Copied 'Domain Driven Design' into 'My DDD'.
Then make the ark: give it a name and a folder. Its own template is a further copy, named after the ark. --dry-run shows the folders without making any.
$ vendor/bin/barnark template:clone "My DDD" Hotel ./src --dry-run
Barn: …/hotel
Making the ark 'Hotel' from a copy of 'My DDD' in ./src
=======================================================
./src
./src/Context
./src/Kernel
./src/Kernel/Application
./src/Kernel/Domain
./src/Kernel/Infrastructure
./src/Transport
…
Run it without --dry-run to make them:
$ vendor/bin/barnark template:clone "My DDD" Hotel ./src
Barn: …/hotel
Making the ark 'Hotel' from a copy of 'My DDD' in ./src
=======================================================
./src
…
[OK] Made the ark 'Hotel' in ./src.
Bound to its own template 'Hotel' in .barn/barnark/tracked-folders.json — check it any time with `barnark template:check`.
The project has an ark now, Hotel, its own template also Hotel, bound to src. A project can have more, each with a name of its own. Each folder holds a
.gitkeep so that git keeps it while it is empty. The ark’s own folder also holds a small .barn-ark.json that points back to the project. Barnark creates nothing else in your folders.
Check the folder #
$ vendor/bin/barnark template:check
Barn: …/hotel
Checking the ark 'Hotel', …/hotel/src, against 'Hotel'
======================================================
[OK] Conformant — no inconsistencies found.
The check compares the folder with its template and reports where they differ. The command exits with status 1 when anything is wrong, so it can run in a build.
Add what the template offers #
Some folders of a template are collections: a place where you add folders of your own, each shaped
the same way. In Domain Driven Design, Context is one. Ask a folder what it offers:
$ vendor/bin/barnark template:offers src/Context
Barn: …/hotel
Slots offered in /src/Context by 'Hotel'
========================================
--------- --------- -------------------------------------------------
Slot Key Create it with
--------- --------- -------------------------------------------------
Context Context barnark template:new Context <name> src/Context
--------- --------- -------------------------------------------------
Add a context. Its folders arrive with it, and the template records the new member as a revision:
$ vendor/bin/barnark template:new Context Reservation src/Context
Barn: …/hotel
New Context 'Reservation'
=========================
…/hotel/src/Context/Reservation
…/hotel/src/Context/Reservation/Application
…/hotel/src/Context/Reservation/Application/Command
…
[OK] Created …/hotel/src/Context/Reservation, added to the template as
Context.
Check it with `barnark template:check`.
Add a second context, FrontDesk, the same way. Then ask what a context’s Domain folder offers, and add an aggregate to it:
$ vendor/bin/barnark template:offers src/Context/Reservation/Domain
Barn: …/hotel
Slots offered in /src/Context/Reservation/Domain by 'Hotel'
===========================================================
----------- ----------- ----------------------------------------------------------------------
Slot Key Create it with
----------- ----------- ----------------------------------------------------------------------
Aggregate Aggregate barnark template:new Aggregate <name> src/Context/Reservation/Domain
----------- ----------- ----------------------------------------------------------------------
$ vendor/bin/barnark template:new Aggregate Booking src/Context/Reservation/Domain
Barn: …/hotel
New Aggregate 'Booking'
=======================
…/hotel/src/Context/Reservation/Domain/Booking
[OK] Created …/hotel/src/Context/Reservation/Domain/Booking, added to the
template as Aggregate.
Check it with `barnark template:check`.
Let the check find what strays #
Make a folder by hand, where the template has no place for it, and check again:
$ mkdir src/Scratch
$ vendor/bin/barnark template:check
Barn: …/hotel
Checking the ark 'Hotel', …/hotel/src, against 'Hotel'
======================================================
Unexpected — on disk, not expected here
---------------------------------------
…/hotel/src/Scratch
This folder is not part of 'Hotel'.
[ERROR] 1 inconsistency(ies) found.
Either remove the folder, or take it into the template by saying what belongs there:
$ vendor/bin/barnark template:add-folder src/Scratch "Throwaway experiments."
Barn: …/hotel
[OK] Added /src/Scratch to the template.
Check it with `barnark template:check`.
$ vendor/bin/barnark template:check
Barn: …/hotel
Checking the ark 'Hotel', …/hotel/src, against 'Hotel'
======================================================
[OK] Conformant — no inconsistencies found.
Open the browser app #
$ vendor/bin/barnark gui
This serves the barn on your own machine and opens it in your browser, on port 8081 or the next free one. Stop it with Ctrl-C. The project’s folder is on the left: Browse shows its tree with a button for each thing the template lets you add, Check runs the check, and History lists every revision of the template. The browser app page covers the rest.
Let your AI agent help #
If you work with an AI agent, copy Barnark’s agent skills into the project:
$ vendor/bin/barnark skills:install
barnark-choosing-an-architecture: 2 written, 0 up to date, 0 left as you changed them
barnark-designing-your-template: 1 written, 0 up to date, 0 left as you changed them
barnark-getting-started: 1 written, 0 up to date, 0 left as you changed them
barnark-placing-code: 1 written, 0 up to date, 0 left as you changed them
Skills are in …/shop/.claude/skills
These are four skills in .claude/skills/, the folder Claude Code reads (--dir=<folder> for another agent’s). They teach your agent what Barnark keeps, the commands that read and the ones that write, how to choose an architecture, how to write a template and its folder meanings, and where code belongs. Ask it to set up a new project, add a module, review a change against the template, or explain a failed check: it reads your template first, shows you what it would create, and writes through the commands only once you agree.
Run the command again after updating Barnark: files you have changed are kept unless you pass --force.
Where next #
- Choose and clone an architecture: what each shipped template is for and what it makes.
- Add folders to your template: collections, members and folders of your own.
- Philosophy: why a template is copied, never referred to, and why conformance is checked, not claimed.