advanced

Hexagonal architecture

Put domain and application policy behind ports while adapters translate HTTP, database, queue, or UI concerns at the edge.

Hexagonal architecture places domain and application policy at the center, exposing ports (interfaces) that adapters implement for HTTP, databases, queues, and UI. Inbound adapters drive use cases; outbound adapters satisfy driven ports. The metaphor reinforces testability by swapping edges without rewriting core rules.

On interviews: sketch primary and secondary adapters for a payment flow. Relate ports to interfaces in your stack and adapters to framework glue.

Common pitfalls: anemic hexagon with empty domain; ports that mirror framework controllers one-to-one; adapters containing business rules.

The trade-off is flexibility versus complexity—know when the simpler path is enough.

Checklist:

  • Domain free of framework imports.
  • Each external system has dedicated adapter.
  • Use cases depend on outbound port interfaces.
  • Contract tests on adapter boundaries.