arch-guard
進行代碼重構或新增模組時觸發。確保程式碼符合 Clean Architecture + DDD + CQRS 的層次關係,防止架構腐化。
Best use case
arch-guard is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
進行代碼重構或新增模組時觸發。確保程式碼符合 Clean Architecture + DDD + CQRS 的層次關係,防止架構腐化。
Teams using arch-guard should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/arch-guard/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How arch-guard Compares
| Feature / Agent | arch-guard | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
進行代碼重構或新增模組時觸發。確保程式碼符合 Clean Architecture + DDD + CQRS 的層次關係,防止架構腐化。
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# Architecture Guard Skill
## 觸發時機
- 進行代碼重構時
- 新增模組或類別時
- 修改現有程式碼的依賴關係時
- AI 生成新代碼前的架構審查
## 核心任務
確保程式碼放對位置,嚴格遵守領域驅動設計 (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) │
└─────────────────────────────────────────────────┘
```
## 依賴規則 (Dependency Rule)
**核心原則:依賴只能向內指向,內層不能知道外層的存在**
### 允許的依賴方向
```
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 |
## 違規檢測規則
### 🚫 嚴重違規 (必須立即修正)
1. **Domain 層引用資料庫驅動**
```java
// ❌ 違規:Domain 層出現 JDBC/JPA 實作
package com.example.domain.entity;
import java.sql.Connection; // 禁止!
import javax.persistence.EntityManager; // 禁止!
```
2. **Domain 層引用 Spring Framework**
```java
// ❌ 違規:Domain 層出現 Spring 註解
package com.example.domain.service;
import org.springframework.stereotype.Service; // 禁止!
import org.springframework.beans.factory.annotation.Autowired; // 禁止!
```
3. **Domain 層引用外部 HTTP 客戶端**
```java
// ❌ 違規:Domain 層直接呼叫外部服務
package com.example.domain.service;
import org.springframework.web.client.RestTemplate; // 禁止!
```
### ⚠️ 中度違規 (應該重構)
1. **Application 層包含業務邏輯**
- Application Layer 應只負責編排 (Orchestration)
- 複雜業務邏輯應下沉到 Domain Layer
2. **Repository 實作暴露在 Domain 層**
- Domain 層只應定義 Repository 介面
- 實作應在 Infrastructure 層
### 💡 建議改進
1. **使用 Port/Adapter 模式**
- Domain 定義 Port (介面)
- Infrastructure 提供 Adapter (實作)
## 標準目錄結構
```
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/ # 技術配置
```
## 審查檢查清單
### 新增類別時
- [ ] 類別放在正確的層次?
- [ ] import 語句是否違反依賴規則?
- [ ] Domain 層是否為純 POJO(無框架依賴)?
- [ ] Repository 介面與實作是否分離?
### 重構時
- [ ] 是否引入新的跨層依賴?
- [ ] 是否破壞現有的層次邊界?
- [ ] 是否需要透過介面解耦?
## 違規處理流程
1. **識別違規**:標記具體的類別和 import 語句
2. **分類嚴重度**:嚴重 / 中度 / 建議
3. **提供修正方案**:給出具體的重構建議
4. **阻止提交**:嚴重違規時應阻止代碼合併
## 範例:違規修正
### 修正前 (違規)
```java
// 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; // ❌
}
```
### 修正後 (正確)
```java
// 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 實作
}
```Related Skills
architecture-readiness
Use this skill to create Product Owner Specifications documenting business requirements before architecture design
amazon-product-search-recommender
When the user wants to search for specific products on Amazon within budget constraints and generate structured recommendations. This skill navigates to Amazon.com, performs targeted searches using specific criteria (price range, material, color), browses search results, extracts product details (title, price, store/brand, URL), and compiles recommendations into a structured JSON format. Triggers include requests for product recommendations, shopping assistance, budget-constrained searches, or when users need to find specific items on Amazon with detailed specifications.
advanced-text-search-matching
Production-grade text search algorithms for finding and matching text in large documents with millisecond performance. Includes Boyer-Moore search, n-gram similarity, fuzzy matching, and intelligent indexing. Use when building search features for large documents, finding quotes with imperfect matches, implementing fuzzy search, or need character-level precision.
archive-tasks
Archiva tareas completadas de TASKS.md a TASKS-DONE.md. Usar automáticamente cuando TASKS.md tenga muchas tareas completadas o supere 20K tokens.
ai-architect-expert
Expert-level AI system design, MLOps, architecture patterns, and AI infrastructure
rey-web-search
Quick web search for information. Returns top results with summaries. Use when user says "search", "look up", "find info about".
solidstart-hydration-guard
SolidStart hydration guard: keep SSR/CSR output identical, gate browser-only APIs, use stable IDs, align Suspense/resource fallbacks, and use clientOnly/onMount for client-only UI.
jekyll-research-theme
Create production-grade, accessible Jekyll themes for researchers conducting "research in public." Generates complete lab notebook-style themes with Tufte-inspired sidenotes, KaTeX math rendering, and WCAG 2.1 AA compliance. Use when building Jekyll themes for scientific journals, experiment logs, field notes, or research documentation sites. Supports collections for organizing experiments and field notes, responsive sidenote rendering (sidebar on desktop, inline on mobile), and full-width layout options.
hig-components-search
Apple HIG guidance for navigation-related components including search fields, page controls, and path controls.
frontend-architect
Build production-grade UI/UX with React (Next.js, Docusaurus), CSS architecture (Tailwind, Modules, Global), animations, theming, performance optimization, state management, and testing. Use when creating React components, building layouts, refactoring CSS, implementing animations, auditing accessibility, optimizing performance, setting up state management, or writing component tests.
architecture-analysis
Comprehensive frontend architecture analyzer that identifies technology stacks, build tools, and architectural patterns. Use when you need to quickly understand a project's structure, dependencies, and technical configuration. Provides analysis for Vue/React/Angular frameworks, Node.js environments, package managers, TypeScript usage, linters, and architecture patterns with multiple output formats including executive summaries and visualizations.
architecting-components
Defines rules for Atomic Design and separating logic from UI. Use when creating new components in the src directory.