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.

  1. 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.

    1. 0.00 msCONFIGHttpAdapter ← PlaceOrder
    2. 0.00 msCONFIGOrderRepository ← PostgresAdapter
    3. 0.00 msCONFIGPaymentGateway ← PaymentProviderAdapter
  2. 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.

    1. 0.00 msREQPOST /orders → HttpAdapter
  3. 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.

    1. 0.05 msREQHttpAdapter → PlaceOrder (driving port)
  4. 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.

    1. 0.06 msRULEorder#1042 lines > 0 OK · total > 0 OK
  5. 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.

    1. 0.07 msWRITEOrderRepository.save(order#1042)
  6. 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.

    1. 4.27 msWRITEPostgresAdapter INSERT INTO orders
  7. 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.

    1. 184.28 msREQPaymentGateway.charge(49.00 EUR) → PaymentProviderAdapter
  8. 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.

    1. 184.34 msRESP201 Created order#1042
  9. 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.

    1. 0.08 msWRITEInMemoryAdapter map.set(1042)
  10. 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.

    1. 4.26 msERROrder domain → PostgresAdapter · swap ignored, the core must change

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.

Suggest the next one on X
Drawing register
Dwg no.TitleFamilyStatusRev
MCH · MachinesOne concept, and switches that break it
MCH-001Hexagonal architectureBackendIssuedA
Driving sideApplicationDriven side

Hexagonal architecture

Scale
NTS
Rev
A
Source
A. Cockburn, 2005
Run MCH-001
MCH-002JavaScript event loopFrontendIssuedA
MCH-003Redis cache-asideInfraIssuedA
MCH-004Domain-driven designBackendIssuedA
MCH-005Offline-first syncMobileIssuedA
MCH-006BackendIn draft—
MCH-007FrontendIn draft—
MCH-008InfraIn draft—
BEN · BenchesSeveral machines, one input
BEN-001RAG vs CAG vs KAGAIIssuedA
FMD · Failure modesA failure replayed, then repaired
FMD-001Retry stormInfraIssuedA
PRT · ProtocolsAn exchange, counted in round trips
PRT-001TLS 1.3 handshakeInfraIssuedA

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.

ReadersDeliveryCore
PRJ-001 · Nightprint · seen from above

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.

  1. 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.

  2. Dimension

    A route's modelled latency: here, 4.2 ms from OrderRepository to Postgres.

  3. Flow colour

    What travels a pipe: a request, a write, a response or an error.

  4. Arrowhead

    Which end depends on the other in source code: here the payment provider adapter depends on PaymentGateway, the port the core declares.

  5. Title block

    Code, scale, revision, and the reference the machine was checked against.

Driving sideApplicationDriven side4.2 ms12345678910Hexagonal architectureCODEMCH-001SCALENTSREVASOURCEA. Cockburn, 2005

General notes

  1. Latencies are modelled, in milliseconds. They are not measured.
  2. Every machine is checked against the reference in its title block, and never shows a behaviour the real system does not have.
  3. 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.
  4. 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.

Follow @ewenlq on X
Revisions
DateKindChange
18 OCTSHIPThree 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 OCTSHIPMCH-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 OCTSHIPEvery machine now downloads as a video: a 1080p MP4 shot in your browser, frame by frame, with no server involved.
15 OCTARCHA 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 OCTFIXA repository with no JavaScript or TypeScript is turned down at once, before the model is paid for.
15 OCTSHIPDraw your own repository at /import: a public JavaScript or TypeScript repo becomes a machine you can run, in about two minutes.
14 OCTSHIPPRJ-001: Nightprint drawn from its own code. Every route between two parts stands on an import the survey found.
13 OCTSHIPMCH-003 is out: Redis cache-aside. Miss, load, cache for 60 s; then three ways to serve a stale price or flood the database.
Full history on GitHub