home / skills / pluginagentmarketplace / custom-plugin-software-design / solid-principles

solid-principles skill

/skills/solid-principles

This skill analyzes Python code to apply and validate SOLID principles, highlighting violations and offering actionable refactor suggestions for maintainable

npx playbooks add skill pluginagentmarketplace/custom-plugin-software-design --skill solid-principles

Review the files below or copy the command above to add this skill to your agents.

Files (6)
SKILL.md
6.4 KB
---
name: solid-principles
description: Apply and validate SOLID principles in object-oriented design
sasmp_version: "1.3.0"
bonded_agent: 01-design-principles
bond_type: PRIMARY_BOND
version: "2.0.0"
updated: "2025-12-30"
---

# SOLID Principles Skill

> Atomic skill for applying and validating SOLID principles

## Skill Definition

```yaml
skill_id: solid-principles
responsibility: Single - SOLID principle analysis and application
atomic: true
idempotent: true
```

## Parameter Schema

```typescript
interface SkillParams {
  // Required
  code: string;                    // Code to analyze
  language: string;                // Programming language

  // Optional
  principles?: ('SRP' | 'OCP' | 'LSP' | 'ISP' | 'DIP')[];  // Focus areas
  strictness?: 'relaxed' | 'normal' | 'strict';            // Validation level
  include_examples?: boolean;                               // Show fixes
}

interface SkillResult {
  violations: Violation[];
  compliance_score: number;        // 0-100
  suggestions: Suggestion[];
  metrics: PrincipleMetrics;
}
```

## Validation Rules

```yaml
input_validation:
  code:
    min_length: 10
    max_length: 50000
    required: true
  language:
    allowed: [typescript, javascript, python, java, csharp, go, ruby]
    required: true
  principles:
    default: ['SRP', 'OCP', 'LSP', 'ISP', 'DIP']

output_validation:
  compliance_score:
    min: 0
    max: 100
  violations:
    max_count: 50
```

## Retry Logic

```yaml
retry_config:
  max_attempts: 3
  backoff:
    type: exponential
    initial_delay_ms: 1000
    max_delay_ms: 10000
    multiplier: 2

  retryable_errors:
    - TIMEOUT
    - RATE_LIMIT
    - CONTEXT_OVERFLOW

  non_retryable_errors:
    - INVALID_INPUT
    - UNSUPPORTED_LANGUAGE
```

## Logging & Observability

```yaml
logging:
  level: INFO
  events:
    - skill_invoked
    - analysis_started
    - violation_found
    - analysis_completed
    - error_occurred

metrics:
  - name: analysis_duration_ms
    type: histogram
  - name: violations_per_principle
    type: counter
  - name: compliance_score
    type: gauge

tracing:
  span_name: solid_principles_analysis
  attributes:
    - language
    - code_size
    - principle_count
```

## Principle Definitions

### SRP - Single Responsibility Principle

```yaml
definition: "A class should have only one reason to change"
detection:
  indicators:
    - Multiple unrelated methods
    - Mixed abstraction levels
    - Too many dependencies
  thresholds:
    methods_per_class: 10
    dependencies: 5
    lines_of_code: 200
```

### OCP - Open/Closed Principle

```yaml
definition: "Open for extension, closed for modification"
detection:
  indicators:
    - Switch statements on type
    - Instanceof/typeof checks
    - Frequent modifications for new features
  patterns:
    - Strategy pattern opportunity
    - Template method opportunity
```

### LSP - Liskov Substitution Principle

```yaml
definition: "Subtypes must be substitutable for base types"
detection:
  indicators:
    - Overridden methods with different behavior
    - Empty method implementations
    - Type checking in polymorphic code
  violations:
    - Precondition strengthening
    - Postcondition weakening
    - Invariant breaking
```

### ISP - Interface Segregation Principle

```yaml
definition: "Clients should not depend on interfaces they don't use"
detection:
  indicators:
    - Large interfaces (>5 methods)
    - Unused method implementations
    - Throw NotImplemented patterns
  thresholds:
    max_interface_methods: 5
```

### DIP - Dependency Inversion Principle

```yaml
definition: "Depend on abstractions, not concretions"
detection:
  indicators:
    - Direct instantiation with 'new'
    - Concrete class parameters
    - No interface/abstract usage
  patterns:
    - Constructor injection missing
    - Service locator anti-pattern
```

## Usage Examples

### Basic Analysis
```typescript
// Input
{
  code: "class UserService { ... }",
  language: "typescript"
}

// Output
{
  violations: [
    {
      principle: "SRP",
      location: "UserService:1",
      severity: "high",
      message: "Class has 5 different responsibilities",
      suggestion: "Extract to: AuthService, ProfileService, NotificationService"
    }
  ],
  compliance_score: 65,
  suggestions: [...],
  metrics: { srp: 60, ocp: 80, lsp: 100, isp: 70, dip: 45 }
}
```

### Focused Analysis
```typescript
// Input
{
  code: "interface Repository { ... }",
  language: "typescript",
  principles: ["ISP"],
  strictness: "strict"
}
```

## Unit Test Template

```typescript
describe('SolidPrinciplesSkill', () => {
  describe('analyze', () => {
    it('should detect SRP violation in god class', async () => {
      const code = `
        class UserManager {
          saveUser() {}
          sendEmail() {}
          generateReport() {}
          validateInput() {}
          logActivity() {}
        }
      `;

      const result = await skill.analyze({ code, language: 'typescript' });

      expect(result.violations).toContainEqual(
        expect.objectContaining({ principle: 'SRP' })
      );
      expect(result.compliance_score).toBeLessThan(70);
    });

    it('should pass for well-designed code', async () => {
      const code = `
        class UserRepository {
          save(user: User): void {}
          find(id: string): User {}
          delete(id: string): void {}
        }
      `;

      const result = await skill.analyze({ code, language: 'typescript' });

      expect(result.violations).toHaveLength(0);
      expect(result.compliance_score).toBeGreaterThan(90);
    });

    it('should handle invalid input gracefully', async () => {
      await expect(
        skill.analyze({ code: '', language: 'typescript' })
      ).rejects.toThrow('INVALID_INPUT');
    });
  });
});
```

## Error Handling

```yaml
errors:
  INVALID_INPUT:
    code: 400
    message: "Invalid input parameters"
    recovery: "Check parameter schema"

  UNSUPPORTED_LANGUAGE:
    code: 400
    message: "Language not supported"
    recovery: "Use supported language"

  ANALYSIS_TIMEOUT:
    code: 408
    message: "Analysis exceeded time limit"
    recovery: "Reduce code size or complexity"

  CONTEXT_OVERFLOW:
    code: 413
    message: "Code too large for analysis"
    recovery: "Split into smaller modules"
```

## Integration

```yaml
requires:
  - code_parser
  - ast_analyzer

emits:
  - solid_analysis_completed
  - violation_detected

consumed_by:
  - 01-design-principles (bonded agent)
  - 04-refactoring (for smell detection)
```

Overview

This skill applies and validates SOLID principles in object-oriented code to identify design issues and suggest concrete improvements. It provides a compliance score, lists violations per principle, and can optionally show example fixes for detected problems. The skill is language-aware and configurable for strictness and focus areas.

How this skill works

The analyzer parses the provided code into an AST and inspects structural and behavioral indicators tied to each SOLID principle (SRP, OCP, LSP, ISP, DIP). It reports violations with locations, severity, and actionable suggestions, and computes a numeric compliance score along with per-principle metrics. Options let you focus on selected principles, adjust validation strictness, and include example refactorings.

When to use it

  • Assess design quality during code reviews or refactoring planning
  • Validate new implementations against SOLID before merging
  • Identify responsibility or dependency problems in legacy or monolithic classes
  • Measure progress after refactorings by tracking compliance score over time
  • Enforce architectural guidance in CI pipelines or automated checks

Best practices

  • Start with relaxed analysis to get broad insights, then increase strictness for targeted cleanup
  • Run focused checks on one principle when addressing a specific smell (e.g., ISP for large interfaces)
  • Use suggestions as a starting point; review proposed refactorings to fit domain constraints
  • Split large files into modules before analyzing to avoid context overflow errors
  • Combine automated results with manual review for behavioral issues not detectable statically

Example use cases

  • Detect a god class violating SRP and get concrete extraction suggestions (services, repositories)
  • Find switch/type checks that indicate OCP violations and propose strategy/template pattern opportunities
  • Spot overridden methods that break LSP and highlight pre/postcondition mismatches
  • Locate large interfaces or unused methods to guide ISP-driven interface segregation
  • Reveal direct instantiation and missing abstractions to recommend dependency inversion via constructor injection

FAQ

Which languages are supported?

The skill supports common OO languages: TypeScript, JavaScript, Python, Java, C#, Go, and Ruby.

What does strictness control?

Strictness adjusts detection sensitivity: relaxed finds obvious issues, normal balances precision and recall, strict flags subtle or borderline design smells.

How large can the code input be?

Inputs should be between 10 and 50,000 characters; very large modules should be split to avoid context overflow.