AgentSkillsCN

musubix-best-practices

MUSUBIX 已学 17 大最佳实践指南,可用于指导代码、设计及测试模式的落地应用。

SKILL.md
--- frontmatter
name: musubix-best-practices
description: MUSUBIX学習済み17ベストプラクティスガイド。コード・設計・テストパターンの適用に使用。
license: MIT

Best Practices Skill

14以上のプロジェクトから学習した17のベストプラクティス。

Code Patterns (5)

IDパターン概要
BP-CODE-001Entity Input DTO複数パラメータ→DTOオブジェクト
BP-CODE-002Date-based IDPREFIX-YYYYMMDD-NNN形式
BP-CODE-003Value Objectsドメイン概念にVO使用
BP-CODE-004Function-based VOinterface + factory関数(classは非推奨)
BP-CODE-005Result TypeResult<T, E>で失敗を表現

BP-CODE-004: Function-based VO

typescript
// ✅ 推奨
interface Price { readonly amount: number; readonly currency: 'JPY'; }
function createPrice(amount: number): Result<Price, ValidationError> {
  if (amount < 100) return err(new ValidationError('...'));
  return ok({ amount, currency: 'JPY' });
}

// ❌ 非推奨: class-based

Design Patterns (7)

IDパターン概要
BP-DESIGN-001Status Transition MapRecord<Status, Status[]>で遷移定義
BP-DESIGN-002Repository Async将来DB移行に備えてasync化
BP-DESIGN-003Service Layer DIリポジトリをDI
BP-DESIGN-004Optimistic Lockingversionフィールドで同時編集検出
BP-DESIGN-005AuditServiceデータ変更の監査ログ
BP-DESIGN-006Entity Counter Resetテスト用resetXxxCounter()
BP-DESIGN-007Expiry Time LogicexpiresAtで有効期限管理

BP-DESIGN-001: Status Transition Map

typescript
const validTransitions: Record<Status, Status[]> = {
  draft: ['active', 'cancelled'],
  active: ['completed', 'cancelled'],
  completed: [], cancelled: [],
};

Test Patterns (5)

IDパターン概要
BP-TEST-001Counter ResetbeforeEachでIDカウンターリセット
BP-TEST-002Verify APIテスト前にAPIシグネチャ確認
BP-TEST-003Vitest ESMVitest + TypeScript ESM構成
BP-TEST-004Result Type TestisOk()/isErr()で両ケーステスト
BP-TEST-005Status Transition有効・無効遷移を網羅テスト

CLI

bash
npx musubix learn best-practices               # 全パターン表示
npx musubix learn best-practices --category code
npx musubix learn best-practices --high-confidence

出力例

code
┌────────────────────────────────────────────────┐
│ Best Practices Applied                         │
├────────────────────────────────────────────────┤
│ Code Patterns:   5 applied                     │
│ Design Patterns: 7 applied                     │
│ Test Patterns:   5 applied                     │
│ Confidence:      95% average                   │
└────────────────────────────────────────────────┘