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 warehouse team is adding inventory reservation to an order service. Existing callers know too much about table names, lock ordering, and stock status codes. Future work includes moving inventory storage from SQL to an external warehouse API, so callers should not depend on today’s storage details.
Design the module and interface, then sketch a minimal implementation outline in Python. Include a brief explanation of how future storage replacement becomes easier.
Produce inventory_design.md, inventory.py, and result.md.
=============== FILE: current_inventory.py ===============
def reserve(order_id, db, sku_rows, lock_timeout_ms, allow_backorder):
tx = db.begin()
try:
for row in sku_rows:
stock = tx.query("select available,status_code from inventory_skus where sku=? for update", [row["sku"]]).one()
if stock["status_code"] == 3 and not allow_backorder:
raise Exception("backorder")
if stock["available"] < row["qty"]:
raise Exception("insufficient")
tx.execute("update inventory_skus set available=available-? where sku=?", [row["qty"], row["sku"]])
tx.commit()
except Exception:
tx.rollback()
raise