一键导入
arch-guard
進行代碼重構或新增模組時觸發。確保程式碼符合 Clean Architecture + DDD + CQRS 的層次關係,防止架構腐化。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
進行代碼重構或新增模組時觸發。確保程式碼符合 Clean Architecture + DDD + CQRS 的層次關係,防止架構腐化。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Automated code review that checks code quality, Clean Architecture compliance, DDD patterns, coding standards, and spec traceability.
從規格目錄的 acceptance.yaml 生成/維護 BDD/ezSpec 測試。使用類似 Gherkin 語法,AI 自動產生 step definition(開發人員不需要手寫),驗收測試規格即為 Executable Specification。
在單元測試通過後觸發。透過引入人工錯誤(Mutants)來「測試你的測試」,確保測試案例具有足夠的錯誤偵測能力,建立對驗證機制的信任(Trust the Verification)。
驗證規格檔案的完整性與一致性,確保所有必要的規格元素都已定義且符合標準格式。
Replace with description of the skill and when Claude should use it.
協調多個 AI 模型(ChatGPT、Gemini、Codex、QWEN、Claude)進行三角驗證,確保「Specification == Program == Test」一致性。過濾假警報後輸出報告,大幅減少人工介入時間。
| name | arch-guard |
| description | 進行代碼重構或新增模組時觸發。確保程式碼符合 Clean Architecture + DDD + CQRS 的層次關係,防止架構腐化。 |
確保程式碼放對位置,嚴格遵守領域驅動設計 (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 實作
}