Skip to content
Katabench
Try free

Break the Checkout Cycle

Hard About 50 min Free, no account needed

Orders, Pricing and Promotions import each other in a three-hop cycle while Pricing also reaches into Inventory's internals. Moving the obvious call only rotates the cycle; hoist the shared vocabulary into a kernel leaf and reach Inventory through its published port to turn every rule green.

The brief

You've inherited a Shop checkout. Pricing a line touches three modules in a loop:

  • Shop.Orders owns the checkout and the customer-status type (OrderStatus).
  • Shop.Pricing applies a bulk discount, then asks Shop.Promotions for the returning-customer promo.
  • Shop.Promotions reads OrderStatus back out of Shop.Orders to decide whether the promo applies.

That last read closes a three-hop import cycle: Orders → Pricing → Promotions → Orders. The architecture rules flag it, the modules don't form a DAG. On top of that, Shop.Pricing reaches straight into Shop.Inventory.Internal.StockLevel to ask whether the line qualifies for the bulk discount, sailing past Inventory's published IStockQuery. A second rule flags that.

The obvious move is to chase the back-edge: relocate the status read so Promotions stops importing Orders, and make the internal StockLevel reachable so Pricing can keep calling it. Try that and you'll find it isn't that simple. A cycle is a property of the whole graph, not of any single arrow, so moving the read just rotates the loop instead of breaking it, and prying open a module's internals is never how you cross its boundary. Both of those naive moves leave a pinned rule red.

There is already a Shop.Kernel at the bottom of the graph, a leaf that imports nothing from Shop.*, so the home for shared vocabulary exists. But mind the next trap: a third rule watches what the kernel is allowed to depend on. Shove the existing status type down there to make it "shared" and, if it drags a feature dependency along with it, the kernel stops being a sink and that rule goes red. The kernel only stays a sink if what you put in it is genuinely feature-neutral.

Your job

Figure out why these modules are tangled in the first place, then restructure them so the import graph is a genuine DAG and Inventory is reached only through its published port, passing every architecture rule, not just the one you happened to chase. The behavior must stay byte-for-byte identical: same inputs, same "Total: ..." output.

How it's graded

Your submission must (1) still pass the behavior tests (identical total strings) and (2) satisfy every architecture rule shown in the results, the acyclicity rule, the module-boundary rule, and the rule about what the shared kernel is allowed to depend on. A naive relocation clears at most one and trips another; only the deeper refactor turns them all green.

The cycle is a symptom. The real work is finding the shared vocabulary that has no business living inside one feature, and giving it a home that depends on nobody.

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

Dependency cycles
Find and break cycles between modules by inverting or extracting a dependency.
Modular monolith
Modules talk through published contracts and own their data, never each other's internals.
Stable dependencies
Stable kernels and contracts must not depend on volatile features.

Related katas