Now that most of the code of one of our products is written by agents, we need a clear model of organisation, for an LLM as much as for a human. To give the scale, that product’s application folder went from 451 TypeScript files in July 2026 to 1,241 in October. An agent that opens a folder has to know where to write without asking, and the question is the same for the person who reviews, in the evening, a folder a model generated end to end.
Alistair Cockburn’s hexagonal architecture, published in 2005, can answer that need for segmentation: it puts the business logic in the middle and has it talk to the outside world through ports, with adapters plugged into them. But the article, and the books that followed, are illustrated with object-oriented examples, where a port is an interface, an adapter is a class, and a container wires everything at start-up, whereas a framework like Next.js is written in functions rather than classes, with no container. Some of the paradigms can be translated all the same.
A function import is analogous to an injection: the dependency is written at the top of the file, and you replace it by changing one line, or by mocking the module in a test. A function’s signature is close to a port: the types of the parameters and of the return value are the contract, and it is the only contract available anyway, since a TypeScript interface no longer exists at run time and any object with the right shape goes through. Finally, the module stands in for the singleton: the database client is created once and shared by every file that imports it.
Very concretely, the hexagon becomes one folder per feature, with seven files with fixed roles: types, schemas, validators, services, loaders, actions, components. Four rules come with the layout: only one file queries the database; components display and compute nothing; business rules live in the validators, and an action calls them before it writes; a loader is split in two, a cached core and an uncached wrapper that checks the user’s rights first, because a cached function serves its stored result to the next caller without running again, so a permission check inside it protects nobody after the first call.
Why this helps a model: the map is the same in every feature, so the document that describes it is short, it is read once at the start of a task, and each file has one role to load into the context. Every rule is written with its reason, because an agent that knows why a rule exists applies it to the case the rule did not foresee. For the review, the gain is the same: on a merge request touching a feature, you know in advance which files can have changed and what each may contain.
The deep dive gives the code excerpts, every rule of the architecture document with its reason, what a machine checks on every merge request, and the concepts of hexagonal architecture we deliberately set aside.
Want the sources, timeline and detail? Read the deep dive (8 min).