software-patterns について
設計パターン、アルゴリズム、コード品質、分散システム、ドメインモデリング、プログラミング基礎などの質問を適切なスキルへ導く知識ルーターです。アーキテクチャの相談では複数スキルを組み合わせ、比較や実装の質問も振り分けます。
主な機能
- 01七つのエンジニアリング分野を網羅
- 02質問を関連資料へルーティング
- 03複数スキルによる設計案の調整
- 04パターンや手法の比較に対応
- 05言語別実装の質問を振り分け
活用シーン
- 01課題に適した設計パターンの選択
- 02要件に応じたデータ構造やアルゴリズムの選定
- 03システム設計概念の組み合わせ
- 04手法とトレードオフの比較
インストール
コマンドをコピーしてターミナルで実行します。
npx skills add https:/ / github.com/ grndlvl/ software-patterns --skill software-patternsインストール後、Claude Code で/software-patternsを入力して読み込まれたか確認します。
同梱ファイル
SKILL.md と一緒にインストールされる参考資料やスクリプト。
examples/composite-solutions/caching-example.mdevent-system-example.mdindex/composite-solutions.yamlproblem-taxonomy.yamltriggers.yamlindex/decision-trees/data-structure-selection.yamlpattern-selection.yamlstorage-engine-selection.yamlquick-ref/ds-cheatsheet.mdpattern-cheatsheet.mdtemplates/language-idioms.mdpattern-implementation.md詳細
ソフトウェアパターン - 統合ナレッジルーター
7 つの専門スキルにまたがる 147 個のドキュメントファイルを網羅した、包括的なソフトウェアエンジニアリングのナレッジベースです。このルーターは、クエリを適切な基盤スキルにインテリジェントに振り分け、必要に応じてスキルを横断したソリューションを調整します。
このスキルが有効になる条件
次のような場合に、このスキルが自動的に有効になります。
- デザインパターンやアルゴリズムを選ぶ必要がある
- システムアーキテクチャやデータモデルを設計する
- コード品質、リファクタリング、またはベストプラクティスについて話し合う
- 特定の要件に適したデータ構造を選ぶ
- 分散システムやデータベースを設計する
- 複雑なビジネスドメインをモデル化する
- 基本的なプログラミング概念を適用する
クイックリファレンス:各スキルの対象範囲
| スキル | ファイル数 | 対象範囲 | 用途 |
|---|---|---|---|
| gof-patterns | 25 | 23 種類の GoF デザインパターン + 選択ガイド | オブジェクトの生成、合成、振る舞い |
| clrs-algorithms | 40 | データ構造とアルゴリズム | パフォーマンス最適化、アルゴリズムの選択 |
| clean-code | 14 | SOLID 原則 + 8 つのプラクティス | コード品質、リファクタリング、保守性 |
| ddia | 21 | 分散システムの概念 | スケーラビリティ、一貫性、可用性 |
| pragmatic-programmer | 19 | 7 つの原則 + 11 のプラクティス | ソフトウェア職人技、デバッグ、ツール |
| ddd | 15 | 4 つの戦略パターン + 5 つの戦術パターン | ドメインモデリング、境界づけられたコンテキスト |
| sicp | 13 | 12 の基本的な CS 概念 | 抽象化、再帰、インタープリター |
合計:147 個のドキュメントファイル
クエリコマンド
パターンクエリ
/pattern <problem>
特定の問題に適したデザインパターンを探します。
例:
/pattern create objects without knowing exact type→ Factory Method/pattern add behavior dynamically→ Decorator/pattern notify multiple objects of changes→ Observer/pattern simplify complex subsystem→ Facade
振り分け先: gof-patterns スキルの pattern-selection.md
データ構造クエリ
/ds <requirement>
特定の要件に適したデータ構造を探します。
例:
/ds fast lookup by key→ Hash Table/ds maintain sorted order→ Tree Set or Heap/ds fast insert/delete at ends→ Deque/ds priority queue→ Binary Heap
振り分け先: clrs-algorithms スキルの data-structure-selection.md
アーキテクチャクエリ
/architecture <scenario>
パターン、データ構造、分散システムの概念を組み合わせた、複数スキルにまたがるソリューションスタックを取得します。
例:
/architecture e-commerce checkout→ State pattern + Command + Observer + distributed transactions/architecture real-time leaderboard→ Sorted Set + Redis + Pub/Sub/architecture multi-tenant SaaS→ Abstract Factory + Bounded Contexts + Partitioning
振り分け先: gof-patterns、clrs-algorithms、ddia、ddd にまたがって調整します
実装クエリ
/implement <pattern> [language]
特定の言語でパターンの実装コードを生成します。
例:
/implement factory method typescript/implement observer python/implement heap java
振り分け先: 言語固有の翻訳に対応した適切なスキル
比較クエリ
/compare <a> vs <b>
2 つのアプローチのトレードオフを分析します。
例:
/compare factory method vs abstract factory/compare array vs linked list/compare postgres vs mongodb/compare event sourcing vs crud
振り分け先: 比較表を含む関連スキル
ルーターの仕組み
1. クエリ解析
ルーターは、問題を示すキーワードをクエリから分析します。
patterns:
- "create", "instantiate", "build" → Creational patterns
- "structure", "compose", "organize" → Structural patterns
- "behavior", "algorithm", "interact" → Behavioral patterns
data_structures:
- "fast lookup", "search", "find" → Hash or Tree
- "sorted", "ordered" → Tree or Heap
- "insert", "delete", "add", "remove" → List or Tree
- "queue", "stack", "priority" → Specialized structures
distributed_systems:
- "scale", "partition", "shard" → ddia/partitioning
- "replicate", "consistency" → ddia/replication
- "distributed", "consensus" → ddia/consensus
domain_modeling:
- "entity", "value object", "aggregate" → ddd/tactical
- "bounded context", "ubiquitous language" → ddd/strategic
2. スキルのルーティング
クエリの種類に基づいて、1つ以上のスキルにルーティングします。
| クエリの種類 | 主なスキル | 補助スキル |
|---|---|---|
| デザインパターン | gof-patterns | clean-code(SOLID)、ddd(パターン) |
| データ構造 | clrs-algorithms | ddia(ストレージエンジン) |
| コード品質 | clean-code | pragmatic-programmer |
| 分散システム | ddia | clrs-algorithms(グラフ)、ddd(コンテキスト) |
| ドメインモデリング | ddd | gof-patterns(戦術的パターン) |
| 基礎 | sicp | pragmatic-programmer |
| アーキテクチャ | ALL | オーケストレーションによる解決 |
3. スキル横断のオーケストレーション
複雑な問題では、ルーターが複数のスキルをオーケストレーションします。
例:「分散システム向けのキャッシュ層を設計する」
1. clrs-algorithms → LRU cache data structure (Hash Table + Doubly Linked List)
2. gof-patterns → Proxy pattern (control access), Flyweight (share state)
3. ddia → Replication strategies, consistency models
4. clean-code → Interface design, SOLID principles
例:「eコマースの注文処理システムを構築する」
1. ddd → Order aggregate, bounded contexts (order, payment, shipping)
2. gof-patterns → State (order states), Command (payment actions), Observer (notifications)
3. clrs-algorithms → Priority Queue (order processing), Hash Table (inventory lookup)
4. ddia → Event sourcing, CQRS, distributed transactions
5. clean-code → SRP (one class per concern), DIP (depend on abstractions)
自動トリガールール
クエリに次の指標が含まれる場合、このスキルが自動的に有効になります。
パターン/設計の指標
- 「どのパターン」「デザインパターン」「使うべき」
- 「ファクトリー」「シングルトン」「オブザーバー」「デコレーター」「アダプター」
- 「オブジェクトを作成する」「振る舞いを追加する」「インターフェースを簡素化する」
データ構造の指標
- 「どのデータ構造」「高速な検索」「ソート順」
- 「配列」「リスト」「ツリー」「ハッシュ」「グラフ」「ヒープ」
- 「O(1)」「O(log n)」「計算量」「時間/空間」
アーキテクチャの指標
- 「設計」「アーキテクチャ」「どのように構成すべきか」
- 「スケーラブル」「分散」「高可用性」
- 「マイクロサービス」「イベント駆動」「ドメインモデル」
コード品質の指標
- 「リファクタリング」「コードの臭い」「整理」「改善」
- 「SOLID」「DRY」「命名」「関数のサイズ」
- 「テスト」「保守しやすい」「読みやすい」
スキルの対象範囲
GoF パターン(gof-patterns)
生成(5パターン):
- Abstract Factory、Builder、Factory Method、Prototype、Singleton
構造(7パターン):
- Adapter、Bridge、Composite、Decorator、Facade、Flyweight、Proxy
振る舞い(11パターン):
- Chain of Responsibility、Command、Interpreter、Iterator、Mediator、Memento、Observer、State、Strategy、Template Method、Visitor
選択ガイド:
- pattern-selection.md - 包括的な選択ガイド
- 問題 → パターンの対応付け
- よく使われる組み合わせ
- 避けるべきアンチパターン
CLRS アルゴリズム(clrs-algorithms)
線形構造(6):
- Array、Dynamic Array、Linked List、Stack、Queue、Deque
ツリー(12):
- Binary Tree、BST、AVL、Red-Black、B-Tree、Trie、Heap、Splay Tree、Treap、Interval Tree、Order-Statistic Tree、K-D Tree
ハッシュベース(3):
- Hash Table、Hash Set、Bloom Filter
グラフ(5):
- 隣接リスト/行列、ネットワークフロー、強連結成分、およびアルゴリズム(BFS、DFS、Dijkstra など)
高度な構造(7):
- Skip List、Disjoint Set、Segment Tree、Fenwick Tree、Fibonacci Heap、Binomial Heap、van Emde Boas Tree
文字列(3):
- 文字列アルゴリズム(KMP、Rabin-Karp)、Suffix Array、Suffix Tree
アルゴリズム:
- ソート(QuickSort、MergeSort、HeapSort、RadixSort)
選択ガイド:
- data-structure-selection.md - 「高速な……が必要」な場合のシナリオ
- complexity-cheat-sheet.md - Big-O リファレンス
クリーンコード(clean-code)
SOLID 原則(5):
- 単一責任、開放/閉鎖、リスコフの置換、インターフェース分離、依存性逆転
プラクティス(8):
- 意味のある名前、関数、コメント、フォーマット、エラー処理、ユニットテスト、コードの臭い、ボーイスカウトルール
DDIA (ddia)
データモデル(3):
- リレーショナル、ドキュメント、グラフ
ストレージ(3):
- B ツリー、LSM ツリー、カラムストレージ
レプリケーション(3):
- リーダー/フォロワー、マルチリーダー、リーダーレス
パーティショニング(2):
- 戦略、リバランシング
トランザクション(3):
- ACID、分離レベル、分散トランザクション
一貫性(2):
- モデル、線形化可能性
合意形成(1):
- アルゴリズム(Paxos、Raft)
処理(3):
- バッチ、ストリーム、イベントソーシング/CQRS
Pragmatic Programmer (pragmatic-programmer)
原則(7):
- DRY、直交性、可逆性、トレーサーバレット、プロトタイプ、ドメイン言語、見積もり
プラクティス(11):
- プレーンテキスト、シェルゲーム、デバッグ、テキスト操作、コードジェネレーター、契約による設計、アサーティブプログラミング、疎結合、リファクタリング、テスト、自動化
Domain-Driven Design (ddd)
戦略的パターン(4):
- ユビキタス言語、境界づけられたコンテキスト、コンテキストマッピング、腐敗防止層
戦術的パターン(5):
- エンティティ、値オブジェクト、集約、ドメインサービス、ドメインイベント
支援パターン(3):
- リポジトリ、ファクトリー、仕様
プラクティス(2):
- イベントストーミング、モデル探索
SICP (sicp)
手続き(3):
- 抽象化、高階関数、再帰パターン(線形、末尾、木、相互)
データ(3):
- データ抽象化、階層データ、シンボリックデータ
モジュール性(3):
- 代入と状態、環境モデル、ストリーム
メタ言語的抽象化(3):
- インタープリター、遅延評価、レジスタマシン
スキル横断型ソリューションスタック
一般的なアーキテクチャパターン
1. キャッシュスタック
Pattern: Caching layer with eviction policy
Skills Used:
- clrs-algorithms: Hash Table + Doubly Linked List (LRU)
- gof-patterns: Proxy (control access), Flyweight (share state)
- ddia: Replication (distributed cache), Consistency (cache coherence)
- clean-code: SRP (separate concerns), DIP (interface-based)
Implementation Guide:
1. Use Hash Table for O(1) key lookup
2. Use Doubly Linked List for O(1) LRU eviction
3. Apply Proxy pattern to control access and logging
4. Apply Flyweight to share immutable state
5. Consider replication strategy for distributed scenarios
2. イベントパイプライン
Pattern: Event-driven system with processing pipeline
Skills Used:
- gof-patterns: Observer (event notification), Command (encapsulate actions)
- clrs-algorithms: Queue (FIFO processing), Priority Queue (prioritized events)
- ddia: Stream Processing (Kafka/Flink), Event Sourcing
- ddd: Domain Events, Aggregates (event producers)
- clean-code: SRP (one handler per event type)
Implementation Guide:
1. Use Observer for event subscription
2. Use Queue or Priority Queue for event buffer
3. Use Command pattern for event handlers
4. Apply Event Sourcing for audit trail
5. Define Domain Events in Ubiquitous Language
3. マルチテナント SaaS
Pattern: Isolated tenants with shared infrastructure
Skills Used:
- ddd: Bounded Contexts (per tenant or shared), Context Mapping
- gof-patterns: Abstract Factory (tenant-specific objects), Strategy (tenant policies)
- clrs-algorithms: Hash Table (tenant lookup), B-Tree (tenant data indexing)
- ddia: Partitioning (tenant sharding), Isolation Levels
- clean-code: OCP (extend without modifying), ISP (tenant-specific interfaces)
Implementation Guide:
1. Define Bounded Context boundaries (shared kernel vs separate)
2. Use Abstract Factory for tenant-specific object creation
3. Use Strategy for tenant-specific policies (pricing, limits)
4. Partition data by tenant ID for isolation
5. Choose appropriate isolation level (row-level, schema-level, database-level)
4. E コマース注文システム
Pattern: Order processing with inventory, payment, shipping
Skills Used:
- ddd: Aggregates (Order, Inventory, Payment), Bounded Contexts
- gof-patterns: State (order lifecycle), Command (payment operations), Observer (notifications)
- clrs-algorithms: Priority Queue (order processing), Hash Table (inventory lookup)
- ddia: Distributed Transactions (Saga pattern), Event Sourcing
- clean-code: SRP (separate concerns), DIP (depend on repositories)
Implementation Guide:
1. Define Order Aggregate with invariants
2. Use State pattern for order states (cart → payment → processing → shipped)
3. Use Command for payment operations (process, refund, cancel)
4. Use Observer for notifications (customer, warehouse, shipping)
5. Apply Saga pattern for distributed transaction coordination
6. Use Event Sourcing for order history and replay
5. リアルタイムランキング
Pattern: Sorted rankings with fast updates
Skills Used:
- clrs-algorithms: Red-Black Tree or Skip List (sorted rankings), Hash Table (user lookup)
- gof-patterns: Observer (rank change notifications), Memento (snapshot rankings)
- ddia: Replication (read scaling), Partitioning (range-based)
- clean-code: Functions (small, focused), DRY (ranking logic)
Implementation Guide:
1. Use Sorted Set (Red-Black Tree) for O(log n) insert/delete/rank
2. Use Hash Table for O(1) user score lookup
3. Apply Observer for real-time rank change notifications
4. Use Read Replicas for scaling leaderboard queries
5. Partition by rank ranges for very large leaderboards
使用例
例 1:パターンの選択
クエリ:「具体クラスを指定せずにオブジェクトを作成したい」
ルーターの応答:
Primary Match: Creational Patterns (gof-patterns)
Recommendation: Factory Method Pattern
Routing to: gof-patterns/gof-creational/factory-method.md
Additional Considerations:
- If creating families of related objects → Abstract Factory
- If construction is complex → Builder
- See: gof-patterns/pattern-selection.md for decision tree
例 2:データ構造の選択
クエリ:「高速な検索とソート順の維持に最適なデータ構造は何ですか?」
ルーターの応答:
Primary Match: Data Structure Selection (clrs-algorithms)
Recommendation: Tree Map (Red-Black Tree or AVL Tree)
Comparison:
- Hash Table: O(1) lookup, NO sorted order
- Tree Map: O(log n) lookup, YES sorted order ✓
- Sorted Array: O(log n) search, O(n) insert ✗
Routing to: clrs-algorithms/data-structures/trees/red-black-tree.md
See also: clrs-algorithms/data-structure-selection.md
例 3:アーキテクチャ設計
クエリ:「メール、SMS、プッシュ通知に対応する通知システムを設計してください」
ルーターの応答:
Multi-Skill Solution:
1. Pattern Selection (gof-patterns):
- Observer Pattern: Subscribe to events
- Strategy Pattern: Switch between notification methods
- Command Pattern: Queue notification actions
2. Data Structures (clrs-algorithms):
- Priority Queue: Prioritize urgent notifications
- Hash Table: User preference lookup
3. Distributed Systems (ddia):
- Queue (Kafka/RabbitMQ): Async processing
- Retry mechanisms: Handle failures
4. Code Quality (clean-code):
- SRP: One class per notification channel
- OCP: Add new channels without modifying existing
Implementation Stack:
Observer → Command → Priority Queue → Strategy → DIP
例 4:コード品質レビュー
クエリ:「この関数は 200 行もあり、処理が多すぎます。どう改善すればよいですか?」
ルーターの応答:
Primary Match: Code Quality (clean-code)
Violations Detected:
1. Single Responsibility Principle (SRP) - function does too many things
2. Function size - should be 5-20 lines
Refactoring Steps:
1. Extract methods for each responsibility (clean-code/practices/functions.md)
2. Apply SRP (clean-code/solid/single-responsibility.md)
3. Use meaningful names (clean-code/practices/meaningful-names.md)
Supporting Guidance:
- pragmatic-programmer/practices/refactoring.md: When and how to refactor
- gof-patterns: Consider Template Method or Strategy if algorithm varies
Tools:
- Extract Method refactoring
- Compose Method pattern
- Replace Temp with Query
言語翻訳に関する注記
すべての例では、次の規則に従う言語非依存の擬似コードを使用します。
- 型定義には
class - メソッド/関数には
function - オブジェクトのメソッド呼び出しには
-> - コメントには
// - 型ヒントは
name: Typeの形式
翻訳ガイド
| 言語 | クラス | メソッド | 呼び出し | コメント | 型 |
|---|---|---|---|---|---|
| PHP | class | function | -> | // | Docblocks または PHP 8+ |
| JavaScript | class | function/arrow | . | // | JSDoc または TypeScript |
| TypeScript | class | method/arrow | . | // | ネイティブ型 |
| Python | class | def | . | # | 型ヒント |
| Java | class | method | . | // | ネイティブ型 |
| C# | class | method | . | // | ネイティブ型 |
| Go | type/struct | func | . | // | ネイティブ型 |
| Rust | struct/trait | fn | . | // | ネイティブ型 |
高度な使い方
複数のスキルの組み合わせ
複雑な問題については、複数のスキルを使った分析を明示的に依頼してください。
"I need a comprehensive solution for [problem] covering patterns, data structures, and distributed systems"
ルーターは関連するすべてのスキルを横断して連携し、次の内容を提示します。
- パターンの推奨(gof-patterns)
- データ構造の選択(clrs-algorithms)
- スケーラビリティに関する考慮事項(ddia)
- ドメインモデリング(該当する場合は ddd)
- コード品質のガイドライン(clean-code)
- 実装のベストプラクティス(pragmatic-programmer)
詳細な解説
特定のスキルに関する詳しいドキュメントをリクエストします。
"Show me the full Observer pattern documentation"
→ Routes to: gof-patterns/gof-behavioral/observer.md
"Explain Red-Black Tree implementation with examples"
→ Routes to: clrs-algorithms/data-structures/trees/red-black-tree.md
"What are all SOLID principles?"
→ Routes to: clean-code/solid/ (all 5 principles)
比較クエリ
トレードオフ分析をリクエストします。
"/compare singleton vs dependency injection"
→ Multi-skill analysis from gof-patterns + clean-code
"/compare b-tree vs lsm-tree"
→ Multi-skill analysis from clrs-algorithms + ddia
"/compare entity vs value object"
→ Analysis from ddd/tactical/
効果的に活用するためのヒント
1. 解決策ではなく、課題から始める
❌ 「Singleton パターンを見せてください」 ✅ 「設定マネージャーのインスタンスを1つだけにしたいです」
ルーターが適切なパターンを提案し、潜在的な問題について警告します。
2. コンテキストを伝える
❌ 「どのデータ構造を使えばよいですか?」 ✅ 「10,000 個の項目をキーですばやく検索し、ソート順に反復処理したいです」
コンテキストを伝えると、ルーティングと推奨内容の精度が向上します。
3. トレードオフについて質問する
✅ 「Factory Method と Abstract Factory のトレードオフは何ですか?」 ✅ 「Array と Linked List はどのような場合に使うべきですか?」 ✅ 「イベントソーシングと従来の CRUD を比較してください」
トレードオフに関する質問をすると、表や判断ガイドを使った比較モードが起動します。
4. 実装のガイダンスを求める
✅ 「TypeScript で LRU キャッシュを実装する方法を教えてください」 ✅ 「Python で Observer パターンを見せてください」 ✅ 「PHP で Repository パターンを実装してください」
ベストプラクティスに沿った、言語固有のコード生成が含まれます。
5. 関連する概念を探る
推奨内容を受け取った後、次のように質問してください:
- 「[pattern] と相性のよいパターンは何ですか?」
- 「[data structure] とよく組み合わせて使われるものは何ですか?」
- 「[concept] は [other concept] とどのように関連していますか?」
貢献
任意のスキルに新しいパターン、アルゴリズム、概念を追加するには:
- 既存のドキュメントで確立されている形式に従います
- 定義、使用する場面、実装、例、トレードオフを含めます
- 該当する SKILL.md のクイックリファレンステーブルを更新します
- 該当する場合は判断ガイドの項目を追加します
謝辞
この統合ナレッジベースは、多くの先人たちの功績の上に築かれています:
- Gang of Four(Gamma、Helm、Johnson、Vlissides):Design Patterns
- CLRS(Cormen、Leiserson、Rivest、Stein):Introduction to Algorithms
- Robert C. Martin(Uncle Bob):Clean Code
- Martin Kleppmann:Designing Data-Intensive Applications
- Eric Evans:Domain-Driven Design
- Andrew Hunt & David Thomas:The Pragmatic Programmer
- Harold Abelson & Gerald Jay Sussman:Structure and Interpretation of Computer Programs
Claude Code で作成
合計:7つの専門スキルにわたる147個のドキュメントファイル