create-ai-project 1.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (150) hide show
  1. package/.claude/agents/acceptance-test-generator.md +316 -0
  2. package/.claude/agents/code-reviewer.md +193 -0
  3. package/.claude/agents/document-reviewer.md +182 -0
  4. package/.claude/agents/prd-creator.md +186 -0
  5. package/.claude/agents/quality-fixer.md +295 -0
  6. package/.claude/agents/requirement-analyzer.md +161 -0
  7. package/.claude/agents/rule-advisor.md +194 -0
  8. package/.claude/agents/task-decomposer.md +291 -0
  9. package/.claude/agents/task-executor.md +270 -0
  10. package/.claude/agents/technical-designer.md +343 -0
  11. package/.claude/agents/work-planner.md +181 -0
  12. package/.claude/agents-en/acceptance-test-generator.md +256 -0
  13. package/.claude/agents-en/code-reviewer.md +195 -0
  14. package/.claude/agents-en/design-sync.md +225 -0
  15. package/.claude/agents-en/document-reviewer.md +190 -0
  16. package/.claude/agents-en/integration-test-reviewer.md +195 -0
  17. package/.claude/agents-en/prd-creator.md +196 -0
  18. package/.claude/agents-en/quality-fixer-frontend.md +334 -0
  19. package/.claude/agents-en/quality-fixer.md +291 -0
  20. package/.claude/agents-en/requirement-analyzer.md +165 -0
  21. package/.claude/agents-en/rule-advisor.md +194 -0
  22. package/.claude/agents-en/task-decomposer.md +291 -0
  23. package/.claude/agents-en/task-executor-frontend.md +276 -0
  24. package/.claude/agents-en/task-executor.md +272 -0
  25. package/.claude/agents-en/technical-designer-frontend.md +441 -0
  26. package/.claude/agents-en/technical-designer.md +371 -0
  27. package/.claude/agents-en/work-planner.md +216 -0
  28. package/.claude/agents-ja/acceptance-test-generator.md +256 -0
  29. package/.claude/agents-ja/code-reviewer.md +195 -0
  30. package/.claude/agents-ja/design-sync.md +225 -0
  31. package/.claude/agents-ja/document-reviewer.md +192 -0
  32. package/.claude/agents-ja/integration-test-reviewer.md +195 -0
  33. package/.claude/agents-ja/prd-creator.md +194 -0
  34. package/.claude/agents-ja/quality-fixer-frontend.md +335 -0
  35. package/.claude/agents-ja/quality-fixer.md +292 -0
  36. package/.claude/agents-ja/requirement-analyzer.md +164 -0
  37. package/.claude/agents-ja/rule-advisor.md +194 -0
  38. package/.claude/agents-ja/task-decomposer.md +291 -0
  39. package/.claude/agents-ja/task-executor-frontend.md +276 -0
  40. package/.claude/agents-ja/task-executor.md +272 -0
  41. package/.claude/agents-ja/technical-designer-frontend.md +442 -0
  42. package/.claude/agents-ja/technical-designer.md +370 -0
  43. package/.claude/agents-ja/work-planner.md +213 -0
  44. package/.claude/commands/build.md +78 -0
  45. package/.claude/commands/design.md +27 -0
  46. package/.claude/commands/implement.md +79 -0
  47. package/.claude/commands/plan.md +43 -0
  48. package/.claude/commands/project-inject.md +76 -0
  49. package/.claude/commands/refine-rule.md +206 -0
  50. package/.claude/commands/review.md +78 -0
  51. package/.claude/commands/sync-rules.md +116 -0
  52. package/.claude/commands/task.md +13 -0
  53. package/.claude/commands-en/build.md +77 -0
  54. package/.claude/commands-en/design.md +39 -0
  55. package/.claude/commands-en/front-build.md +103 -0
  56. package/.claude/commands-en/front-design.md +42 -0
  57. package/.claude/commands-en/front-plan.md +40 -0
  58. package/.claude/commands-en/implement.md +75 -0
  59. package/.claude/commands-en/plan.md +45 -0
  60. package/.claude/commands-en/project-inject.md +76 -0
  61. package/.claude/commands-en/refine-rule.md +208 -0
  62. package/.claude/commands-en/review.md +78 -0
  63. package/.claude/commands-en/sync-rules.md +116 -0
  64. package/.claude/commands-en/task.md +13 -0
  65. package/.claude/commands-ja/build.md +75 -0
  66. package/.claude/commands-ja/design.md +37 -0
  67. package/.claude/commands-ja/front-build.md +103 -0
  68. package/.claude/commands-ja/front-design.md +42 -0
  69. package/.claude/commands-ja/front-plan.md +40 -0
  70. package/.claude/commands-ja/implement.md +73 -0
  71. package/.claude/commands-ja/plan.md +43 -0
  72. package/.claude/commands-ja/project-inject.md +76 -0
  73. package/.claude/commands-ja/refine-rule.md +206 -0
  74. package/.claude/commands-ja/review.md +78 -0
  75. package/.claude/commands-ja/sync-rules.md +116 -0
  76. package/.claude/commands-ja/task.md +13 -0
  77. package/.claude/settings.local.json +74 -0
  78. package/.husky/pre-commit +1 -0
  79. package/.husky/pre-push +3 -0
  80. package/.madgerc +14 -0
  81. package/.tsprunerc +11 -0
  82. package/CLAUDE.en.md +102 -0
  83. package/CLAUDE.ja.md +102 -0
  84. package/CLAUDE.md +111 -0
  85. package/LICENSE +21 -0
  86. package/README.ja.md +233 -0
  87. package/README.md +243 -0
  88. package/bin/create-project.js +87 -0
  89. package/biome.json +51 -0
  90. package/docs/adr/template-en.md +64 -0
  91. package/docs/adr/template-ja.md +64 -0
  92. package/docs/design/template-en.md +281 -0
  93. package/docs/design/template-ja.md +285 -0
  94. package/docs/guides/en/quickstart.md +111 -0
  95. package/docs/guides/en/rule-editing-guide.md +266 -0
  96. package/docs/guides/en/sub-agents.md +343 -0
  97. package/docs/guides/en/use-cases.md +308 -0
  98. package/docs/guides/ja/quickstart.md +112 -0
  99. package/docs/guides/ja/rule-editing-guide.md +266 -0
  100. package/docs/guides/ja/sub-agents.md +343 -0
  101. package/docs/guides/ja/use-cases.md +290 -0
  102. package/docs/guides/sub-agents.md +306 -0
  103. package/docs/plans/20250123-integration-test-improvement.md +993 -0
  104. package/docs/plans/template-en.md +130 -0
  105. package/docs/plans/template-ja.md +130 -0
  106. package/docs/prd/template-en.md +109 -0
  107. package/docs/prd/template-ja.md +109 -0
  108. package/docs/rules/ai-development-guide.md +260 -0
  109. package/docs/rules/architecture/implementation-approach.md +136 -0
  110. package/docs/rules/documentation-criteria.md +180 -0
  111. package/docs/rules/project-context.md +38 -0
  112. package/docs/rules/rules-index.yaml +137 -0
  113. package/docs/rules/technical-spec.md +47 -0
  114. package/docs/rules/typescript-testing.md +188 -0
  115. package/docs/rules/typescript.md +166 -0
  116. package/docs/rules-en/architecture/implementation-approach.md +136 -0
  117. package/docs/rules-en/coding-standards.md +333 -0
  118. package/docs/rules-en/documentation-criteria.md +184 -0
  119. package/docs/rules-en/frontend/technical-spec.md +143 -0
  120. package/docs/rules-en/frontend/typescript-testing.md +124 -0
  121. package/docs/rules-en/frontend/typescript.md +131 -0
  122. package/docs/rules-en/integration-e2e-testing.md +149 -0
  123. package/docs/rules-en/project-context.md +38 -0
  124. package/docs/rules-en/rules-index.yaml +211 -0
  125. package/docs/rules-en/technical-spec.md +86 -0
  126. package/docs/rules-en/typescript-testing.md +149 -0
  127. package/docs/rules-en/typescript.md +116 -0
  128. package/docs/rules-ja/architecture/implementation-approach.md +136 -0
  129. package/docs/rules-ja/coding-standards.md +333 -0
  130. package/docs/rules-ja/documentation-criteria.md +180 -0
  131. package/docs/rules-ja/frontend/technical-spec.md +143 -0
  132. package/docs/rules-ja/frontend/typescript-testing.md +124 -0
  133. package/docs/rules-ja/frontend/typescript.md +131 -0
  134. package/docs/rules-ja/integration-e2e-testing.md +149 -0
  135. package/docs/rules-ja/project-context.md +38 -0
  136. package/docs/rules-ja/rules-index.yaml +196 -0
  137. package/docs/rules-ja/technical-spec.md +86 -0
  138. package/docs/rules-ja/typescript-testing.md +149 -0
  139. package/docs/rules-ja/typescript.md +116 -0
  140. package/package.json +98 -0
  141. package/scripts/check-unused-exports.js +69 -0
  142. package/scripts/cleanup-test-processes.sh +32 -0
  143. package/scripts/post-setup.js +110 -0
  144. package/scripts/set-language.js +310 -0
  145. package/scripts/setup-project.js +199 -0
  146. package/scripts/show-coverage.js +74 -0
  147. package/src/index.ts +11 -0
  148. package/templates/.gitignore.template +52 -0
  149. package/tsconfig.json +50 -0
  150. package/vitest.config.mjs +47 -0
@@ -0,0 +1,137 @@
1
+ # 各ルールファイルのメタデータ
2
+ # 各ルールの概要、タグ、典型的な使用場面、サイズを管理
3
+
4
+ rules:
5
+ typescript:
6
+ file: "typescript.md"
7
+ tags: [implementation, type-safety, async, refactoring, coding-style, functional-programming, dependency-injection, branded-types]
8
+ typical-use: "TypeScriptコードの作成・修正・リファクタリング、モダンな型機能活用"
9
+ size: medium
10
+ key-references:
11
+ - "YAGNI原則 - Kent Beck"
12
+ - "Clean Code - Robert C. Martin"
13
+ - "DRY原則 - The Pragmatic Programmer"
14
+ - "Refactoring - Martin Fowler"
15
+ - "TypeScript 4.9 satisfies演算子 - Microsoft"
16
+ - "Branded Types - TypeScript Community"
17
+ - "Effect-TS / fp-ts - 関数型プログラミング"
18
+ - "Dependency Injection - Martin Fowler"
19
+ - "Avoiding fallback in distributed systems - AWS Builders' Library"
20
+ sections:
21
+ - "基本原則"
22
+ - "コメント記述ルール"
23
+ - "型安全性"
24
+ - "コーディング規約"
25
+ - "エラーハンドリング"
26
+ - "リファクタリング手法"
27
+ - "パフォーマンス最適化"
28
+
29
+ typescript-testing:
30
+ file: "typescript-testing.md"
31
+ tags: [quality, testing, tdd, coverage, vitest, implementation, debugging, refactoring]
32
+ typical-use: "テスト作成、品質チェック、コード修正・バグ修正・リファクタリング・新機能実装時の開発ステップ"
33
+ size: medium
34
+ key-references:
35
+ - "Test-Driven Development - Kent Beck"
36
+ - "Rule of Three - Martin Fowler"
37
+ - "Red-Green-Refactor - Kent Beck"
38
+ - "AAAパターン - Arrange-Act-Assert"
39
+ sections:
40
+ - "テストフレームワーク"
41
+ - "テストの基本方針"
42
+ - "Red-Green-Refactorプロセス(テストファースト開発)"
43
+ - "テストの設計原則"
44
+ - "テストヘルパーの活用ルール"
45
+ - "テストの実装規約"
46
+ - "テストの粒度"
47
+ - "モックの型安全性"
48
+ - "継続性テストの範囲"
49
+ - "Vitestの基本例"
50
+
51
+ ai-development-guide:
52
+ file: "ai-development-guide.md"
53
+ tags: [anti-patterns, technical-judgment, debugging, quality-commands, rule-of-three, implementation, type-safety, refactoring, code-reading, best-practices, impact-analysis, unused-code, code-deletion]
54
+ typical-use: "技術的判断基準、アンチパターン検出、デバッグ手法、品質チェックコマンド、実装時のベストプラクティス、影響範囲調査、未使用コード削除"
55
+ size: medium
56
+ key-references:
57
+ - "Rule of Three - Martin Fowler"
58
+ - "5 Whys - トヨタ生産方式"
59
+ - "DRY原則 - The Pragmatic Programmer"
60
+ - "単一責任原則(SRP) - Clean Code"
61
+ - "YAGNI原則 - Extreme Programming"
62
+ - "Avoiding fallback in distributed systems - AWS Builders' Library"
63
+ sections:
64
+ - "技術的アンチパターン(赤信号パターン)"
65
+ - "フォールバック処理に関する設計原則"
66
+ - "Rule of Three - コード重複の判断基準"
67
+ - "よくある失敗パターンと回避方法"
68
+ - "デバッグ手法"
69
+ - "品質チェックコマンドリファレンス"
70
+ - "技術的判断が必要な場面"
71
+ - "継続的改善のマインドセット"
72
+ - "実装作業の完全性担保"
73
+
74
+ technical-spec:
75
+ file: "technical-spec.md"
76
+ tags: [architecture, design, documentation, environment, data-flow, implementation]
77
+ typical-use: "技術設計、環境設定、ドキュメント作成プロセス、実装方針決定"
78
+ size: medium
79
+ key-references:
80
+ - "ADRフォーマット - Michael Nygard"
81
+ - "単一データソース原則 - Single Source of Truth"
82
+ sections:
83
+ - "技術スタックの基本方針"
84
+ - "環境変数管理とセキュリティ"
85
+ - "アーキテクチャ設計"
86
+ - "パターン適用の一貫性"
87
+ - "データフロー統一原則"
88
+ - "ビルドとテスト"
89
+
90
+ project-context:
91
+ file: "project-context.md"
92
+ tags: [context, project-specific, implementation]
93
+ typical-use: "プロジェクト固有情報、実装原則の理解"
94
+ size: small
95
+ key-references:
96
+ - "プロジェクト固有(経験則)"
97
+ sections:
98
+ - "基本設定"
99
+ - "実装原則"
100
+ - "カスタマイズガイド"
101
+
102
+ documentation-criteria:
103
+ file: "documentation-criteria.md"
104
+ tags: [documentation, decision-making, adr, prd, design-doc, planning, process]
105
+ typical-use: "実装開始時の規模判定、ドキュメント作成判定、ADR/PRD/Design Doc/作業計画書の作成基準"
106
+ size: medium
107
+ key-references:
108
+ - "ADR手法 - Michael Nygard"
109
+ - "Design Doc文化 - Google Engineering Practices"
110
+ - "Single Source of Truth"
111
+ sections:
112
+ - "作成判定マトリクス"
113
+ - "ADR作成条件(いずれか該当で必須)"
114
+ - "各ドキュメントの詳細定義"
115
+ - "作成プロセス"
116
+ - "保存場所"
117
+ - "ADRステータス"
118
+ - "AI自動化ルール"
119
+ - "図表作成要件"
120
+ - "共通ADRとの関係性"
121
+
122
+ implementation-approach:
123
+ file: "architecture/implementation-approach.md"
124
+ tags: [architecture, implementation, task-decomposition, strategy-patterns, strangler-pattern, facade-pattern, design, planning, confirmation-levels]
125
+ typical-use: "実装戦略の選択、タスク分解、設計判断、大規模変更の計画"
126
+ size: medium
127
+ key-references:
128
+ - "Strangler Fig Pattern - Martin Fowler"
129
+ - "Feature Slicing - Martin Fowler"
130
+ - "Walking Skeleton - Alistair Cockburn"
131
+ - "Facade Pattern - Gang of Four"
132
+ sections:
133
+ - "メタ認知的戦略選択プロセス"
134
+ - "確認レベル定義"
135
+ - "統合ポイントの定義"
136
+ - "アンチパターン"
137
+ - "メタ認知的実行のための指針"
@@ -0,0 +1,47 @@
1
+ # 技術設計ルール
2
+
3
+ ## 技術スタックの基本方針
4
+ TypeScriptをベースとしたアプリケーション実装。アーキテクチャパターンはプロジェクトの要件と規模に応じて選択すること。
5
+
6
+ ## 環境変数管理とセキュリティ
7
+
8
+ ### 環境変数管理
9
+ - 環境変数は一元管理し、型安全性を確保する仕組みを構築すること
10
+ - `process.env` の直接参照は避け、設定管理層を通じて取得すること
11
+ - デフォルト値の設定や必須チェックを適切に実装すること
12
+
13
+ ### セキュリティ
14
+ - `.env`ファイルはGitに含めない
15
+ - APIキーやシークレットは必ず環境変数として管理
16
+ - 機密情報のログ出力は禁止
17
+ - エラーメッセージに機密情報を含めない
18
+
19
+ ## アーキテクチャ設計
20
+
21
+ ### アーキテクチャ設計の原則
22
+ プロジェクトごとに適切なアーキテクチャを選択し、明確に定義すること:
23
+
24
+ - **明確な定義**: プロジェクトのアーキテクチャは`docs/rules/architecture/`配下に専用ファイルで定義
25
+ - **責務の分離**: 各層やモジュールの責務を明確に定義し、境界を守ること
26
+
27
+ ## パターン適用の一貫性
28
+
29
+ 選択したアーキテクチャパターンに厳密に従う。プロジェクト固有詳細は`docs/rules/architecture/`参照。
30
+
31
+ ## データフロー統一原則
32
+
33
+ #### 基本原則
34
+ 1. **単一データソース**: 同じ情報は1箇所にのみ保存する
35
+ 2. **構造化データ優先**: JSON文字列ではなくパース済みオブジェクトを使用
36
+ 3. **明確な責務分離**: 各層の責務を明確に定義
37
+
38
+ #### データフローのベストプラクティス
39
+ - **入力時点での検証**: データは入力層で検証し、型安全な形で内部に渡す
40
+ - **変換の一元化**: データ変換ロジックは専用のユーティリティに集約
41
+ - **ログの構造化**: データフローの各段階で構造化ログを出力
42
+
43
+ ## ビルドとテスト
44
+
45
+ プロジェクトごとにビルドコマンドとテスト実行方法を定義。
46
+
47
+ 品質チェックは実装完了時に必須。
@@ -0,0 +1,188 @@
1
+ # TypeScript テストルール
2
+
3
+ ## テストフレームワーク
4
+ - **Vitest**: このプロジェクトではVitestを使用
5
+ - テストのインポート: `import { describe, it, expect, beforeEach, vi } from 'vitest'`
6
+ - モックの作成: `vi.mock()` を使用
7
+
8
+ ## テストの基本方針
9
+
10
+ ### 品質要件
11
+ - **カバレッジ**: 単体テストのカバレッジは70%以上を必須
12
+ - **独立性**: 各テストは他のテストに依存せず実行可能
13
+ - **再現性**: テストは環境に依存せず、常に同じ結果を返す
14
+ - **可読性**: テストコードも製品コードと同様の品質を維持
15
+
16
+ ### カバレッジ要件
17
+ **必須**: 単体テストのカバレッジは70%以上
18
+ **指標**: Statements(文)、Branches(分岐)、Functions(関数)、Lines(行)
19
+
20
+ ### テストの種類と範囲
21
+ 1. **単体テスト(Unit Tests)**
22
+ - 個々の関数やクラスの動作を検証
23
+ - 外部依存はすべてモック化
24
+ - 最も数が多く、細かい粒度で実施
25
+
26
+ 2. **統合テスト(Integration Tests)**
27
+ - 複数のコンポーネントの連携を検証
28
+ - 実際の依存関係を使用(DBやAPI等)
29
+ - 主要な機能フローの検証
30
+
31
+ 3. **E2Eテストでの機能横断検証**
32
+ - 新機能追加時、既存機能への影響を必ず検証
33
+ - Design Docの「統合ポイントマップ」で影響度「高」「中」の箇所をカバー
34
+ - 検証パターン: 既存機能動作 → 新機能有効化 → 既存機能の継続性確認
35
+ - 判定基準: レスポンス内容の変化なし、処理時間5秒以内
36
+ - CI/CDでの自動実行を前提とした設計
37
+
38
+ ## Red-Green-Refactorプロセス(テストファースト開発)
39
+
40
+ **推奨原則**: コード変更は必ずテストから始める
41
+
42
+ **背景**:
43
+ - 変更前の動作を保証し、リグレッションを防止
44
+ - 期待する動作を明確化してから実装
45
+ - リファクタリング時の安全性を確保
46
+
47
+ **開発ステップ**:
48
+ 1. **Red**: 期待する動作のテストを書く(失敗する)
49
+ 2. **Green**: 最小限の実装でテストを通す
50
+ 3. **Refactor**: テストが通る状態を維持しながらコード改善
51
+
52
+ **NGケース(テストファースト不要)**:
53
+ - 純粋な設定ファイル変更(.env、config等)
54
+ - ドキュメントのみの更新(README、コメント等)
55
+ - 緊急本番障害対応(ただし事後テスト必須)
56
+
57
+ ## テストの設計原則
58
+
59
+ ### テストケースの構造
60
+ - テストは「準備(Arrange)」「実行(Act)」「検証(Assert)」の3段階で構成
61
+ - 各テストの目的が明確に分かる命名
62
+ - 1つのテストケースでは1つの振る舞いのみを検証
63
+
64
+ ### テストデータ管理
65
+ - テストデータは専用ディレクトリで管理
66
+ - 環境変数はテスト用の値を定義
67
+ - 機密情報は必ずモック化
68
+ - テストデータは最小限に保ち、テストケースの検証目的に直接関連するデータのみ使用
69
+
70
+ ### モックとスタブの使用方針
71
+
72
+ ✅ **推奨: 単体テストでの外部依存モック化**
73
+ - メリット: テストの独立性と再現性を確保
74
+ - 実践: DB、API、ファイルシステム等の外部依存をモック化
75
+
76
+ ❌ **避けるべき: 単体テストでの実際の外部接続**
77
+ - 理由: テスト速度が遅くなり、環境依存の問題が発生するため
78
+
79
+ ### テスト失敗時の対応判断基準
80
+
81
+ **テストを修正**: 間違った期待値、存在しない機能参照、実装詳細への依存、テストのためだけの実装
82
+ **実装を修正**: 妥当な仕様、ビジネスロジック、重要なエッジケース
83
+ **判断に迷ったら**: ユーザーに確認
84
+
85
+ ## テストヘルパーの活用ルール
86
+
87
+ ### 基本原則
88
+ テストヘルパーは、テストコードの重複を減らし、保守性を高めるために活用します。
89
+
90
+ ### 判断基準
91
+ | モックの特性 | 対応方針 |
92
+ |-------------|---------|
93
+ | **単純で安定** | 共通ヘルパーに集約 |
94
+ | **複雑または変更頻度高** | 個別実装 |
95
+ | **3箇所以上で重複** | 共通化を検討 |
96
+ | **テスト固有ロジック** | 個別実装 |
97
+
98
+ ### テストヘルパー活用例
99
+ ```typescript
100
+ // ✅ ビルダーパターン
101
+ const testData = new TestDataBuilder().withDefaults().withName('Test User').build()
102
+
103
+ // ✅ カスタムアサーション
104
+ function assertValidUser(user: unknown): asserts user is User {}
105
+
106
+ // ❌ 重複する複雑なモックの個別実装
107
+ ```
108
+
109
+ ## テストの実装規約
110
+
111
+ ### ディレクトリ構造
112
+ ```
113
+ src/
114
+ └── application/
115
+ └── services/
116
+ ├── __tests__/
117
+ │ ├── service.test.ts # 単体テスト
118
+ │ └── service.int.test.ts # 統合テスト
119
+ └── service.ts
120
+ ```
121
+
122
+ ### 命名規則
123
+ - テストファイル: `{対象ファイル名}.test.ts`
124
+ - 統合テストファイル: `{対象ファイル名}.int.test.ts`
125
+ - テストスイート: 対象の機能や状況を説明する名前
126
+ - テストケース: 期待される動作を説明する名前
127
+
128
+
129
+ ### テストコードの品質ルール
130
+
131
+ ✅ **推奨: すべてのテストを常に有効に保つ**
132
+ - メリット: テストスイートの完全性を保証
133
+ - 実践: 問題があるテストは修正して有効化
134
+
135
+ ❌ **避けるべき: test.skip()やコメントアウト**
136
+ - 理由: テストの穴が生まれ、品質チェックが不完全になる
137
+ - 対処: 不要なテストは完全に削除する
138
+
139
+ ## テストの粒度
140
+
141
+ ### 原則:観測可能な振る舞いのみ
142
+ **テスト対象**:公開API、戻り値、例外、外部呼び出し、永続化された状態
143
+ **テスト対象外**:privateメソッド、内部状態、アルゴリズム詳細
144
+
145
+ ```typescript
146
+ // ✅ 振る舞いをテスト
147
+ expect(calculatePrice(100, 0.1)).toBe(110)
148
+
149
+ // ❌ 実装詳細をテスト
150
+ expect((calculator as any).taxRate).toBe(0.1)
151
+ ```
152
+
153
+ ## モックの型安全性
154
+
155
+ ### 必要最小限の型定義
156
+ ```typescript
157
+ // ✅ 必要な部分のみ
158
+ type TestRepo = Pick<Repository, 'find' | 'save'>
159
+ const mock: TestRepo = { find: vi.fn(), save: vi.fn() }
160
+
161
+ // やむを得ない場合のみ、理由明記
162
+ const sdkMock = {
163
+ call: vi.fn()
164
+ } as unknown as ExternalSDK // 外部SDKの複雑な型のため
165
+ ```
166
+
167
+ ## 継続性テストの範囲
168
+
169
+ 新機能追加時の既存機能への影響確認に限定。長時間運用・負荷テストはインフラ層の責務のため対象外。
170
+
171
+ ## Vitestの基本例
172
+
173
+ ```typescript
174
+ import { describe, it, expect, vi } from 'vitest'
175
+
176
+ vi.mock('./userService', () => ({
177
+ getUserById: vi.fn(),
178
+ updateUser: vi.fn()
179
+ }))
180
+
181
+ describe('ComponentName', () => {
182
+ it('should follow AAA pattern', () => {
183
+ const input = 'test'
184
+ const result = someFunction(input)
185
+ expect(result).toBe('expected')
186
+ })
187
+ })
188
+ ```
@@ -0,0 +1,166 @@
1
+ # TypeScript 開発ルール
2
+
3
+ ## 基本原則
4
+
5
+ ✅ **積極的なリファクタリング** - 技術的負債を防ぎ、健全性を維持
6
+ ❌ **使われない「念のため」のコード** - YAGNI原則(Kent Beck)に反する
7
+
8
+ ## コメント記述ルール
9
+ - **機能説明重視**: コードが「何をするか」を記述
10
+ - **履歴情報禁止**: 開発履歴は記載しない
11
+ - **タイムレス**: いつ読んでも有効な内容のみ記述
12
+ - **簡潔性**: 必要最小限の説明にとどめる
13
+
14
+ ## 型安全性
15
+
16
+ **絶対ルール**: any型は完全禁止。型チェックが無効化され、実行時エラーの温床となる。
17
+
18
+ **any型の代替手段(優先順位順)**
19
+ 1. **unknown型 + 型ガード**: 外部入力の検証に使用
20
+ 2. **ジェネリクス**: 型の柔軟性が必要な場合
21
+ 3. **ユニオン型・インターセクション型**: 複数の型の組み合わせ
22
+ 4. **型アサーション(最終手段)**: 型が確実な場合のみ
23
+
24
+ **型ガードの実装パターン**
25
+ ```typescript
26
+ function isUser(value: unknown): value is User {
27
+ return typeof value === 'object' && value !== null && 'id' in value && 'name' in value
28
+ }
29
+ ```
30
+
31
+ **モダンな型機能の活用**
32
+ - **satisfies演算子**: `const config = { port: 3000 } satisfies Config` - 型推論維持
33
+ - **const assertion**: `const ROUTES = { HOME: '/' } as const satisfies Routes` - 不変かつ型安全
34
+ - **ブランド型**: `type UserId = string & { __brand: 'UserId' }` - 意味を区別
35
+ - **テンプレートリテラル型**: `type Endpoint = \`\${HttpMethod} \${Route}\`` - 文字列パターンを型で表現
36
+
37
+ **実装での型安全性**
38
+ - API通信: レスポンスは必ず`unknown`で受け、型ガードで検証
39
+ - フォーム入力: 外部入力は`unknown`、バリデーション後に型確定
40
+ - レガシー統合: `window as unknown as LegacyWindow`のように段階的アサーション
41
+ - テストコード: モックも必ず型定義、`Partial<T>`や`vi.fn<[Args], Return>()`活用
42
+
43
+ **データフローでの型安全性**
44
+ 入力層(`unknown`) → 型ガード → ビジネス層(型保証) → 出力層(シリアライズ)
45
+
46
+ **型の複雑性管理**
47
+ - フィールド数: 20個まで(超えたら責務で分割、外部API型は例外)
48
+ - オプショナル率: 30%まで(超えたら必須/任意で分離)
49
+ - ネスト深さ: 3階層まで(超えたらフラット化)
50
+ - 型アサーション: 3回以上使用したら設計見直し
51
+ - **外部API型の扱い**: 制約を緩和し、実態に合わせて定義(内部では適切に変換)
52
+
53
+ ## コーディング規約
54
+
55
+ **クラス使用の判断基準**
56
+ - **推奨:関数とinterfaceでの実装**
57
+ - 背景: テスタビリティと関数合成の柔軟性が向上
58
+ - **クラス使用を許可**:
59
+ - フレームワーク要求時(NestJSのController/Service、TypeORMのEntity等)
60
+ - カスタムエラークラス定義時
61
+ - 状態とビジネスロジックが密結合している場合(例: ShoppingCart、Session、StateMachine)
62
+ - **判断基準**: 「このデータは振る舞いを持つか?」がYesならクラス検討
63
+ ```typescript
64
+ // ✅ 関数とinterface
65
+ interface UserService { create(data: UserData): User }
66
+ const userService: UserService = { create: (data) => {...} }
67
+ ```
68
+
69
+ **関数設計**
70
+ - **引数は0-2個まで**: 3個以上はオブジェクト化
71
+ ```typescript
72
+ // ✅ オブジェクト引数
73
+ function createUser({ name, email, role }: CreateUserParams) {}
74
+ ```
75
+
76
+ **依存性注入**
77
+ - **外部依存は引数で注入**: テスト可能性とモジュール性確保
78
+ ```typescript
79
+ // ✅ 依存性を引数で受け取る
80
+ function createService(repository: Repository) { return {...} }
81
+ ```
82
+
83
+ **非同期処理**
84
+ - Promise処理: 必ず`async/await`を使用
85
+ - エラーハンドリング: 必ず`try-catch`でハンドリング
86
+ - 型定義: 戻り値の型は明示的に定義(例: `Promise<Result>`)
87
+
88
+ **フォーマット規則**
89
+ - セミコロン省略(Biomeの設定に従う)
90
+ - 型は`PascalCase`、変数・関数は`camelCase`
91
+ - インポートは絶対パス(`src/`)
92
+
93
+ **クリーンコード原則**
94
+ - ✅ 使用されていないコードは即座に削除
95
+ - ✅ デバッグ用`console.log()`は削除
96
+ - ❌ コメントアウトされたコード(バージョン管理で履歴管理)
97
+ - ✅ コメントは「なぜ」を説明(「何」ではなく)
98
+
99
+ ## エラーハンドリング
100
+
101
+ **絶対ルール**: エラーの握りつぶし禁止。すべてのエラーは必ずログ出力と適切な処理を行う。
102
+
103
+ **Fail-Fast原則**: エラー時は速やかに失敗させ、不正な状態での処理継続を防ぐ
104
+ ```typescript
105
+ // ❌ 禁止: 無条件フォールバック
106
+ catch (error) {
107
+ return defaultValue // エラーを隠蔽
108
+ }
109
+
110
+ // ✅ 必須: 明示的な失敗
111
+ catch (error) {
112
+ logger.error('処理失敗', error)
113
+ throw error // 上位層で適切に処理
114
+ }
115
+ ```
116
+
117
+ **Result型パターン**: エラーを型で表現し、明示的に処理
118
+ ```typescript
119
+ type Result<T, E> = { ok: true; value: T } | { ok: false; error: E }
120
+
121
+ // 使用例:エラーの可能性を型で表現
122
+ function parseUser(data: unknown): Result<User, ValidationError> {
123
+ if (!isValid(data)) return { ok: false, error: new ValidationError() }
124
+ return { ok: true, value: data as User }
125
+ }
126
+ ```
127
+
128
+ **カスタムエラークラス**
129
+ ```typescript
130
+ export class AppError extends Error {
131
+ constructor(message: string, public readonly code: string, public readonly statusCode = 500) {
132
+ super(message)
133
+ this.name = this.constructor.name
134
+ }
135
+ }
136
+ // 用途別: ValidationError(400), BusinessRuleError(400), DatabaseError(500), ExternalServiceError(502)
137
+ ```
138
+
139
+ **層別エラー処理**
140
+ - API層: HTTPレスポンスに変換、機密情報を除外してログ出力
141
+ - サービス層: ビジネスルール違反を検出、AppErrorはそのまま伝播
142
+ - リポジトリ層: 技術的エラーをドメインエラーに変換
143
+
144
+ **構造化ログと機密情報保護**
145
+ 機密情報(password, token, apiKey, secret, creditCard)は絶対にログに含めない
146
+
147
+ **非同期エラーハンドリング**
148
+ - グローバルハンドラー設定必須: `unhandledRejection`, `uncaughtException`
149
+ - すべてのasync/awaitでtry-catch使用
150
+ - エラーは必ずログと再スロー
151
+
152
+ ## リファクタリング手法
153
+
154
+ **基本方針**
155
+ - 小さなステップ: 段階的改善により、常に動作する状態を維持
156
+ - 安全な変更: 一度に変更する範囲を最小限に抑制
157
+ - 動作保証: 既存の動作を変えないことを確認しながら進める
158
+
159
+ **実施手順**: 現状把握 → 段階的変更 → 動作確認 → 最終検証
160
+
161
+ **優先順位**: 重複コード削除 > 長大な関数分割 > 複雑な条件分岐簡素化 > 型安全性向上
162
+
163
+ ## パフォーマンス最適化
164
+
165
+ - ストリーミング処理: 大きなデータセットはストリームで処理
166
+ - メモリリーク防止: 不要なオブジェクトは明示的に解放
@@ -0,0 +1,136 @@
1
+ # Implementation Strategy Selection Framework (Meta-cognitive Approach)
2
+
3
+ ## Meta-cognitive Strategy Selection Process
4
+
5
+ ### Phase 1: Comprehensive Current State Analysis
6
+
7
+ **Core Question**: "What does the existing implementation look like?"
8
+
9
+ #### Analysis Framework
10
+ ```yaml
11
+ Architecture Analysis: Responsibility separation, data flow, dependencies, technical debt
12
+ Implementation Quality Assessment: Code quality, test coverage, performance, security
13
+ Historical Context Understanding: Current form rationale, past decision validity, constraint changes, requirement evolution
14
+ ```
15
+
16
+ #### Meta-cognitive Question List
17
+ - What is the true responsibility of this implementation?
18
+ - Which parts are business essence and which derive from technical constraints?
19
+ - What dependencies or implicit preconditions are unclear from the code?
20
+ - What benefits and constraints does the current design bring?
21
+
22
+ ### Phase 2: Strategy Exploration and Creation
23
+
24
+ **Core Question**: "When determining before → after, what implementation patterns or strategies should be referenced?"
25
+
26
+ #### Strategy Discovery Process
27
+ ```yaml
28
+ Research and Exploration: Tech stack examples (WebSearch), similar projects, OSS references, literature/blogs
29
+ Creative Thinking: Strategy combinations, constraint-based design, phase division, extension point design
30
+ ```
31
+
32
+ #### Reference Strategy Patterns (Creative Combinations Encouraged)
33
+
34
+ **Legacy Handling Strategies**:
35
+ - Strangler Pattern: Gradual migration through phased replacement
36
+ - Facade Pattern: Complexity hiding through unified interface
37
+ - Adapter Pattern: Bridge with existing systems
38
+
39
+ **New Development Strategies**:
40
+ - Feature-driven Development: Vertical implementation prioritizing user value
41
+ - Foundation-driven Development: Foundation-first construction prioritizing stability
42
+ - Risk-driven Development: Prioritize addressing maximum risk elements
43
+
44
+ **Integration/Migration Strategies**:
45
+ - Proxy Pattern: Transparent feature extension
46
+ - Decorator Pattern: Phased enhancement of existing features
47
+ - Bridge Pattern: Flexibility through abstraction
48
+
49
+ **Important**: The optimal solution is discovered through creative thinking according to each project's context.
50
+
51
+ ### Phase 3: Risk Assessment and Control
52
+
53
+ **Core Question**: "What risks arise when applying this to existing implementation, and what's the best way to control them?"
54
+
55
+ #### Risk Analysis Matrix
56
+ ```yaml
57
+ Technical Risks: System impact, data consistency, performance degradation, integration complexity
58
+ Operational Risks: Service availability, deployment downtime, process changes, rollback procedures
59
+ Project Risks: Schedule delays, learning costs, quality achievement, team coordination
60
+ ```
61
+
62
+ #### Risk Control Strategies
63
+ ```yaml
64
+ Preventive Measures: Phased migration, parallel operation verification, integration/regression tests, monitoring setup
65
+ Incident Response: Rollback procedures, log/metrics preparation, communication system, service continuation procedures
66
+ ```
67
+
68
+ ### Phase 4: Constraint Compatibility Verification
69
+
70
+ **Core Question**: "What are this project's constraints?"
71
+
72
+ #### Constraint Checklist
73
+ ```yaml
74
+ Technical Constraints: Library compatibility, resource capacity, mandatory requirements, numerical targets
75
+ Temporal Constraints: Deadlines/priorities, dependencies, milestones, learning periods
76
+ Resource Constraints: Team/skills, work hours/systems, budget, external contracts
77
+ Business Constraints: Market launch timing, customer impact, regulatory compliance
78
+ ```
79
+
80
+ ### Phase 5: Implementation Approach Decision
81
+
82
+ Select optimal solution from basic implementation approaches (creative combinations encouraged):
83
+
84
+ #### Vertical Slice (Feature-driven)
85
+ **Characteristics**: Vertical implementation across all layers by feature unit
86
+ **Application Conditions**: Low inter-feature dependencies, output in user-usable form, changes needed across all architecture layers
87
+ **Verification Method**: End-user value delivery at each feature completion
88
+
89
+ #### Horizontal Slice (Foundation-driven)
90
+ **Characteristics**: Phased construction by architecture layer
91
+ **Application Conditions**: Foundation system stability important, multiple features depend on common foundation, layer-by-layer verification effective
92
+ **Verification Method**: Integrated operation verification when all foundation layers complete
93
+
94
+ #### Hybrid (Creative Combination)
95
+ **Characteristics**: Flexible combination according to project characteristics
96
+ **Application Conditions**: Unclear requirements, need to change approach per phase, transition from prototyping to full implementation
97
+ **Verification Method**: Verify at appropriate L1/L2/L3 levels according to each phase's goals
98
+
99
+ ### Phase 6: Decision Rationale Documentation
100
+
101
+ **Design Doc Documentation**: Clearly specify implementation strategy selection reasons and rationale.
102
+
103
+ ## Verification Level Definitions
104
+
105
+ Priority for completion verification of each task:
106
+
107
+ - **L1: Functional Operation Verification** - Operates as end-user feature (e.g., search executable)
108
+ - **L2: Test Operation Verification** - New tests added and passing (e.g., type definition tests)
109
+ - **L3: Build Success Verification** - No compile errors (e.g., interface definitions)
110
+
111
+ **Priority**: L1 > L2 > L3 in order of verifiability importance
112
+
113
+ ## Integration Point Definitions
114
+
115
+ Define integration points according to selected strategy:
116
+ - **Strangler-based**: When switching between old and new systems for each feature
117
+ - **Feature-driven**: When users can actually use the feature
118
+ - **Foundation-driven**: When all architecture layers are ready and E2E tests pass
119
+ - **Hybrid**: When individual goals defined for each phase are achieved
120
+
121
+ ## Anti-patterns
122
+
123
+ - **Pattern Fixation**: Selecting only from listed strategies without considering unique combinations
124
+ - **Insufficient Analysis**: Skipping Phase 1 analysis framework before strategy selection
125
+ - **Risk Neglect**: Starting implementation without Phase 3 risk analysis matrix
126
+ - **Constraint Ignorance**: Deciding strategy without checking Phase 4 constraint checklist
127
+ - **Rationale Omission**: Selecting strategy without using Phase 6 documentation template
128
+
129
+ ## Guidelines for Meta-cognitive Execution
130
+
131
+ 1. **Leverage Known Patterns**: Use as starting point, explore creative combinations
132
+ 2. **Active WebSearch Use**: Research implementation examples from similar tech stacks
133
+ 3. **Apply 5 Whys**: Pursue root causes to grasp essence
134
+ 4. **Multi-perspective Evaluation**: Comprehensively evaluate from each Phase 1-4 perspective
135
+ 5. **Creative Thinking**: Consider sequential application of multiple strategies and designs leveraging project-specific constraints
136
+ 6. **Clarify Decision Rationale**: Make strategy selection rationale explicit in design documents