進行代碼重構或新增模組時觸發。確保程式碼符合 Clean Architecture + DDD + CQRS 的層次關係,防止架構腐化。
Detects architecture violations during refactoring or new module creation. Enforces Clean Architecture and DDD layering rules to prevent dependency violations, ensuring domain layers remain framework-free.
/plugin marketplace add knowlet/skills/plugin install knowlet-skills@knowlet/skillsThis skill inherits all available tools. When active, it can use any tool Claude has access to.
確保程式碼放對位置,嚴格遵守領域驅動設計 (DDD) 與 Clean Architecture 的層次關係。
┌─────────────────────────────────────────────────┐
│ Presentation Layer │
│ (Controllers, Views, DTOs) │
├─────────────────────────────────────────────────┤
│ Application Layer │
│ (Use Cases, Application Services, Commands) │
├─────────────────────────────────────────────────┤
│ Domain Layer │
│ (Entities, Value Objects, Domain Services, │
│ Aggregates, Domain Events, Repositories IF) │
├─────────────────────────────────────────────────┤
│ Infrastructure Layer │
│ (Repository Impl, External Services, DB, MQ) │
└─────────────────────────────────────────────────┘
核心原則:依賴只能向內指向,內層不能知道外層的存在
Presentation → Application → Domain ← Infrastructure
| 禁止情況 | 說明 | 違規範例 |
|---|---|---|
| Domain → Infrastructure | 領域層不能依賴基礎設施 | Domain Entity import JDBC |
| Domain → Application | 領域層不能依賴應用層 | Entity import UseCase |
| Domain → Presentation | 領域層不能依賴展示層 | Entity import Controller |
| Application → Presentation | 應用層不能依賴展示層 | UseCase import DTO |
Domain 層引用資料庫驅動
// ❌ 違規:Domain 層出現 JDBC/JPA 實作
package com.example.domain.entity;
import java.sql.Connection; // 禁止!
import javax.persistence.EntityManager; // 禁止!
Domain 層引用 Spring Framework
// ❌ 違規:Domain 層出現 Spring 註解
package com.example.domain.service;
import org.springframework.stereotype.Service; // 禁止!
import org.springframework.beans.factory.annotation.Autowired; // 禁止!
Domain 層引用外部 HTTP 客戶端
// ❌ 違規:Domain 層直接呼叫外部服務
package com.example.domain.service;
import org.springframework.web.client.RestTemplate; // 禁止!
Application 層包含業務邏輯
Repository 實作暴露在 Domain 層
src/main/java/com/example/
├── presentation/ # 展示層
│ ├── controller/
│ ├── dto/
│ │ ├── request/
│ │ └── response/
│ └── assembler/
│
├── application/ # 應用層
│ ├── command/ # CQRS Command
│ │ └── handler/
│ ├── query/ # CQRS Query
│ │ └── handler/
│ ├── service/ # Application Services
│ └── port/ # 輸出埠口定義
│ ├── inbound/
│ └── outbound/
│
├── domain/ # 領域層 (純 POJO)
│ ├── model/
│ │ ├── aggregate/
│ │ ├── entity/
│ │ └── valueobject/
│ ├── service/ # Domain Services
│ ├── event/ # Domain Events
│ ├── repository/ # Repository 介面
│ └── exception/ # Domain Exceptions
│
└── infrastructure/ # 基礎設施層
├── persistence/
│ ├── repository/ # Repository 實作
│ └── entity/ # JPA/ORM Entities
├── messaging/
├── external/ # 外部服務整合
└── config/ # 技術配置
// domain/service/OrderDomainService.java
package com.example.domain.service;
import org.springframework.stereotype.Service; // ❌
import com.example.infrastructure.repository.JpaOrderRepository; // ❌
@Service // ❌
public class OrderDomainService {
private final JpaOrderRepository repository; // ❌
}
// domain/service/OrderDomainService.java
package com.example.domain.service;
import com.example.domain.repository.OrderRepository; // ✅ 介面
public class OrderDomainService {
private final OrderRepository repository; // ✅ 依賴介面
}
// domain/repository/OrderRepository.java
package com.example.domain.repository;
public interface OrderRepository { // ✅ 純介面
Order findById(OrderId id);
void save(Order order);
}
// infrastructure/persistence/repository/JpaOrderRepository.java
package com.example.infrastructure.persistence.repository;
import org.springframework.stereotype.Repository; // ✅ 在 Infrastructure
import com.example.domain.repository.OrderRepository;
@Repository
public class JpaOrderRepository implements OrderRepository {
// JPA 實作
}
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.