Back to Architecture & Design Patterns

SOLID Principles Architect

ooprefactoringarchitectureclean-codepython
4.4 (41)🕒 2025-10-29Source ↗

Install this skill

npx skills add SmidigStorm/regelverk-python

Works across Claude Code, Cursor, Codex, Copilot & Antigravity

What this skill does

  • Detects violations of SRP, OCP, LSP, ISP, and DIP in existing class hierarchies
  • Suggests structural refactorings for monolithic or overly complex classes
  • Promotes the use of Python Protocols and Abstract Base Classes for loose coupling
  • Provides actionable checklists for code reviews focused on maintainability
  • Guides the transition from concrete implementation dependencies to abstraction-based design

When to use it

  • During code reviews when classes grow beyond 200 lines
  • When adding new features requires modifying existing, stable logic
  • When unit testing is blocked by tight coupling or excessive external dependencies
  • When designing new systems that need to remain extensible

When not to use it

  • For rapid prototyping or throwaway scripts where architecture is secondary to speed
  • In highly performance-constrained code where abstraction overhead is unacceptable
  • For extremely small, single-purpose functions that do not involve OOP

How to invoke it

Example prompts that trigger this skill:

  • Analyze this module and identify any SOLID principle violations.
  • Help me refactor these classes to adhere to the Interface Segregation Principle.
  • Review this codebase for tight coupling and suggest how to apply Dependency Inversion.
  • Refactor this rule engine class to follow the Open/Closed principle.
  • Check if my current class hierarchy violates Liskov Substitution.

Example workflow

  1. Load the relevant source files into the context.
  2. Prompt the agent to perform an architectural audit of the target modules.
  3. Review the identified violations and the proposed refactoring strategy.
  4. Apply the suggested code changes to split interfaces or introduce abstractions.
  5. Run existing test suites to confirm that functional behavior remains unchanged.

Prerequisites

  • Basic knowledge of Python object-oriented programming
  • Existing codebase with class structures

Pitfalls & limitations

  • !Over-engineering: applying complex abstractions to code that does not need them
  • !Increased file counts: splitting large classes into many small modules can overwhelm navigation
  • !Performance overhead: excessive use of abstract layers can impact hot code paths

FAQ

Do I need to apply all five principles at once?
No, you should prioritize the principles that address your current specific bottlenecks, such as SRP for readability or DIP for testability.
How does this interact with Python's dynamic nature?
The skill encourages using Python Protocols and Type Hints to enforce static contracts while still maintaining Python's flexibility.
Will this tool break my existing functionality?
Refactoring inherently carries risk. This tool identifies design flaws, but you should always run your test suite after applying suggested changes.

How it compares

Unlike a generic code review prompt, this skill forces the agent to analyze the structure against specific architectural rules, resulting in higher-quality refactoring suggestions rather than simple cleanup.

Source & trust

🕒 Updated 2025-10-29🛡 no risky patterns found

From the source: “# SOLID Principles Skill You are assisting with code that must follow SOLID principles strictly. ## Principles to Enforce ### 1. Single Responsibility Principle (SRP) - Each class should have ONE reason to change - Each function should do ONE thing well - Separate concerns: business logic, data acce…”

View the full SKILL.md source

# SOLID Principles Skill

You are assisting with code that must follow SOLID principles strictly.

## Principles to Enforce

### 1. Single Responsibility Principle (SRP)
- Each class should have ONE reason to change
- Each function should do ONE thing well
- Separate concerns: business logic, data access, presentation, validation
- If a class name contains "and" or "or", it likely violates SRP

**Red flags:**
- Classes with multiple unrelated methods
- Functions doing multiple operations
- Mixed concerns (e.g., validation + persistence in same method)

### 2. Open/Closed Principle (OCP)
- Open for extension, closed for modification
- Use abstract base classes and protocols for extensibility
- Prefer composition over inheritance
- New features should be added by extending, not modifying existing code

**Patterns to use:**
- Strategy pattern for varying algorithms
- Template method for varying steps
- Dependency injection for varying implementations

### 3. Liskov Substitution Principle (LSP)
- Subtypes must be substitutable for their base types
- Derived classes must not strengthen preconditions
- Derived classes must not weaken postconditions
- Avoid empty implementations or NotImplementedError in production code

**Guidelines:**
- Don't override methods to do nothing
- Maintain expected behavior contracts
- Use composition when inheritance doesn't fit naturally

### 4. Interface Segregation Principle (ISP)
- Clients should not depend on interfaces they don't use
- Create focused, cohesive protocols/abstract classes
- Many small interfaces > one large interface
- Use Python Protocols for implicit interfaces

**Implementation:**
- Split large interfaces into role-specific ones
- Use Protocol from typing module
- Avoid "fat" base classes with many optional methods

### 5. Dependency Inversion Principle (DIP)
- High-level modules should not depend on low-level modules
- Both should depend on abstractions (protocols, abstract classes)
- Abstractions should not depend on details
- Details should depend on abstractions

**Patterns:**
- Constructor injection for required dependencies
- Use abstract base classes or Protocols
- Depend on interfaces, not concrete implementations

## Code Review Checklist

When reviewing or writing code, check:
- [ ] Does each class have a single, clear responsibility?
- [ ] Can new behavior be added without modifying existing code?
- [ ] Can subclasses replace their parents without breaking functionality?
- [ ] Are interfaces focused and cohesive?
- [ ] Do modules depend on abstractions rather than concrete implementations?

## Practical Application for Admission Rules System

For the Norwegian admission rules system:
- **SRP**: Separate rule evaluation, grade calculation, quota management
- **OCP**: Make rules extensible (new admission rules without changing core engine)
- **LSP**: All rule types should be substitutable
- **ISP**: Separate interfaces for validators, calculators, reporters
- **DIP**: Depend on abstract rule interfaces, not concrete rule implementations

## Response Format

When applying SOLID principles:
1. Identify which principle(s) are relevant
2. Explain the violation if any exists
3. Provide refactored code following the principle(s)
4. Explain the benefit of the refactoring

Quoted from SmidigStorm/regelverk-python for reference — see the original for the authoritative, latest version.

📄 Full skill instructions — original source: SmidigStorm/regelverk-python
The SOLID Principles Architect skill provides a systematic framework for evaluating and refactoring object-oriented codebases to improve maintainability and scalability. It focuses on applying the five core principles—Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, and Dependency Inversion—to identify design flaws and architectural technical debt. By analyzing class relationships and interface definitions, this skill guides developers through structural improvements that make code easier to test, extend, and modify. Whether you are building complex business logic, such as rule engines or validation systems, or simply cleaning up monolithic class structures, this tool ensures your code adheres to professional standards. It is an essential aid for backend engineers and system architects who need to maintain clean, modular, and decoupled Python software without introducing regressions during structural changes.

How to Use This Skill Unit

Option A: Project-Specific (Recommended)

  1. Click "Download" above
  2. In your project, create the directory: .agent/skills/solid-principles/
  3. Save the file as SKILL.md
  4. The agent will automatically discover the skill based on its description.

Option B: Global Installation (All Agents)

Save the file to these locations to make it available across all projects:

  • Claude Code: ~/.claude/skills/SmidigStorm/regelverk-python/solid-principles/SKILL.md
  • Cursor: ~/.cursor/skills/SmidigStorm/regelverk-python/solid-principles/SKILL.md
  • Antigravity: ~/.gemini/antigravity/skills/SmidigStorm/regelverk-python/solid-principles/SKILL.md

🚀 Install with CLI:
npx skills add SmidigStorm/regelverk-python

Read the Master Guide: Mastering Agent Skills

Recommended Rules

View more rules

Recommended Workflows

View more workflows

Recommended MCP Servers

View more MCP servers

Take It Further

Maximize your productivity with these powerful resources

📋

Define Your Standards

Set up coding standards to ensure this workflow produces consistent, high-quality results.

Browse Rules Library
📖

Master Workflows

Learn how to create custom workflows, use Turbo Mode, and build your automation library.

Complete Guide

How to use this Skill in Claude Code & Cursor

For Claude Code (CLI)

To use this skill in Claude Code, copy the rule content into your project's custom instructions or follow our Add-Skill CLI guide. This ensures Claude follows your standards during every code generation.

For Cursor & Windsurf

For Cursor or Windsurf, individual skills are best used in the "Rules for AI" section. This specific unit helps the agent avoid architecture & design patterns issues, leading to cleaner, more efficient code.

Why the skill format matters: the standardized Agent Skills format lets your AI agent load detailed instructions only when they are relevant, keeping your prompt clean while improving results.

Source & attribution

This skill is categorized under Architecture & Design Patterns and is published by SmidigStorm, maintained in SmidigStorm/regelverk-python.

← Browse All Agent Skills
Sponsored AI assistant. Recommendations may be paid.