From cook-en
Analyzes code for design patterns usage and SOLID compliance, suggests applicable patterns with examples, detects anti-patterns, and proposes refactors via options like --suggest and --solid.
npx claudepluginhub wasabeef/claude-code-cookbook --plugin cook-en## Design Patterns Suggests design patterns for your code and checks if it follows SOLID principles. ### Usage ### Options - `--suggest`: Suggest applicable patterns (default) - `--analyze`: Analyze existing pattern usage - `--refactor`: Generate refactoring proposals - `--solid`: Check compliance with SOLID principles - `--anti-patterns`: Detect anti-patterns ### Basic Examples ### Pattern Categories #### 1. Creational Patterns - **Factory Pattern**: Abstracts object creation - **Builder Pattern**: Step-by-step construction of complex objects - **Singleton Pattern**: Ensures on...
/design-patternsSuggests applicable design patterns for the codebase, analyzes usage, checks SOLID compliance, detects anti-patterns, and proposes refactorings via options.
/design-patternsSuggests applicable design patterns for the codebase, analyzes current usage, checks SOLID principles, detects anti-patterns, and proposes refactorings with code examples.
/design-patternsSuggests design patterns for code, analyzes existing usage, proposes refactors, verifies SOLID principles, and detects anti-patterns. Supports --suggest, --analyze, --refactor, --solid, --anti-patterns flags.
/design-patternsSuggests applicable design patterns for the codebase or targets, analyzes usage, checks SOLID compliance, detects anti-patterns, and proposes refactorings via options.
/design-patternsSuggests design patterns for codebase or target file, analyzes usage, evaluates SOLID compliance, detects anti-patterns, and suggests refactors. Supports --suggest, --analyze, --solid flags.
/design-patternsSuggests applicable design patterns, analyzes existing usage, proposes refactors, verifies SOLID principles, and detects anti-patterns in code targets via optional flags.
Share bugs, ideas, or general feedback.
Suggests design patterns for your code and checks if it follows SOLID principles.
/design-patterns [analysis_target] [options]
--suggest: Suggest applicable patterns (default)--analyze: Analyze existing pattern usage--refactor: Generate refactoring proposals--solid: Check compliance with SOLID principles--anti-patterns: Detect anti-patterns# Analyze patterns for entire project
/design-patterns
# Suggest patterns for specific file
/design-patterns src/services/user.js --suggest
# Check SOLID principles
/design-patterns --solid
# Detect anti-patterns
/design-patterns --anti-patterns
S - Single Responsibility (one class, one job)
O - Open/Closed (open for extension, closed for modification)
L - Liskov Substitution (subtypes should be replaceable)
I - Interface Segregation (don't force unused methods)
D - Dependency Inversion (depend on abstractions, not details)
Design Pattern Analysis Report
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Currently Used Patterns
├─ Observer Pattern: EventEmitter (12 instances)
├─ Factory Pattern: UserFactory (3 instances)
├─ Singleton Pattern: DatabaseConnection (1 instance)
└─ Strategy Pattern: PaymentProcessor (5 instances)
Recommended Patterns
├─ [HIGH] Repository Pattern
│ └─ Where: src/models/*.js
│ └─ Why: Separate data access from business logic
│ └─ Example:
│ class UserRepository {
│ async findById(id) { ... }
│ async save(user) { ... }
│ }
│
├─ [MED] Command Pattern
│ └─ Where: src/api/handlers/*.js
│ └─ Why: Standardize how requests are handled
│
└─ [LOW] Decorator Pattern
└─ Where: src/middleware/*.js
└─ Why: Better way to combine features
SOLID Violations Found
├─ [S] UserService: Does too much (auth AND authorization)
├─ [O] PaymentGateway: Must change code to add payment types
├─ [D] EmailService: Depends on specific classes, not interfaces
└─ [I] IDataStore: Has methods nobody uses
How to Fix
1. Split UserService into AuthService and AuthorizationService
2. Add a PaymentStrategy interface for new payment types
3. Create an EmailService interface
4. Break up IDataStore into smaller interfaces
# See what happens if you use a pattern
/design-patterns --impact-analysis Repository
# Get example code for a pattern
/design-patterns --generate Factory --for src/models/Product.js
# Find patterns that work well together
/design-patterns --combine --context "API with caching"
# Check your architecture
/design-patterns --architecture MVC
class OrderService {
processOrder(order, paymentType) {
if (paymentType === "credit") {
// Credit card processing
} else if (paymentType === "paypal") {
// PayPal processing
}
// Other payment methods...
}
}
// Strategy interface
class PaymentStrategy {
process(amount) {
throw new Error("Must implement process method");
}
}
// Concrete strategies
class CreditCardPayment extends PaymentStrategy {
process(amount) {
/* Implementation */
}
}
// Context
class OrderService {
constructor(paymentStrategy) {
this.paymentStrategy = paymentStrategy;
}
processOrder(order) {
this.paymentStrategy.process(order.total);
}
}