Skip to content
Katabench
Try free

Move the Port Home

Medium About 25 min Free, no account needed

A *Port abstraction 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.

The brief

In a ports-and-adapters (hexagonal) architecture, a port is an abstraction owned by the application core. The adapters implement it. Dependencies point inward: the core never references the adapter layer.

This team already "extracted a port". An InventoryPort abstraction exists and OrderService depends on it, so it looks decoupled. But the port is declared in Shop.Adapters, right next to its SQL implementation. So Shop.Core carries a using Shop.Adapters just to see its own port, and at the namespace level the dependency arrow still points Shop.Core to Shop.Adapters. Worse: a *Port role is stranded in the adapter namespace, where ports do not belong.

The architecture rules flag both symptoms. The obvious move is to "give the core its own port": add a fresh InventoryPort in Shop.Core, point OrderService at that one, and leave the adapter as it was. Try that and you'll find it isn't that simple. The symptom (wrong layer) is protecting you from a deeper problem, and the half-fix trips a different rule.

Your job

Figure out why the port is stranded in the adapter layer in the first place, then fix it so the core genuinely owns its port, passing every architecture rule, not just the layering one. The behavior must stay byte-for-byte identical: same inputs, same "reserved ..." output.

What you need to do

  • Move the single port abstraction InventoryPort into Shop.Core (don't add a second copy, don't inline the concrete store).
  • Keep SqlInventoryStore in Shop.Adapters, now depending inward on the core's port.
  • Shop.Core must not depend on Shop.Adapters at all, and the only *Port in the system must live in the core.
  • Wire the concrete store in Solution (the composition root).

How it's graded

Your submission must (1) still pass the behavior tests (identical reservation strings) and (2) satisfy every architecture rule shown in the results: both the rule about which way the layer arrow points and the rule about where a *Port role lives. A naive "duplicate the port in the core" clears the layering rule but leaves a stray *Port in Shop.Adapters, so the role-placement rule stays red; only moving the single port turns them all green.

The layering rule is a symptom. The real work is moving the one abstraction so the core owns it outright, with no copy left behind on the wrong side of the boundary.

How it is graded

You work across multiple files, and architecture rules turn the design boundaries into executable feedback.

C# architecture exercises →

Related guides

What it practices

Ports and adapters
Driving and driven adapters meet the application only through its ports.
Dependency inversion
Point dependencies at abstractions the core owns, never at outer mechanisms.

Related katas