Your Own Enclosure Layout
The sign printer used to print for one shape of enclosure, and residents with burrows of their own had to move or go without signs. Now every enclosure tells the printer its own layout, and the signs come out the same. Built and tested in the shared library.
👋 Hi, I'm Anton - a software engineer. These days I work on a platform: contracts, generated code, data paths and the tooling around them. Running notes live on my GitHub: github.com/brilliant-almazov.
This part is about built and tested generator behaviour. The share of printed code is a goal the library sets itself, not a measurement; I say so on the figure.
This is part 17 of the series on what a shared platform does for every service, told as a zoo. Maybe you already do it better, maybe you'd do it another way - this is how it is going, and where it stops.
In real life
The Menagerie lives in one of the older enclosures in the zoo. It is not one animal but a crowd - small, busy residents who go out every day and bring back whatever they find. They dug their burrows long before the sign printer arrived, and the burrows do not look like anybody's plan. When Gus, the quartermaster, came with the standard signs, the crowd had one complaint, all at once: "Our burrows don't fit your plan!"
Gus, who returns in this part, does not ask them to move. "Tell me your rooms. I print into them." Pip splits the plan into pages, one per subject, so nobody has to read the whole book to change one sign. And Penny, who counts everything, compares the new signs with the old ones and finds that not a single letter changed. The Menagerie is the new resident here; in the real platform it stands for the data-collection service, which had a tree of its own long before the printer.
One printer, one tree
Every service in our platform is printed from its manifest. The printer - the generator in the shared library - has its renderers and templates, and until this change it printed into folders it chose itself. For a new service that is perfect: there is nothing to keep, and the default tree is a good tree.
For an old service it is a choice between two bad options. Either the service moves its code into the generator's tree - a large move with no value for anyone who uses the service - or it stays outside the printer and keeps writing by hand what every other service gets for free. The data-collection service had exactly that choice, and it is the reason the zoo got this part.
The rooms, in the manifest
The fix keeps the move the series keeps making: declare it, and let the generator print it. A layout: section in the manifest sets the print directories. Without it, every file goes to the library's default folder:
# before - no layout: section; the printer uses the library's default folders infra: postgres: main: { ... } With it, the service keeps its own tree, and the printer prints into it:
# service.yaml - a form, paths illustrative layout: di: internal/app/di # instead of the library's default folder transport: internal/transport The same change split the manifest. A service with many resources, daemons, enums and rpcs used to carry one file that only grew. Now the manifest can be split into parts named service.<section>.yaml, one per subject. The printer reads them as one plan; a person reads only the page they came for:
# service.infra.yaml - one page of the plan; the printer reads every service.*.yaml together infra: postgres: main: migrations: daemons: [server] Signs that say who printed them
Two smaller rules came with it, and both make the printed tree easier to live in.
Each printed file names its template and its print time in its header. When something in a printed file looks wrong, the header says where to fix it - in the template or in the manifest - and never in the file itself.
A reprint also cleans up after itself. When a template is removed, the files it used to print are removed on the next reprint, together with leftovers in the migrations folder. Before that, a removed template left orphans that nobody owned and everybody was afraid to delete.
// printed by <template> at <time> - do not edit; fix the template or the manifest And a hand edit to a printed file fails the build: the drift check reprints the service and compares. So the header is not a polite request. It is the address of the only place where a change will survive.
The rewrite nobody could see
To make the templates bend to any layout, they had to be rewritten. The library also set itself a rule for them: at most one template tag per line. Templates that mix several tags on a line are short to write and hard to read; one tag per line keeps every template readable top to bottom, like the file it prints.
Rewriting templates across the printer is the kind of change that quietly breaks a dozen services. So the rewrite had one acceptance rule: the printed output does not change by a single byte. Penny's line in the comic is that rule.
| What changed | Zoo | What a service sees |
|---|---|---|
layout: sets print directories | the printer prints into your rooms | its own tree stays |
manifest in service.<section>.yaml parts | one plan, many pages | a short file per subject |
| at most one template tag per line | signs you can read top to bottom | nothing - the output is the same |
| header names template and print time | every sign says who printed it | where to fix a printed file |
| reprint removes files of removed templates | old signs come down | no orphans in the tree |
What the printer is for
The library has a stated goal: at least 95 % of a service's code is not written by hand. What stays by hand is short - the body of your own method and the business rules in it, the checks of meaning in tests, and a few decisions people make, like which daemons a service runs. A fixed tree was the quietest obstacle to that goal: the services that most needed printing were the ones whose shape did not fit.
What went wrong
Not much went wrong with the change itself, and I think that is the lesson. The expensive part of a layout change is not the code; it is the fear of the rewrite. A byte-for-byte comparison turned a rewrite of every template into a change nobody downstream could see.
What went wrong was earlier, and it was a design choice, not a bug: a printer with fixed folders. It looked like simplicity. It was a decision that every service must look like the newest one, and an older service paid for it by staying outside the printer. A generator should own what a file says, not where a service keeps it.
What I do not claim
- Not that every service already uses
layout:. The section is built and tested; one older service is the reason it exists. - Not the exact numbers of renderers and templates. They are rounded.
- Not that 95 % is reached. It is a goal the library sets itself, not a measurement.
- Not the exact manifest syntax. The YAML above is a form, and the paths are illustrative.
- Not the exact header text. The line above is a form.
- Not how long the rewrite took. That is not measured here.
What of this is method
- Own what a file says, not where it lives. Let the service keep its tree.
- Split the plan by subject. One manifest, many pages.
- Rewrite behind a byte-for-byte check. A change nobody can see is a change nobody fears.
Zoo keeping, built in - Part 17. Next: Six Complaints, One Delivery.
If your generator prints into fixed folders, which of your old services stayed outside it? If your manifest is one growing file, who still reads it end to end? If you rewrote your templates, how did you prove nothing printed changed? Which burrow in your zoo still has no sign?










