Skip to content

borghei/Claude-Skills / engineering/deep-module-design

deep-module-design

Verified

Design deep modules with small interfaces and rank shallow, pass-through or leaky code for deepening. Use when designing a module interface, improving codebase architecture, or making code easier to test.

assets/sample_codebase.json

View on GitHub
{
  "description": "Order-management sample: two pass-through layers, a shallow adapter, a field-validator module with a wide surface and little behind it, a checkout entry point with a 7-parameter signature that imports another module's private helpers, a deep pricing module that reaches into a private tax table, and a deep cart class.",
  "files": {
    "orders/order_service.py": "\"\"\"Order service: thin facade over the repository.\"\"\"\nfrom orders.order_repository import OrderRepository\n\n\nclass OrderService:\n    def __init__(self, repo):\n        self.repo = repo\n\n    def get_order(self, order_id):\n        return self.repo.get_order(order_id)\n\n    def save_order(self, order):\n        return self.repo.save_order(order)\n\n    def delete_order(self, order_id):\n        return self.repo.delete_order(order_id)\n\n    def list_orders(self, customer_id, status):\n        return self.repo.list_orders(customer_id, status)\n",
    "orders/order_repository.py": "\"\"\"Persistence for orders.\"\"\"\n\n\nclass OrderRepository:\n    def __init__(self, db):\n        self.db = db\n\n    def get_order(self, order_id):\n        return self.db.fetch_one(\"orders\", order_id)\n\n    def save_order(self, order):\n        return self.db.upsert(\"orders\", order)\n\n    def delete_order(self, order_id):\n        return self.db.delete(\"orders\", order_id)\n\n    def list_orders(self, customer_id, status):\n        return self.db.query(\"orders\", customer_id=customer_id, status=status)\n",
    "orders/validation.py": "\"\"\"Order field validators, one per field.\"\"\"\n\n\ndef check_sku(sku):\n    return bool(sku) and sku.isalnum()\n\n\ndef check_quantity(quantity):\n    return 0 < quantity <= 999\n\n\ndef check_currency(currency):\n    return currency in (\"EUR\", \"USD\", \"GBP\")\n\n\ndef check_postcode(postcode, country):\n    return bool(postcode) and len(postcode) <= 10\n\n\ndef check_email(email):\n    return \"@\" in email\n",
    "orders/pricing.py": "\"\"\"Prices an order: line totals, tiered discounts, tax, rounding at the end.\"\"\"\nfrom decimal import Decimal, ROUND_HALF_EVEN\nfrom orders.tax_tables import _RATES\n\n__all__ = [\"price_order\"]\n\n_TIERS = [(Decimal(\"1000\"), Decimal(\"0.10\")), (Decimal(\"500\"), Decimal(\"0.05\"))]\n\n\ndef price_order(order, catalog):\n    \"\"\"Return a fully priced order. Rounds once, after summing, to avoid drift.\"\"\"\n    lines = []\n    subtotal = Decimal(\"0\")\n    for item in order[\"items\"]:\n        product = catalog[item[\"sku\"]]\n        unit = Decimal(str(product[\"price\"]))\n        qty = Decimal(item[\"quantity\"])\n        line = unit * qty\n        if product.get(\"bundle_discount\") and qty >= 3:\n            line -= line * Decimal(str(product[\"bundle_discount\"]))\n        lines.append({\"sku\": item[\"sku\"], \"amount\": line})\n        subtotal += line\n    discount = _tier_discount(subtotal)\n    taxable = subtotal - discount\n    rate = _RATES.get(order[\"country\"], Decimal(\"0\"))\n    tax = taxable * rate\n    total = taxable + tax\n    return {\n        \"lines\": [_round_line(l) for l in lines],\n        \"subtotal\": _money(subtotal),\n        \"discount\": _money(discount),\n        \"tax\": _money(tax),\n        \"total\": _money(total),\n    }\n\n\ndef _tier_discount(subtotal):\n    for threshold, pct in _TIERS:\n        if subtotal >= threshold:\n            return subtotal * pct\n    return Decimal(\"0\")\n\n\ndef _round_line(line):\n    return {\"sku\": line[\"sku\"], \"amount\": _money(line[\"amount\"])}\n\n\ndef _money(value):\n    return value.quantize(Decimal(\"0.01\"), rounding=ROUND_HALF_EVEN)\n",
    "web/api_client.ts": "// HTTP helpers: each export forwards to the shared transport.\nimport { transport } from \"./transport\";\n\nexport async function getCart(cartId: string) {\n  return transport.get(cartId);\n}\n\nexport async function addItem(cartId: string, sku: string, qty: number) {\n  return transport.addItem(cartId, sku, qty);\n}\n\nexport async function removeItem(cartId: string, sku: string) {\n  return transport.removeItem(cartId, sku);\n}\n\nexport const clearCart = (cartId: string) => transport.clear(cartId);\n",
    "web/checkout.ts": "// Checkout: callers must assemble every pricing input themselves.\nimport { _applyTax, _roundMoney } from \"./pricing-internals\";\n\nexport function submitCheckout(cartId: string, items: Item[], country: string, currency: string,\n  couponCode: string, taxExempt: boolean, retryCount: number) {\n  const subtotal = items.reduce((s, i) => s + i.price * i.qty, 0);\n  const taxed = taxExempt ? subtotal : _applyTax(subtotal, country);\n  const total = _roundMoney(taxed, currency);\n  if (retryCount > 3) {\n    throw new Error(\"too many retries\");\n  }\n  return { cartId, total, couponCode };\n}\n",
    "web/cart.ts": "// Cart: owns line merging, stock limits, coupon rules and persistence behind three methods.\nexport class Cart {\n  private lines: Map<string, number> = new Map();\n  private coupon: string | null = null;\n\n  constructor(private store: CartStore, private stock: StockLookup) {}\n\n  add(sku: string, qty: number) {\n    const current = this.lines.get(sku) ?? 0;\n    const limit = this.stock.available(sku);\n    const next = Math.min(current + qty, limit, 99);\n    if (next <= 0) {\n      this.lines.delete(sku);\n    } else {\n      this.lines.set(sku, next);\n    }\n    this.revalidateCoupon();\n    this.store.save(this.snapshot());\n  }\n\n  applyCoupon(code: string) {\n    const normalised = code.trim().toUpperCase();\n    if (!/^[A-Z0-9]{4,12}$/.test(normalised)) {\n      return false;\n    }\n    this.coupon = normalised;\n    this.revalidateCoupon();\n    this.store.save(this.snapshot());\n    return this.coupon !== null;\n  }\n\n  snapshot() {\n    return {\n      lines: Array.from(this.lines.entries()).map(([sku, qty]) => ({ sku, qty })),\n      coupon: this.coupon,\n      itemCount: Array.from(this.lines.values()).reduce((a, b) => a + b, 0),\n    };\n  }\n\n  private revalidateCoupon() {\n    if (this.coupon === null) {\n      return;\n    }\n    const count = Array.from(this.lines.values()).reduce((a, b) => a + b, 0);\n    if (count === 0) {\n      this.coupon = null;\n    }\n    if (this.coupon && this.coupon.startsWith(\"BULK\") && count < 10) {\n      this.coupon = null;\n    }\n  }\n}\n"
  },
  "churn": {
    "orders/order_service.py": 14,
    "orders/order_repository.py": 9,
    "web/checkout.ts": 22,
    "web/api_client.ts": 3,
    "orders/validation.py": 2,
    "orders/pricing.py": 5,
    "web/cart.ts": 6
  }
}
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall