Choose and clone an architecture

Five shipped templates, and how to clone one.

Barnark has no favourite. The description of each shipped template says where it suits, and the choice is yours. template:list lists them:

$ 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
TemplateWhat it isSuits
Domain Driven DesignCode organised around the business: bounded contexts, each with its own domain model, an application layer of commands and queries, and infrastructure, over a shared kernel with transports at the edge.A long-lived application with rich business rules and several distinct parts of the business.
Feature Based ArchitectureOne self-contained folder per feature, holding its own entities, values, exceptions, repositories and controllers.A small or medium application whose features change independently, where full layering would be overhead.
Model View ControllerThe classic three-way split: controllers take requests, models hold data and rules, views present them.A conventional web application, especially one built on an MVC framework.
LibraryA small public Api over hidden Internal code, split into features and shared parts.A reusable package whose users should depend only on a stable surface.
Package AppA whole application packaged behind a public Api, with bounded contexts, features and a kernel inside.An application that other code installs and drives as a dependency.
Blank projectOne empty folder, src, and nothing else.A project whose shape is still to be decided: add to it as it grows.

See what an ark would hold #

An ark is made only from a template of your own, so copy the shipped one first, for example template:copy "Model View Controller" "My Model View Controller". Then --dry-run checks the template, the ark’s name and the target, and prints the folders it would make without writing anything. Each of these was run in a barn with nothing bound, after that copy.

Model View Controller #

$ vendor/bin/barnark template:clone "My Model View Controller" Pricing ./app --dry-run
Barn: …/hotel

Making the ark 'Pricing' from a copy of 'My Model View Controller' in ./app
===========================================================================

  ./app
  ./app/Controller
  ./app/Model
  ./app/View

 ! [NOTE] Dry run — nothing was written.

Library #

$ vendor/bin/barnark template:clone "My Library" Pricing ./lib --dry-run
Barn: …/hotel

Making the ark 'Pricing' from a copy of 'My Library' in ./lib
=============================================================

  ./lib
  ./lib/Api
  ./lib/Api/Contract
  ./lib/Api/Exception
  ./lib/Api/Factory
  ./lib/Api/ValueObject
  ./lib/Internal
  ./lib/Internal/Feature
  ./lib/Internal/Shared
  ./lib/Internal/Shared/Exception
  ./lib/Internal/Shared/ResultObject
  ./lib/Internal/Shared/Service
  ./lib/Internal/Shared/ValueObject

 ! [NOTE] Dry run — nothing was written.

Feature Based Architecture #

$ vendor/bin/barnark template:clone "My Feature Based Architecture" Pricing ./app --dry-run
Barn: …/hotel

Making the ark 'Pricing' from a copy of 'My Feature Based Architecture' in ./app
================================================================================

 ! [NOTE] This template has no fixed folders and no members, so only the
 !        directory itself is made. Folders for its slots appear once
 !        something fills them.

  ./app

 ! [NOTE] Dry run — nothing was written.

Feature Based Architecture is built entirely from members, so an ark made from it has only the folder. Its features arrive as you add them: Add folders to your template shows how.

Domain Driven Design #

$ vendor/bin/barnark template:clone "My Domain Driven Design" Hotel ./src --dry-run
Barn: …/hotel

Making the ark 'Hotel' from a copy of 'My Domain Driven Design' in ./src
========================================================================

  ./src
  ./src/Context
  ./src/Kernel
  ./src/Kernel/Application
  ./src/Kernel/Domain
  ./src/Kernel/Infrastructure
  ./src/Transport
  ./src/Transport/Cli
  ./src/Transport/Cli/V1
  ./src/Transport/Cli/V1/Bootstrap
  ./src/Transport/Cli/V1/Command
  ./src/Transport/Http
  ./src/Transport/Http/Json
  ./src/Transport/Http/Json/V1
  ./src/Transport/Http/Json/V1/EventSubscriber
  ./src/Transport/Http/Json/V1/Role
  ./src/Transport/Http/Json/V1/Value

 ! [NOTE] Dry run — nothing was written.

The Context folder is made empty. Contexts are members, and you add them yourself.

Make the ark #

$ vendor/bin/barnark template:clone "My Domain Driven Design" Hotel ./src
Barn: …/hotel

Making the ark 'Hotel' from a copy of 'My Domain Driven Design' 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 first argument names one of your own templates, as template:list shows it. A shipped one is refused: copy it first.
  • The second is the ark’s name, unique in the project. The ark’s own template, a further copy, takes the same name, or the name with a number when one of yours has it.
  • The third is the folder to make. It is relative to the barn’s root, and the folder above it must exist.
$ vendor/bin/barnark template:clone "My Library" X ./nope/lib
Barn: …/hotel

 [ERROR] Folder '/nope' does not exist. Create that one first.

Each folder made has 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, and Barnark creates no other file in your folders. The ark is recorded in .barn/barnark/tracked-folders.json and its template is kept in .barn/barnark/catalogue/, so a later template:check with no arguments knows what to check.

In the browser app, Create ark on one of Your scaffolds asks the same questions.

Next: add folders to your template.