AgentStack
Browse Sign in
Browse Why AgentStack Sell Docs
Sign in
SKILL verified MIT Self-run

Pattern Detection Walkthroughs

skill-mickeyyaya-refactoring-skills-pattern-detection-walkthroughs · by mickeyyaya

Use when you need end-to-end examples of detecting a code smell, identifying the underlying anti-pattern, selecting a refactoring technique, and applying the appropriate design pattern — each walkthrough traces the full diagnostic flow with before/after TypeScript code

No reviews yet
0 installs
11 views
0.0% view→install

Install

$ agentstack add skill-mickeyyaya-refactoring-skills-pattern-detection-walkthroughs

✓ scanned · ✓ verified, works with Claude Code, Cursor, and more.

Security review

✓ Passed

No issues found. Passed automated security review. · v0.1.0 How review works →

  • Prompt-injection patterns
  • Secret / credential exfiltration
  • Dangerous shell & filesystem operations
  • Untrusted network calls
  • Known-malicious package signatures

What it can access

  • Network access No
  • Filesystem access No
  • Shell / process execution No
  • Environment & secrets No
  • Dynamic code execution No

From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.

View the full security report →

Verified badge

Passed review? Show it. Paste this badge into your README, it links to the public security report.

AgentStack Verified badge Links to your public security report.
[![AgentStack Verified](https://agentstack.voostack.com/badges/verified.svg)](https://agentstack.voostack.com/security/report/skill-mickeyyaya-refactoring-skills-pattern-detection-walkthroughs)

Reliability & compatibility

Security review passed
0 installs to date
no reviews yet
5mo ago

Declared compatibility

Claude CodeClaude Desktop

Compatibility is declared by the source manifest. End-to-end runtime verification is coming, see below.

Preview Execution monitoring

We're building live execution health for every listing: tool-call success rate, median latency, uptime, and last-checked timestamps, measured, not self-reported. It isn't live yet, so we don't show numbers we can't stand behind.

How agent discovery & health will work →
Are you the author of Pattern Detection Walkthroughs? Claim this listing to set pricing, connect Stripe payouts, and keep 70% of every sale.
Sign up to claim

About

Pattern Detection Walkthroughs

Diagnostic Flow

Each walkthrough follows four steps:

  1. Smell Detection (detect-code-smells)
  2. Anti-Pattern Check (anti-patterns-catalog)
  3. Refactoring Selection (refactor skills)
  4. Design Pattern (prevent recurrence)

Walkthrough 1: God Class → Extract Class + Facade

Smell: Large Class — 15+ methods across auth, profiles, email, billing.

// BEFORE: UserManager does everything
class UserManager {
  private db: Database; private mailer: Mailer; private stripe: StripeClient;
  login(email: string, password: string): Session { /* ... */ }
  logout(sessionId: string): void { /* ... */ }
  updateProfile(userId: string, data: ProfileData): User { /* ... */ }
  sendWelcomeEmail(userId: string): void { /* ... */ }
  createSubscription(userId: string, plan: string): Subscription { /* ... */ }
  processRefund(userId: string, amount: number): void { /* ... */ }
  // ... 8 more methods
}

Anti-Pattern: God Object — changes to billing break auth; every dev edits same file.

Refactoring: Extract Class per responsibility (refactor-moving-features).

// AFTER: focused services
class AuthService { login(...) { } logout(...) { } }
class ProfileService { updateProfile(...) { } deleteAccount(...) { } }
class NotificationService { sendWelcomeEmail(...) { } sendInvoice(...) { } }
class BillingService { createSubscription(...) { } processRefund(...) { } }

Pattern: Facade — single entry point for coordinated multi-service flows.

class UserFacade {
  constructor(private auth: AuthService, private profile: ProfileService,
    private notifications: NotificationService, private billing: BillingService) {}

  async registerUser(email: string, password: string, plan: string): Promise {
    const session = await this.auth.login(email, password);
    await this.billing.createSubscription(session.userId, plan);
    await this.notifications.sendWelcomeEmail(session.userId);
    return this.profile.updateProfile(session.userId, { email });
  }
}

Walkthrough 2: Switch Statement → Strategy Pattern

Smell: Switch on type code for shipping calculation.

// BEFORE
function calculateShipping(order: Order): number {
  switch (order.shippingMethod) {
    case 'standard': return order.weight * 0.5 + 2.99;
    case 'express':  return order.weight * 1.2 + 9.99;
    case 'overnight': return order.weight * 2.5 + 24.99;
    case 'free': return 0;
    default: throw new Error(`Unknown: ${order.shippingMethod}`);
  }
}

Anti-Pattern: Switch on Type Code — replicates into discount, label printing, carrier selection.

Refactoring: Replace Conditional with Polymorphism (refactor-simplifying-conditionals).

interface ShippingStrategy { calculate(order: Order): number; }
class StandardShipping implements ShippingStrategy { calculate(order: Order) { return order.weight * 0.5 + 2.99; } }
class ExpressShipping implements ShippingStrategy { calculate(order: Order) { return order.weight * 1.2 + 9.99; } }
class OvernightShipping implements ShippingStrategy { calculate(order: Order) { return order.weight * 2.5 + 24.99; } }
class FreeShipping implements ShippingStrategy { calculate(_order: Order) { return 0; } }

Pattern: Strategy — new shipping type = one new class. Calculator never changes.

class ShippingCalculator {
  private strategies: Record = {
    standard: new StandardShipping(), express: new ExpressShipping(),
    overnight: new OvernightShipping(), free: new FreeShipping(),
  };
  calculate(order: Order): number {
    const s = this.strategies[order.shippingMethod];
    if (!s) throw new Error(`Unknown: ${order.shippingMethod}`);
    return s.calculate(order);
  }
}

Walkthrough 3: Callback Hell → Function Composition + Observer

Smell: Long Method + 4-level nesting with duplicated error handling.

// BEFORE: pyramid of callbacks
function processOrder(orderId: string, cb: (err: Error | null, result?: Receipt) => void) {
  db.findOrder(orderId, (err, order) => {
    if (err) { cb(err); return; }
    payment.charge(order.total, order.customerId, (err, charge) => {
      if (err) { cb(err); return; }
      inventory.reserve(order.items, (err, reservation) => {
        if (err) { cb(err); return; }
        mailer.confirm(order.customerId, (err) => {
          if (err) { cb(err); return; }
          cb(null, { orderId, chargeId: charge.id, reservationId: reservation.id });
        });
      });
    });
  });
}

Anti-Pattern: Spaghetti Code — adding a step means nesting deeper.

Refactoring: Extract Method + async composition (refactor-functional-patterns).

// AFTER: flat async pipeline
async function processOrder(orderId: string): Promise {
  const order = await db.findOrder(orderId);
  const charge = await payment.charge(order.total, order.customerId);
  const reservation = await inventory.reserve(order.items);
  bus.emit('order.fulfilled', { orderId, customerId: order.customerId });
  return { orderId, chargeId: charge.id, reservationId: reservation.id };
}

Pattern: Observer — side effects attach to event bus; processOrder never modified for new effects.

bus.on('order.fulfilled', ({ customerId }) => mailer.sendConfirmation(customerId));
bus.on('order.fulfilled', ({ orderId }) => analytics.track('order_completed', orderId));

Walkthrough 4: Primitive Obsession → Value Objects + Builder

Smell: Six raw strings for an address with no validation.

// BEFORE: positional strings — easy to swap city/state
function createShipment(recipientName: string, streetLine1: string, streetLine2: string,
  city: string, state: string, postalCode: string): Shipment { /* ... */ }

Anti-Pattern: Primitive Obsession — validation/formatting duplicated across callers.

Refactoring: Replace Data Value with Object + Introduce Parameter Object.

class Address {
  constructor(readonly recipientName: string, readonly streetLine1: string,
    readonly streetLine2: string, readonly city: string,
    readonly state: string, readonly postalCode: string) {
    if (!recipientName.trim()) throw new Error('recipientName required');
    if (!/^[A-Z]{2}$/.test(state)) throw new Error('state must be 2-letter code');
    if (!/^\d{5}(-\d{4})?$/.test(postalCode)) throw new Error('invalid postalCode');
  }
  format(): string { /* ... */ }
}
function createShipment(address: Address): Shipment { /* ... */ }

Pattern: Builder — fluent API; validation fires on build().

const shipment = createShipment(
  new AddressBuilder().recipient('Jane Smith').street('123 Main St', 'Apt 4B')
    .location('Springfield', 'IL', '62701').build()
);

Quick Reference

| Smell | Anti-Pattern | Refactoring | Pattern | |-------|-------------|-------------|---------| | Large Class (15+ methods) | God Object | Extract Class | Facade | | Switch on type code | Switch on Type Code | Replace Conditional with Polymorphism | Strategy | | Long Method + deep nesting | Spaghetti Code | Extract Method + async compose | Observer | | Primitive Obsession + Long Param List | Primitive Obsession | Value Object + Parameter Object | Builder |


Cross-References

| Topic | Skill | |-------|-------| | Smell detection | detect-code-smells | | Anti-pattern definitions | anti-patterns-catalog | | Extract Class, Move Method | refactor-moving-features | | Replace Conditional with Polymorphism | refactor-simplifying-conditionals | | Function composition | refactor-functional-patterns | | Value Object, Encapsulate Field | refactor-organizing-data | | Introduce Parameter Object | refactor-simplifying-method-calls | | Strategy, Observer | design-patterns-behavioral | | Facade, Builder | design-patterns-creational-structural |

Source & license

This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.

Install and usage instructions live in the source repository linked above.

Reviews

No reviews yet, be the first.

Versions

  • v0.1.0 Imported from the upstream source.