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 subscription product currently talks directly to a payment vendor from application code. Support has seen several incidents caused by callers retrying inconsistently and interpreting vendor response codes differently. The business wants to trial a second provider while keeping subscription workflows stable.
Design and sketch a TypeScript boundary that would let subscription code charge customers without depending on provider quirks. Include enough code to show the public API and one provider implementation stub.
Produce payment_design.md, payments.ts, and result.md.
=============== FILE: subscription.ts ===============
export async function renewSubscription(user: User, plan: Plan, stripe: any) {
const response = await stripe.charges.create({
customer: user.stripeCustomerId,
amount: plan.priceCents,
currency: "usd",
idempotency_key: `${user.id}-${plan.id}`
})
if (response.status === "succeeded") return { ok: true, chargeId: response.id }
if (response.status === "requires_action") return { ok: false, code: "3ds" }
if (response.failure_code === "card_declined") return { ok: false, code: "card_declined" }
throw new Error(response.failure_message)
}