ワンクリックで
ddd-refactor
// Analyzes and refactors code using Domain-Driven Design principles. Use when refactoring domain models, identifying DDD anti-patterns, improving domain clarity, or applying tactical/strategic DDD patterns.
// Analyzes and refactors code using Domain-Driven Design principles. Use when refactoring domain models, identifying DDD anti-patterns, improving domain clarity, or applying tactical/strategic DDD patterns.
Writes, edits, and creates dbt models following best practices. Use when user needs to create new dbt SQL models, update existing models, or convert raw SQL to dbt format. Handles staging, intermediate, and mart models with proper config blocks, CTEs, and documentation.
Apply Domain-Driven Design, Clean Architecture, CQRS, and command/query patterns to code reviews and feature design. Use when analyzing or designing code in Application, Service, Infrastructure, DataAccess, Validation, Domain, or Functions projects, or when addressing architectural concerns, layering, mapping, entities, value objects, repositories, or validators in the Rome Repair Order Service.
Guide for DDD strategic design - analyzing domains through structured questioning, conducting stakeholder interviews (PM/domain experts/users), and producing Bounded Context analysis, Context Maps, and Ubiquitous Language. Use when user needs help understanding domain boundaries, planning domain interviews, or structuring DDD strategic artifacts.
Win competitive rounds: run a clean process, deliver value previews before asking, coordinate partners, and manage timelines. Use when you're trying to close a 'must win' deal against other funds.
End-to-end associate workflow with time-boxed gates: thesis -> sourcing -> meetings -> diligence -> memo, ending with either IC-ready memo or explicit kill decision. Use when you need to run the full pipeline for a sector or a specific deal.
DearTs Framework 开发技能。基于 SDL3 + ImGui 的 C++20 现代应用框架,提供完整的应用生命周期管理、类型安全事件系统、Content Registry 和插件架构。适用于 DearTs Framework 相关的所有开发任务,包括应用程序开发、事件驱动架构、插件系统、多视图应用等。
| name | ddd-refactor |
| description | Analyzes and refactors code using Domain-Driven Design principles. Use when refactoring domain models, identifying DDD anti-patterns, improving domain clarity, or applying tactical/strategic DDD patterns. |
| allowed-tools | Read, Grep, Glob, Bash, Edit, Write |
Comprehensive Domain-Driven Design refactoring framework based on Eric Evans' DDD principles.
CRITICAL: Always load the DDD principles first:
Read: plugins/ddd-refactor/resources/ddd-principles.json
This JSON contains 19+ principles with definitions, code smells, and refactoring guidance.
Understand the Domain:
Scan for Code Smells:
Technical Exploration:
# Find potential entities
grep -r "class.*Entity" --include="*.{js,ts,java,cs,py}"
# Find service classes (potential logic that belongs in domain)
grep -r "class.*Service" --include="*.{js,ts,java,cs,py}"
# Find repositories
grep -r "Repository" --include="*.{js,ts,java,cs,py}"
# Find domain events (or lack thereof)
grep -r "Event\|event" --include="*.{js,ts,java,cs,py}"
Based on loaded DDD principles:
Define Bounded Contexts
Establish Ubiquitous Language
Prioritize Refactoring
Apply patterns systematically:
1. Entities - Identity-based objects
2. Value Objects - Immutable descriptive objects
3. Aggregates - Consistency boundaries
4. Domain Events - Significant occurrences
5. Repositories - Aggregate persistence
6. Domain Services - Stateless operations
7. Factories - Complex creation
8. Layered Architecture
Verify Improvements:
Testing Strategy:
File: src/orders/OrderService.java:45-78
Smell: Anemic domain model - Order entity has only getters/setters
Principle Violated: Entity Pattern
Impact: Business logic scattered in services, hard to test and maintain
Principle: Entity (from ddd-principles.json)
Category: Tactical Pattern
Key Point: Entities should encapsulate business rules and behavior
When to Apply: Objects with identity that change over time
Step 1: Move validation logic from OrderService to Order entity
Step 2: Add domain methods: order.cancel(), order.ship(), order.addItem()
Step 3: Enforce invariants within entity methods
Step 4: Raise domain events for significant state changes
Step 5: Update OrderService to orchestrate, not contain logic
// BEFORE: Anemic Domain Model (Anti-pattern)
class Order {
private id: string;
private items: OrderItem[];
private status: string;
// Only getters and setters
getId(): string { return this.id; }
getStatus(): string { return this.status; }
setStatus(status: string): void { this.status = status; }
}
class OrderService {
cancelOrder(order: Order): void {
// Business logic in service layer
if (order.getStatus() === 'SHIPPED') {
throw new Error('Cannot cancel shipped order');
}
order.setStatus('CANCELLED');
this.emailService.sendCancellationEmail(order);
}
}
// AFTER: Rich Domain Model (DDD Pattern)
class Order {
private id: OrderId;
private items: OrderItem[];
private status: OrderStatus;
private events: DomainEvent[] = [];
constructor(id: OrderId, items: OrderItem[]) {
this.id = id;
this.items = items;
this.status = OrderStatus.PENDING;
}
// Business logic in entity
cancel(): void {
if (!this.canBeCancelled()) {
throw new OrderCannotBeCancelledException(
'Cannot cancel order in status: ' + this.status
);
}
this.status = OrderStatus.CANCELLED;
this.recordEvent(new OrderCancelled(this.id, new Date()));
}
private canBeCancelled(): boolean {
return this.status !== OrderStatus.SHIPPED
&& this.status !== OrderStatus.DELIVERED;
}
getDomainEvents(): DomainEvent[] {
return [...this.events];
}
private recordEvent(event: DomainEvent): void {
this.events.push(event);
}
}
// Service becomes thin orchestrator
class OrderService {
constructor(
private orderRepository: OrderRepository,
private eventBus: EventBus
) {}
async cancelOrder(orderId: string): Promise<void> {
const order = await this.orderRepository.findById(orderId);
order.cancel(); // Domain logic stays in domain
await this.orderRepository.save(order);
// Publish events for other bounded contexts
order.getDomainEvents().forEach(event => {
this.eventBus.publish(event);
});
}
}
Benefits:
Metrics:
// Value Object with immutability
class Money {
constructor(
private readonly amount: number,
private readonly currency: string
) {
if (amount < 0) throw new Error('Amount cannot be negative');
}
add(other: Money): Money {
if (this.currency !== other.currency) {
throw new Error('Currency mismatch');
}
return new Money(this.amount + other.amount, this.currency);
}
equals(other: Money): boolean {
return this.amount === other.amount
&& this.currency === other.currency;
}
}
// Aggregate with encapsulation
public class Order {
private final OrderId id;
private final List<OrderLine> lines;
private OrderStatus status;
// Package-private constructor (use factory)
Order(OrderId id) {
this.id = Objects.requireNonNull(id);
this.lines = new ArrayList<>();
this.status = OrderStatus.DRAFT;
}
public void addLine(Product product, Quantity quantity) {
if (this.status != OrderStatus.DRAFT) {
throw new OrderAlreadySubmittedException();
}
this.lines.add(new OrderLine(product, quantity));
}
// Factory method
public static Order create(OrderId id) {
return new Order(id);
}
}
from dataclasses import dataclass
from typing import List
# Value Object with frozen dataclass
@dataclass(frozen=True)
class EmailAddress:
value: str
def __post_init__(self):
if '@' not in self.value:
raise ValueError('Invalid email address')
# Entity with behavior
class Customer:
def __init__(self, customer_id: str, email: EmailAddress):
self._id = customer_id
self._email = email
self._events: List[DomainEvent] = []
def change_email(self, new_email: EmailAddress) -> None:
if self._email != new_email:
old_email = self._email
self._email = new_email
self._events.append(
EmailChanged(self._id, old_email, new_email)
)
resources/ddd-principles.json for complete definitionsCHECKLIST.md for full anti-pattern listThis skill can be:
/refactor commandddd-analyzer agent for autonomous analysis