Use before implementing or refactoring software when the task requires designing module boundaries, APIs, layers, abstractions, services, repositories, adapters, or architecture. Helps coding agents reduce total system complexity by creating deep modules, hiding implementation knowledge, avoiding leakage and pass-through APIs, comparing alternative designs, documenting interfaces before coding, and critiquing existing architecture.
93
94%
Does it follow best practices?
Impact
93%
1.13xAverage score across 5 eval scenarios
Passed
No known issues
A commerce service currently computes loyalty discounts inline in three request handlers. Product wants to add seasonal promotions, employee discounts, and a premium-member rule next quarter. The team needs a small refactor proposal and implementation sketch so handlers can apply discounts without each handler learning all discount sequencing and edge cases.
Create the design and a minimal Python implementation sketch for the chosen approach. Do not build a full application; focus on the boundary that callers should use and enough code to demonstrate it.
Produce design_brief.md, discounts.py, and architecture_result.md.
=============== FILE: current_handlers.py ===============
def preview_cart(cart, user, promo_code):
subtotal = sum(item.price * item.qty for item in cart.items)
if user.loyalty_years > 2:
subtotal *= 0.95
if promo_code == "SPRING":
subtotal *= 0.90
return {"subtotal": subtotal}
def checkout(cart, user, promo_code):
subtotal = sum(item.price * item.qty for item in cart.items)
if user.loyalty_years > 2:
subtotal *= 0.95
if promo_code == "SPRING":
subtotal *= 0.90
charge_card(user.card, subtotal)
return {"charged": subtotal}
def quote_subscription(cart, user, promo_code):
subtotal = sum(item.price * item.qty for item in cart.items)
if user.loyalty_years > 2:
subtotal *= 0.95
if promo_code == "SPRING":
subtotal *= 0.90
return {"monthly_quote": subtotal}