Architectural patterns and design principles for scalable, maintainable systems. Use when designing systems, refactoring architecture, or choosing patterns.
Provides architectural patterns and design principles for building scalable, maintainable systems. Use when designing new systems, refactoring architecture, or choosing between patterns like Clean Architecture, Microservices, or Event-Driven designs.
/plugin marketplace add mjohnson518/claude_superpowers/plugin install mjohnson518-claude-superpowers@mjohnson518/claude_superpowersThis skill inherits all available tools. When active, it can use any tool Claude has access to.
Guide architectural decisions with proven patterns for building scalable, maintainable, and testable systems.
┌─────────────────────────────────────────────────────────────┐
│ Frameworks & Drivers │
│ ┌─────────────────────────────────────────────────────────┐│
│ │ Interface Adapters ││
│ │ ┌─────────────────────────────────────────────────────┐││
│ │ │ Application Business Rules │││
│ │ │ ┌─────────────────────────────────────────────────┐│││
│ │ │ │ Enterprise Business Rules ││││
│ │ │ │ (Domain/Entities) ││││
│ │ │ └─────────────────────────────────────────────────┘│││
│ │ └─────────────────────────────────────────────────────┘││
│ └─────────────────────────────────────────────────────────┘│
└─────────────────────────────────────────────────────────────┘
Key Principles:
Layer Responsibilities:
| Layer | Contains | Depends On |
|---|---|---|
| Entities | Business objects, domain logic | Nothing |
| Use Cases | Application-specific logic | Entities |
| Adapters | Controllers, gateways, presenters | Use Cases, Entities |
| Frameworks | Web framework, database, UI | All inner layers |
┌──────────────┐
│ Driving │
│ Adapter │
│ (REST API) │
└──────┬───────┘
│
┌──────▼───────┐
│ Port │
│ (Interface) │
└──────┬───────┘
│
┌──────────────────────────▼──────────────────────────┐
│ Application Core │
│ ┌────────────────────────────────────────────────┐ │
│ │ Domain Model │ │
│ │ (Entities + Business Rules) │ │
│ └────────────────────────────────────────────────┘ │
└──────────────────────────┬──────────────────────────┘
│
┌──────▼───────┐
│ Port │
│ (Interface) │
└──────┬───────┘
│
┌──────▼───────┐
│ Driven │
│ Adapter │
│ (Database) │
└──────────────┘
Key Concepts:
Strategic Patterns:
| Pattern | Purpose |
|---|---|
| Bounded Context | Define clear boundaries between domains |
| Ubiquitous Language | Shared vocabulary between devs and domain experts |
| Context Mapping | Define relationships between bounded contexts |
Tactical Patterns:
| Pattern | Purpose | Example |
|---|---|---|
| Entity | Object with identity | User, Order |
| Value Object | Immutable, no identity | Money, Address |
| Aggregate | Cluster of entities | Order + OrderItems |
| Repository | Abstraction for persistence | UserRepository |
| Domain Event | Something that happened | OrderPlaced |
| Domain Service | Logic not belonging to entity | PaymentProcessor |
When to Use:
When to Avoid:
┌─────────┐ ┌──────────────┐ ┌─────────┐
│ Service │────▶│ Event Broker │────▶│ Service │
│ A │ │ (Kafka/SQS) │ │ B │
└─────────┘ └──────────────┘ └─────────┘
│ │
└──────────── Events ────────────────┘
Patterns:
┌─────────┐ ┌─────────────┐ ┌───────────┐
│ Client │────▶│ API Gateway │────▶│ Service A │
└─────────┘ └──────┬──────┘ ├───────────┤
│ │ Service B │
└───────────▶├───────────┤
│ Service C │
└───────────┘
Gateway Responsibilities:
enum CircuitState {
CLOSED, // Normal operation
OPEN, // Failing, reject calls
HALF_OPEN // Testing recovery
}
class CircuitBreaker {
private state = CircuitState.CLOSED;
private failures = 0;
private threshold = 5;
async execute<T>(fn: () => Promise<T>): Promise<T> {
if (this.state === CircuitState.OPEN) {
throw new CircuitOpenError();
}
try {
const result = await fn();
this.onSuccess();
return result;
} catch (error) {
this.onFailure();
throw error;
}
}
}
async function retryWithBackoff<T>(
fn: () => Promise<T>,
maxRetries: number = 3
): Promise<T> {
for (let i = 0; i < maxRetries; i++) {
try {
return await fn();
} catch (error) {
if (i === maxRetries - 1) throw error;
await sleep(Math.pow(2, i) * 1000); // 1s, 2s, 4s
}
}
}
Isolate failures to prevent cascade:
class Bulkhead {
private semaphore: Semaphore;
constructor(maxConcurrent: number) {
this.semaphore = new Semaphore(maxConcurrent);
}
async execute<T>(fn: () => Promise<T>): Promise<T> {
await this.semaphore.acquire();
try {
return await fn();
} finally {
this.semaphore.release();
}
}
}
interface UserRepository {
findById(id: string): Promise<User | null>;
findByEmail(email: string): Promise<User | null>;
save(user: User): Promise<void>;
delete(id: string): Promise<void>;
}
// Implementation details hidden
class PostgresUserRepository implements UserRepository {
// ...database-specific code
}
interface UnitOfWork {
users: UserRepository;
orders: OrderRepository;
commit(): Promise<void>;
rollback(): Promise<void>;
}
┌──────────────┐ ┌──────────────────┐
│ Commands │────────▶│ Write Model │
│ (Create, │ │ (Normalized) │
│ Update) │ └────────┬─────────┘
└──────────────┘ │
│ Sync
▼
┌──────────────┐ ┌──────────────────┐
│ Queries │────────▶│ Read Model │
│ (GetById, │ │ (Denormalized) │
│ Search) │ └──────────────────┘
└──────────────┘
| Scenario | Recommended Pattern |
|---|---|
| Complex domain logic | DDD + Clean Architecture |
| High scalability | Microservices + Event-Driven |
| Simple CRUD | MVC / Layered Architecture |
| Real-time updates | Event Sourcing + CQRS |
| Legacy migration | Strangler Fig Pattern |
| API aggregation | BFF (Backend for Frontend) |
| Anti-Pattern | Problem | Solution |
|---|---|---|
| Big Ball of Mud | No structure | Introduce bounded contexts |
| Distributed Monolith | Coupled services | True service boundaries |
| Anemic Domain Model | Logic in services | Rich domain model |
| Golden Hammer | One pattern for all | Right tool for job |
| Premature Abstraction | Over-engineering | YAGNI, iterate |
Before choosing an architecture:
What are the scaling requirements?
What is the team size/structure?
What are the consistency requirements?
What is the expected rate of change?
What are the operational capabilities?
This skill should be used when the user asks to "create a slash command", "add a command", "write a custom command", "define command arguments", "use command frontmatter", "organize commands", "create command with file references", "interactive command", "use AskUserQuestion in command", or needs guidance on slash command structure, YAML frontmatter fields, dynamic arguments, bash execution in commands, user interaction patterns, or command development best practices for Claude Code.
This skill should be used when the user asks to "create an agent", "add an agent", "write a subagent", "agent frontmatter", "when to use description", "agent examples", "agent tools", "agent colors", "autonomous agent", or needs guidance on agent structure, system prompts, triggering conditions, or agent development best practices for Claude Code plugins.
This skill should be used when the user asks to "create a hook", "add a PreToolUse/PostToolUse/Stop hook", "validate tool use", "implement prompt-based hooks", "use ${CLAUDE_PLUGIN_ROOT}", "set up event-driven automation", "block dangerous commands", or mentions hook events (PreToolUse, PostToolUse, Stop, SubagentStop, SessionStart, SessionEnd, UserPromptSubmit, PreCompact, Notification). Provides comprehensive guidance for creating and implementing Claude Code plugin hooks with focus on advanced prompt-based hooks API.