Domain Specialist

Refactoring Advisor

Technical Debt & Code Smells Specialist

A specialized AI agent focused on identifying code smells, technical debt, and maintainability issues that will cause problems as your codebase grows. Finds structural problems before they compound.

What Refactoring Advisor Catches

Structural issues that make code hard to maintain, extend, or understand

Code Smells

Structural problems that indicate deeper issues in your codebase design

Long methods (>50 lines)Large classes (>500 lines)Deep nesting (>4 levels)Long parameter lists (>5)

Design Issues

Object-oriented design problems that make code hard to change and test

God objectsFeature envyInappropriate intimacyPrimitive obsession

SOLID Violations

Violations of fundamental design principles that lead to rigid, fragile code

Single ResponsibilityOpen/ClosedLiskov SubstitutionDependency Inversion

High Complexity

Code paths that are too complex to understand, test, or maintain safely

Cyclomatic complexity >10Complex conditionalsHard-to-follow control flow

Code Smell Thresholds

Objective limits that signal when code needs refactoring

Method Length

> 50 lines

Methods should fit on one screen

Class Size

> 500 lines

Classes should have single responsibility

Parameter Count

> 5 params

Consider using an options object

Nesting Depth

> 4 levels

Extract functions or use early returns

Cyclomatic Complexity

> 10

Too many paths to test reliably

Duplicate Blocks

> 6 lines

Extract to a shared function

Refactoring Patterns in Action

See how Refactoring Advisor identifies problems and suggests specific patterns to apply

Extract Method Pattern

Before
function processOrder(order) {
  // Validate order
  if (!order.items || order.items.length === 0) {
    throw new Error('Empty order')
  }
  if (!order.customer) {
    throw new Error('No customer')
  }

  // Calculate totals
  let subtotal = 0
  for (const item of order.items) {
    subtotal += item.price * item.quantity
  }
  const tax = subtotal * 0.1
  const total = subtotal + tax

  // Apply discounts
  let discount = 0
  if (order.customer.isPremium) {
    discount = total * 0.15
  } else if (subtotal > 100) {
    discount = total * 0.05
  }

  return total - discount
}

Method doing 4 things: validation, calculation, tax, discounts

After
function processOrder(order) {
  validateOrder(order)
  const subtotal = calculateSubtotal(order.items)
  const total = applyTax(subtotal)
  return applyDiscount(total, order.customer)
}

function validateOrder(order) {
  if (!order.items?.length) throw new Error('Empty order')
  if (!order.customer) throw new Error('No customer')
}

function calculateSubtotal(items) {
  return items.reduce((sum, item) =>
    sum + item.price * item.quantity, 0)
}

Extract Method: each function does one thing well

Replace Conditional with Polymorphism

Before
function calculateShipping(order) {
  switch (order.shippingType) {
    case 'express':
      return order.weight * 5.0 + 15
    case 'standard':
      return order.weight * 2.5 + 5
    case 'economy':
      return order.weight * 1.0
    case 'freight':
      return order.weight * 0.5 + 50
    default:
      throw new Error('Unknown type')
  }
}

Switch statement that grows with each new shipping type

After
interface ShippingStrategy {
  calculate(weight: number): number
}

const shippingStrategies: Record<string, ShippingStrategy> = {
  express: { calculate: w => w * 5.0 + 15 },
  standard: { calculate: w => w * 2.5 + 5 },
  economy: { calculate: w => w * 1.0 },
  freight: { calculate: w => w * 0.5 + 50 },
}

function calculateShipping(order) {
  const strategy = shippingStrategies[order.shippingType]
  if (!strategy) throw new Error('Unknown type')
  return strategy.calculate(order.weight)
}

Strategy pattern: add new types without modifying existing code

Remove Feature Envy

Before
class OrderProcessor {
  calculateTax(order) {
    const subtotal = order.items.reduce((sum, item) =>
      sum + item.price * item.quantity, 0)
    const taxRate = order.customer.region === 'EU'
      ? order.customer.country.vatRate
      : 0.0
    return subtotal * taxRate
  }
}

OrderProcessor knows too much about Order and Customer internals

After
class Order {
  calculateSubtotal() {
    return this.items.reduce((sum, item) =>
      sum + item.price * item.quantity, 0)
  }

  calculateTax() {
    return this.calculateSubtotal() * this.customer.getTaxRate()
  }
}

class Customer {
  getTaxRate() {
    return this.region === 'EU' ? this.country.vatRate : 0.0
  }
}

Move behavior to the class that owns the data

Deep Analysis

How Refactoring Advisor Works

Refactoring Advisor doesn't just measure metrics — it understands design patterns and suggests specific refactoring techniques that will improve your code structure.

Pattern Recognition

Identifies code smells and anti-patterns in your code structure

Refactoring Recipes

Suggests specific patterns: Extract Method, Replace Conditional, Move Method

SOLID Principles

Checks adherence to SRP, OCP, LSP, ISP, and DIP

Analysis Pipeline

1

Measure Metrics

Calculates method/class length and complexity scores

2

Identify Patterns

Detects code smells and design anti-patterns

3

Check SOLID

Verifies adherence to design principles

4

Suggest Refactoring

Recommends specific patterns like Extract Method, Replace Conditional with Polymorphism

Prioritized Findings

Focuses on issues that WILL cause maintenance problems, not style nitpicks

HIGHEST

Duplicated Logic

Copy-paste code that must be changed in multiple places

HIGH

God Objects

Classes doing too many things, impossible to test

MEDIUM

High Complexity

Functions with too many paths to test reliably

LOWER

Style Issues

Skipped in favor of structural problems

Technical debt compounds exponentially.
Refactoring Advisor catches it early.

Stop Technical Debt
Before It Starts

Let Refactoring Advisor catch structural issues before they compound. Free for 14 days, no credit card required.

Code smell detection
SOLID violations
Refactoring patterns