Skip to main content
PreparationZone Logo
PrepZone

Hexagonal Architecture

Ports and adapters to keep BookStore domain logic independent of web and JPA.

Pass checkpoint below

Why this matters

  • Ports and adapters keep domain logic testable without Spring context.
  • Interviewers map hexagonal vocabulary to the controller–service–repository layers you already use.
  • Knowing when strict hexagonal structure pays off prevents over-engineering small services.

Ports and adapters

L1 · Fresher

Domain core defines ports (interfaces); adapters implement REST, JPA, and Kafka at the edges.

Driving vs driven

L2 · Intermediate

REST controllers drive the application; JPA repositories are driven adapters for persistence.

Testability win

L3 · Advanced

Swap adapters with fakes in unit tests without Spring — domain rules stay pure Java.

vs layered

L4 · Expert

Hexagonal emphasizes dependency inversion; layered is fine for small BookStore until boundaries blur.

Domain (BookStore core)
Place order use case
REST adapterDriving
JPA adapterDriven
Kafka adapterDriven
Domain core exposes ports; adapters implement web, JPA, and messaging edges.

Hook

BookStore product owners want to swap PostgreSQL for a catalog API and add Kafka events without rewriting pricing rules buried in BookController. Hexagonal architecture keeps domain logic in the center with ports and adapters at the edges.

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 6 sections

  • Domain core
  • Ports and adapters
  • BookStore in action
  • Runnable BookStore lab
  • Failure modes in production
  • Package layout

Test yourself

Answer these before moving on — recall is what makes it stick.