Loading...
Loading...
Audits code for design pattern opportunities and anti-patterns — identifies places where a specific GoF or architectural pattern would solve an observable problem, and flags misapplied patterns that add complexity without benefit. Generates fix prompts. Trigger phrases: "design patterns", "pattern check", "pattern review", "refactoring patterns", "pattern analysis".
npx skill4agent add nishilbhave/codeprobe-claude codeprobe-patterns../codeprobe/shared-preamble.md../codeprobe/references/fullcodeprobe-solidcodeprobe-solidPATTERN-codeprobe-solidcodeprobe-architecturePATTERN-codeprobe-architecturecodeprobe-code-smellsPATTERN-| Observed Problem | Candidate Pattern | How to Detect | Confidence | Severity |
|---|---|---|---|---|
| Complex object construction with 4+ optional params | Builder | Constructor or factory method with 4+ optional/nullable parameters. Methods that build objects step-by-step using setters then | High | Minor |
Duplicated | Factory | Search for | High | Major |
| Switch on type to select behavior (when a specific pattern applies) | Strategy | Switch/if-else chain where each branch executes a different algorithm or behavior — not just returning a value. Must have 3+ branches and the variants are likely to grow. Only flag if NOT already covered by an OCP finding. | High | Major |
| Object behavior changes based on internal state field | State | A class with methods containing if/switch on | Medium | Minor |
| Multiple listeners need to react to a change | Observer / Event Dispatcher | A method that directly calls 3+ other services/handlers after a state change (e.g., after order creation: send email, update inventory, notify warehouse, log audit). Should be events. | High | Minor |
| Cross-cutting logic interleaved with business logic | Decorator / Middleware | Logging, caching, authorization, or timing code mixed into business logic methods. Same cross-cutting concern copy-pasted across 3+ methods. | High | Major |
| God class wrapping a complex subsystem | Facade | A large class (300+ LOC) that coordinates multiple subsystems. Clients only need a simplified interface. Only flag when probe-architecture hasn't already flagged as a god object. | Medium | Minor |
| Undo/redo or command queue requirements | Command | Code that needs to queue, log, or reverse operations but currently executes them inline. | Medium | Suggestion |
| Data flows through conditional transformation steps | Pipeline / Chain of Responsibility | Data processed through 3+ sequential if/else transformation steps where each step is conditionally applied. Could be a pipeline of composable stages. | Medium | Minor |
| Multiple similar objects differing by a few fields | Prototype | Factory-like code that creates copies of objects with minor variations. | Low | Suggestion |
| Anti-Pattern | What to Detect | How to Detect | Severity |
|---|---|---|---|
| Singleton for dependency hiding | Class uses | Search for | Major |
| Pass-through Repository | Repository class wrapping ORM (Eloquent, Doctrine, Prisma) where every method is a 1-line delegation with zero added abstraction, caching, or query logic. The repository adds a layer without value. | Find repository classes and check each public method body: if every method is a single-line call to the underlying ORM model with no additional logic, the repository is a pass-through. | Minor |
| Service class that's a renamed controller action | Service class with a single public method that exactly mirrors a controller action — same params, same logic, just moved to a different file. Adds indirection without reuse. | Find service classes with only one public method. Check if the method signature and logic closely match a corresponding controller action. Look for zero reuse across the codebase (only one caller). | Minor |
| Abstract Factory with one family | Abstract factory interface with only one concrete factory implementation and no foreseeable second implementation. Over-abstraction. | Find abstract factory interfaces/classes. Count the number of concrete implementations. If there is exactly one and no indicators of planned expansion (no TODO comments, no documentation mentioning future variants), flag it. | Suggestion |
PATTERN-PATTERN-001PATTERN-002$typeNotificationSenderNotificationChannelsend(Message $message)EmailChannelSmsChannelPushChannelNotificationChannelFactoryReportBuilder$title$subtitle$dateRange$format$includeCharts$paperSize$orientationReportBuilderConfigbuild()AuditLoggerapp/Services/AuditLogger.phpAuditLogger::getInstance()AuditLogger::getInstance()UserRepositoryInterfaceUserRepositoryapp/Repositories/findcreateupdatedelete