The Layer Skip
Medium About 30 min Free, no account needed
A controller reaches past the application layer straight into infrastructure for the order total. Route the call back through the middle layer with a port the application owns; a thin pass-through that still touches infrastructure only moves the smell, it doesn't remove it.
The brief
You've inherited an orders module built as a strict layered stack: Presentation -> Application ->
Infrastructure -> Domain. It compiles and the totals are correct, but Orders.Presentation.OrderController.GetTotal
constructs a SqlOrderRepository from Orders.Infrastructure and reads it directly.
Presentation is allowed to call Application, and Application is allowed to call Infrastructure, but Presentation must never reach past Application straight into Infrastructure. That's a layer skip: the controller routes around the middle layer, so the middle layer can no longer enforce a rule, swap the data source, or be tested in isolation. The architecture rules flag two edges at once: Presentation depends on Infrastructure, and Presentation skips Application to get there.
The obvious move is to push the repository call down a level: wrap it behind a quick pass-through and have the controller call that. Try it and you'll find it isn't that simple. The skip is a symptom of a deeper problem (the controller can only reach the total through a concrete type), and the naive relocation just moves the smell into the layer below, where a different rule is waiting.
Route the order total back through the application layer without changing the response. Same inputs, same numbers.
- Give
Orders.Applicationa seam it owns, a repository port (interface), and expose the total through the service. - Have the concrete repository in
Orders.Infrastructureimplement that port, depending inward. - Make
Orders.Presentationdepend only onOrders.Application: drop the infrastructureusingand the directnew SqlOrderRepository(). - Wire the concrete repository in
Solution(the composition root).
Your submission must (1) still return the same totals and (2) satisfy every architecture rule: presentation must not depend on infrastructure, presentation must not skip application to reach infrastructure, and the application layer may depend only on itself and the domain.
A thin pass-through that still
news up the repository only relocates the dependency: it clears the skip but leaves the application layer reaching down into infrastructure, so a third rule turns red. Only inverting the dependency (a port the middle layer owns, the concrete injected from the composition root) turns them all green at once.
How it is graded
You work across multiple files, and architecture rules turn the design boundaries into executable feedback.
Related guides
What it practices
- Layered architecture
- Keep transport, wire formats and versions at the edge and route calls through each layer.
- Dependency inversion
- Point dependencies at abstractions the core owns, never at outer mechanisms.
Related katas
- Config Is Infrastructure Medium Free The shipping core reads a framework configuration type directly, welding the domain to infrastructure. Invert it behind a core-owned options port, and don't just rename the framework wrapper into the core, which trips a second rule.
- 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. - The Core Doesn't Know Its Plugins Medium Pro A report host switches on format names and news up every plugin, and the plugins call back into the host and into each other for the report's currency rules. Let the composition root register plugins, refuse two plugins claiming one format, and hand each plugin the host's capabilities through a context the SDK publishes.
- Version the Edge, Not the Core Medium Pro The refund use case takes and returns v1's wire types, v2 is built on top of the v1 controller, and v2's refund reason reaches the policy through a field bolted onto v1's request. Give the application a version-neutral command that carries what the policy needs, so each API version is a thin sibling adapter.