Why: the goal or problem
Imagine a class guide where teachers save schedule pages. Testing its save rule should not require a running web server and database. Replaceable edges matter more than layers alone.
How: work toward a solution
- One process: Class Schedule starts unsaved. HTTP or CLI adapters call SaveArticle through its input port.
- SaveArticle validates IDs, then calls a memory or embedded-database adapter through SaveRepository. Both storage adapters depend on this application-owned port; the application imports neither implementation.
- Saved: 0 → 1; repeat → 1. Invalid IDs or pre-write failure → 0.
Illustrative example
Swap an edge, keep the application
Dani wants to save the Class Schedule · initially unsaved
One process · dotted enclosure
1 · Driving adapters
- HTTP
- CLI
Imports → input port
2 · Application
Validate IDs, coordinate saving
3 · Driven adapters
- Memory
- Embedded database
SaveRepository ← adapter imports
Runtime call
- HTTP / CLI
- SaveArticle
- SaveRepository
- Memory / Embedded database
Dashed path: the call reaches storage through the output port; Saved returns to the caller.
The application imports neither adapter implementation. Memory can stand in for the database during a test. Six sides are not six required parts.
- Save → repeat: 0 → 1 → 1 entries; return Saved.
- From empty: empty IDs or failure before writing → 0. Retry after correction.
HTTP / CLI and memory / embedded database are alternatives; no data migration is implied.
What: the concept
Hexagonal architecture connects an application through ports and technology-specific adapters. Six sides do not mandate six components. Cockburn
Ports add indirection; clean rules can organize policy.
Discuss this idea
Comments are shared across languages. GitHub login required to post.