claude-code/claude-zh/rules/common/patterns.md

32 lines
1.0 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# 通用模式 (Common Patterns)
## 骨架專案 (Skeleton Projects)
實作新功能時:
1. 搜尋經過實戰測試的骨架專案。
2. 使用平行 Agent 評估選項:
- 安全評估
- 可擴充性分析
- 相關性評分
- 實作規劃
3. 複製最匹配的項目作為基礎。
4. 在已證實的結構中進行迭代。
## 設計模式 (Design Patterns)
### 儲存庫模式 (Repository Pattern)
將資料存取封裝在一致的介面後方:
- 定義標準操作findAll, findById, create, update, delete。
- 具體實作處理儲存細節資料庫、API、檔案等
- 業務邏輯依賴於抽象介面,而非儲存機制。
- 實現輕鬆切換資料來源,並簡化使用 Mock 進行的測試。
### API 回應格式 (API Response Format)
為所有 API 回應使用一致的外殼 (Envelope)
- 包含 success/status 指示器。
- 包含數據負載 (Data payload發生錯誤時可為空)。
- 包含錯誤訊息欄位 (成功時可為空)。
- 為分頁回應包含元數據 (total, page, limit)。