Assembling the machine…
MCH-001 is running
Software architecture, drawn as machines you can run.
Each concept is a 3D machine in your browser. Scroll, and a real request travels through the first one, hexagonal architecture, step by step. Then a switch changes the machine, and you see what the pattern protects you from.
Scroll to run MCH-001
MCH-001 · Place an order
Hexagonal architecture, step by step.
Also called ports and adapters: the business core owns its interfaces and depends on nothing outside it. Scroll, and one order goes through it.
Step 1 / 8 · Place an order
The application starts
Before any request, the configurator creates each adapter and plugs it into its port. Postgres answers OrderRepository: decided here, once, not in the core.
- 0.00 msCONFIGHttpAdapter ← PlaceOrder
- 0.00 msCONFIGOrderRepository ← PostgresAdapter
- 0.00 msCONFIGPaymentGateway ← PaymentProviderAdapter
Step 2 / 8 · Place an order
A request arrives
POST /orders reaches the HTTP adapter. It turns the request into a PlaceOrder command, nothing more.
- 0.00 msREQPOST /orders →
HttpAdapter
- 0.00 msREQPOST /orders →
Step 3 / 8 · Place an order
Through the driving port
The adapter calls PlaceOrder, an interface the core owns. The adapter depends on the core, not the other way round.
- 0.05 msREQHttpAdapter →
PlaceOrder (driving port)
- 0.05 msREQHttpAdapter →
Step 4 / 8 · Place an order
The core applies the rules
An order needs at least one line and a positive total. Pure business logic: no SQL, no HTTP, no framework.
- 0.06 msRULEorder#1042 lines > 0 OK · total > 0 OK
Step 5 / 8 · Place an order
Out through OrderRepository
The core saves the order through a port it declares. It does not know which storage will answer.
- 0.07 msWRITEOrderRepository.
save(order#1042)
- 0.07 msWRITEOrderRepository.
Step 6 / 8 · Place an order
Postgres answers
The Postgres adapter implements OrderRepository and runs the INSERT. The core never wrote a line of SQL.
- 4.27 msWRITEPostgresAdapter INSERT INTO orders
Step 7 / 8 · Place an order
Payment through PaymentGateway
The core charges the customer through another port. The payment provider is only one adapter behind it.
- 184.28 msREQPaymentGateway.
charge(49.00 EUR) → PaymentProviderAdapter
- 184.28 msREQPaymentGateway.
Step 8 / 8 · Place an order
The response goes back
201 Created. The HTTP adapter turns the result into a response. The core never saw HTTP.
- 184.34 msRESP201 Created order#1042
What if · Step 6 / 8
InMemory answers
Same port, different adapter: a Map in memory answers, with no database. Not a single domain file changed.
- 0.08 msWRITEInMemoryAdapter map.
set(1042)
- 0.08 msWRITEInMemoryAdapter map.
What if · Step 6 / 8
The swap does not reach the core
InMemory is plugged into OrderRepository, but the core still calls the Postgres adapter it imports. The swap is ignored until someone edits the domain.
- 4.26 msERROrder domain →
PostgresAdapter · swap ignored, the core must change
- 4.26 msERROrder domain →
End of the run · 184.34 ms
One request, one machine, every step on the record.
On its own page, MCH-001 plays two more scenarios, a declined payment and an empty order, and lets you flip every switch yourself.
Drawing register
Eleven sheets on the drawing board.
A machine is issued each week, with benches, failure modes and protocols between them. Say which one comes next on X, or pick a sheet to pull it from the drawer.
Hexagonal architecture
- Scale
- NTS
- Rev
- A
- Source
- A. Cockburn, 2005
| Dwg no. | Title | Family | Status | Rev |
|---|---|---|---|---|
| MCH · MachinesOne concept, and switches that break it | ||||
| MCH-001 | Hexagonal architecture | Backend | Issued | A |
Hexagonal architecture
| ||||
| MCH-002 | JavaScript event loop | Frontend | Issued | A |
| MCH-003 | Redis cache-aside | Infra | Issued | A |
| MCH-004 | Domain-driven design | Backend | Issued | A |
| MCH-005 | Offline-first sync | Mobile | Issued | A |
| MCH-006 | Backend | In draft | — | |
| MCH-007 | Frontend | In draft | — | |
| MCH-008 | Infra | In draft | — | |
| BEN · BenchesSeveral machines, one input | ||||
| BEN-001 | RAG vs CAG vs KAG | AI | Issued | A |
| FMD · Failure modesA failure replayed, then repaired | ||||
| FMD-001 | Retry storm | Infra | Issued | A |
| PRT · ProtocolsAn exchange, counted in round trips | ||||
| PRT-001 | TLS 1.3 handshake | Infra | Issued | A |
Real projects
Real repositories, drawn from their code.
The same drawing, made from a real repository: its packages become parts, and every route between two of them stands on an import the code has. Here is Nightprint's own, PRJ-001, read against its code before it was published.
Draw a public JavaScript or TypeScript repository yourself: it takes about two minutes, and the drawing gets a link you can share.
Legend
Learn to read one machine, and you can read them all.
Every machine is drawn with the same symbols. Here they are on MCH-001, seen from above: point at a note, and its line lights up.
Balloon
A part's number. The same disc marks the part in the scene and its row in the bill of parts: click either, and both light up.
Dimension
A route's modelled latency: here, 4.2 ms from OrderRepository to Postgres.
Flow colour
What travels a pipe: a request, a write, a response or an error.
Arrowhead
Which end depends on the other in source code: here the payment provider adapter depends on PaymentGateway, the port the core declares.
Title block
Code, scale, revision, and the reference the machine was checked against.
General notes
- Latencies are modelled, in milliseconds. They are not measured.
- Every machine is checked against the reference in its title block, and never shows a behaviour the real system does not have.
- The engine steps at a fixed 1/60 s, so a run plays the same on every screen. MCH-001 places an order in 184.34 ms of simulated time.
- Vermillon marks errors and violations, and nothing else.
Build log
Built in public, one machine a week.
The engine, the drawings and the mistakes, posted as they happen.
| Date | Kind | Change |
|---|---|---|
| 18 OCT | SHIP | Three series join the machines: BEN-001 runs RAG, CAG and KAG on one question, FMD-001 replays a retry storm, PRT-001 counts a TLS 1.3 handshake in round trips. |
| 17 OCT | SHIP | MCH-004 is out: domain-driven design. An order's root holds its limit; then go around the root, drop the version, or call Shipping mid-transaction. |
| 15 OCT | SHIP | Every machine now downloads as a video: a 1080p MP4 shot in your browser, frame by frame, with no server involved. |
| 15 OCT | ARCH | A drawn repository is no longer always laid out in bands: the model picks a hub, a mirror or a bus, and the imports must hold it. |
| 15 OCT | FIX | A repository with no JavaScript or TypeScript is turned down at once, before the model is paid for. |
| 15 OCT | SHIP | Draw your own repository at /import: a public JavaScript or TypeScript repo becomes a machine you can run, in about two minutes. |
| 14 OCT | SHIP | PRJ-001: Nightprint drawn from its own code. Every route between two parts stands on an import the survey found. |
| 13 OCT | SHIP | MCH-003 is out: Redis cache-aside. Miss, load, cache for 60 s; then three ways to serve a stale price or flood the database. |