Two Sides of the Hexagon
Medium About 30 min Free, no account needed
A driving (web) adapter reaches the driven (persistence) adapter directly for a quick existence check. Inject the repository "via its interface" and you'll find the seam is still on the wrong side of the hexagon.
The brief
A hexagon has two kinds of ports. Driving (primary, inbound) ports are how the outside world calls the core: the web/CLI adapter drives the core through them. Driven (secondary, outbound) ports are how the core calls infrastructure: persistence, email, and the like. The inbound adapter and the outbound adapter sit on opposite edges of the hexagon, and the inbound adapter must reach the outbound adapter only through the core, never directly.
Here SubscriptionController (in Subs.Web, a driving adapter) was wired to call the use case
and, for a quick "is the customer known?" check, it also news up and calls
SqlCustomerRepository (in Subs.Persistence, a driven adapter) directly. So Subs.Web depends
on Subs.Persistence: the two opposite edges are short-circuited and the core is no longer the only
path between them. The behavior tests still pass, because the controller returns the right answer.
The architecture rules flag the coupling, and there's an obvious move: stop newing up the concrete,
extract an interface for the repository and inject that into the controller. "Depend on an
abstraction, not a concretion", surely that decouples the two adapters. Try it and watch it backfire.
If the extracted interface is declared next to its adapter (in Subs.Persistence, the natural home
for a "repository interface"), then Subs.Web still imports Subs.Persistence to see that
interface: you swapped a concrete dependency for an interface dependency on the same wrong edge.
The placement of the seam, not its shape, is the problem.
Figure out why the inbound adapter has to reach persistence at all, then remove that need so the
two edges genuinely meet only through the core, passing every architecture rule, not just the
"no interface left un-extracted" one. The behavior must stay byte-for-byte identical: same inputs,
same "existing" / "new" output.
Your submission must (1) still return "existing" for a known email and "new" otherwise
and (2) satisfy every architecture rule shown in the results: the core-owned lookup port
exists, Subs.Web does not depend on Subs.Persistence, and Subs.Web depends only on Subs.Core.
A naive "inject the repo via its interface" passes the port-exists rule but leaves both dependency
rules red; only moving the decision behind the driving port turns them all green.
Extracting an interface is half the story. An abstraction owned by the wrong side of the hexagon still points the inbound adapter outward. Ask which side should own the port.
How it is graded
You work across multiple files, and architecture rules turn the design boundaries into executable feedback.
Related guides
What it practices
- Ports and adapters
- Driving and driven adapters meet the application only through its ports.
Related katas
- Move the Port Home Medium Free A
*Portabstraction is declared beside its adapter, so the core reaches outward to see its own port. Move the single port into the core; duplicating it leaves a stray copy that fails the role-placement rule. - Preserve the Opaque Cursor Medium Pro An export invents offsets from row counts even though the storage service owns continuation tokens. Hide adapter details behind materialized pages and return every opaque token unchanged.
- Propagate the Caller's Cancellation Medium Pro A shard scan checks cancellation between probes but strips it from the adapter call. Keep caller-owned cancellation intact across the application port so an in-flight collaborator can observe it.
- Strangle Behind the Port Medium Pro A pricing core chooses between legacy and replacement tax engines itself, so a temporary migration decision has become permanent domain coupling. Put coexistence behind one core-owned port and let an outer adapter route the strangler migration.