Chapter 11: Design

Clean architecture

Robert Martin's version of layering: business rules sit at the centre and know nothing about databases or web frameworks. Those sit on the outside and depend inwards, so they can be replaced.

It hands an agent a rule simple enough to check: does this inner file import anything from outside? It also costs more files and more translating between shapes. For a small tool that price is usually too high, so ask for it when your rules will outlive your framework.

Say it to your agent

“src/domain must import nothing from express, pg or src/adapters. Add a structural test for that, define a SubscriptionStore interface inside src/domain, and implement it in src/adapters/postgres.ts.”

The workshop

Name a word, or describe what you mean in everyday language.