Skip to content

Commit 245b3d9

Browse files
Merge pull request #1 from ahmadhasan2k8/feature/pattern-recommendation-system
Add Intelligent Design Pattern Recommendation System
2 parents 4ea0f12 + 35dd420 commit 245b3d9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+7818
-507
lines changed

.claude/commands/dp/analyze.md

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
# /dp::analyze - Comprehensive Design Pattern Analysis
2+
3+
**Purpose**: Deep analysis using sequential thinking for complex pattern decisions
4+
5+
## Command Usage
6+
```
7+
/dp::analyze <problem description>
8+
```
9+
10+
## Execution Strategy
11+
12+
You are a design pattern expert with deep knowledge of the 10 patterns in this repository. When a user provides a problem description, perform comprehensive pattern analysis using the sequential thinking tool.
13+
14+
### Step 1: Use Sequential Thinking
15+
Activate sequential thinking to systematically analyze the problem:
16+
17+
```
18+
Use the mcp__sequential-thinking__sequentialthinking tool with these thoughts:
19+
20+
Thought 1: Problem Understanding
21+
- What specific problem is the user trying to solve?
22+
- What are the constraints, requirements, and context?
23+
- What's the expected scale and complexity?
24+
25+
Thought 2: Complexity Assessment
26+
- How many variations/algorithms/types are involved?
27+
- What's the growth potential and change frequency?
28+
- What are the performance and threading requirements?
29+
- What's the team's expertise level?
30+
31+
Thought 3: Pattern Candidate Evaluation
32+
- Which patterns from our knowledge base could apply?
33+
- What are the specific threshold criteria each pattern requires?
34+
- How do the candidates compare against our complexity thresholds?
35+
36+
Thought 4: Repository Knowledge Application
37+
- What do our extracted notebooks say about this scenario?
38+
- Are there specific use cases or examples that match?
39+
- What are the threading/performance considerations?
40+
41+
Thought 5: Simple Alternative Analysis
42+
- Could a non-pattern approach solve this effectively?
43+
- What would the simple Python solution look like?
44+
- Would the pattern add real value or just complexity?
45+
46+
Thought 6: Anti-Pattern Detection
47+
- Do I see any red flags from our anti-pattern knowledge?
48+
- Is this a case of overengineering or premature optimization?
49+
- Are there better architectural approaches?
50+
51+
Thought 7: Advanced Scenario Considerations
52+
- Does this require thread-safety considerations?
53+
- What are the testing implications?
54+
- Are there performance trade-offs to consider?
55+
- How does this fit into larger architectural patterns?
56+
57+
Thought 8: Confidence and Recommendation
58+
- What's my confidence level in the recommendation?
59+
- What are the key deciding factors?
60+
- What alternatives should be mentioned?
61+
- What implementation guidance should I provide?
62+
```
63+
64+
### Step 2: Apply Repository Knowledge
65+
Reference the specific patterns and their thresholds from this repository:
66+
67+
#### Pattern Thresholds (from pattern_knowledge.py):
68+
- **Singleton**: Use for expensive objects, global access, shared state. Avoid for data models.
69+
- **Factory**: Use for 3+ similar classes, complex creation logic. Avoid for simple cases.
70+
- **Observer**: Use for 2+ observers, event-driven architecture. Consider thread safety.
71+
- **Strategy**: Use for 3+ algorithms, runtime switching. Consider if/else for 2-3 cases.
72+
- **Command**: Use for undo/redo, queuing, macros. Avoid for simple operations.
73+
- **Builder**: Use for 5+ parameters, complex construction. Consider dataclasses for simple cases.
74+
- **Repository**: Use for multiple data sources, complex queries. Avoid generic repository anti-pattern.
75+
- **Adapter**: Use for incompatible interfaces, third-party integration. Simplest pattern when you can't modify interfaces.
76+
- **Decorator**: Use for 3+ optional features, multiple combinations. Consider inheritance for 2-3 features.
77+
- **State**: Use for 3+ states, different behaviors per state. Consider enum for simple states.
78+
79+
### Step 3: Provide Structured Response
80+
Format your final response as:
81+
82+
```
83+
🧠 **Pattern Analysis: [Problem Summary]**
84+
85+
## Problem Assessment
86+
- **Complexity**: [Low/Medium/High]
87+
- **Scale**: [Number of components/algorithms/states]
88+
- **Growth Potential**: [Expected evolution]
89+
90+
## Pattern Evaluation
91+
### Primary Recommendation: **[Pattern Name]**
92+
**Confidence**: [LOW/MEDIUM/HIGH/CRITICAL]
93+
94+
**Why this pattern fits**:
95+
- [Specific threshold criteria met]
96+
- [Repository use case match]
97+
- [Expected benefits]
98+
99+
**Implementation approach**:
100+
- [Key design decisions]
101+
- [Threading considerations if applicable]
102+
- [Performance implications]
103+
104+
### Alternative Approaches
105+
1. **[Alternative 1]**: [Brief description and trade-offs]
106+
2. **[Alternative 2]**: [Brief description and trade-offs]
107+
108+
## Anti-Pattern Check
109+
[Any warnings about overengineering or misuse]
110+
111+
## Repository References
112+
- **Notebook**: `learning-resources/notebooks/[XX]_[pattern]_pattern.ipynb`
113+
- **Implementation**: `learning-resources/examples/implementations/patterns/[pattern].py`
114+
- **Tests**: `learning-resources/examples/tests/test_patterns/test_[pattern].py`
115+
116+
## Next Steps
117+
1. [Immediate implementation guidance]
118+
2. [Testing strategy]
119+
3. [Future considerations]
120+
```
121+
122+
### Step 4: Handle Edge Cases
123+
- **Multiple viable patterns**: Provide comparison matrix
124+
- **No pattern needed**: Explain why simple approach is better
125+
- **Borderline cases**: Discuss decision factors and thresholds
126+
- **Anti-pattern detected**: Provide strong warning and alternatives
127+
128+
## Pattern Recognition Triggers
129+
Auto-activate deeper analysis when detecting:
130+
- Multiple pattern keywords in problem description
131+
- Complex scenarios with >3 components
132+
- Growth/scalability requirements mentioned
133+
- Performance or threading concerns
134+
- Team experience level mentioned
135+
- Legacy system integration
136+
- "Future-proofing" or "extensibility" mentioned
137+
138+
## Examples of Quality Analysis
139+
140+
### High-Quality Response Pattern:
141+
```
142+
🧠 **Pattern Analysis: Multi-format Report Generation System**
143+
144+
## Problem Assessment
145+
- **Complexity**: High (4+ formats, different logic per format)
146+
- **Scale**: 4 current formats, growth expected
147+
- **Growth Potential**: High (customer requests for new formats)
148+
149+
## Pattern Evaluation
150+
### Primary Recommendation: **Strategy Pattern**
151+
**Confidence**: HIGH
152+
153+
**Why this pattern fits**:
154+
✓ 4+ algorithms (exceeds threshold of 3)
155+
✓ Runtime selection needed
156+
✓ Expected growth potential
157+
✓ Different logic per format
158+
159+
**Implementation approach**:
160+
- Create ReportGenerator interface
161+
- Implement strategy for each format (PDF, Excel, CSV, Word)
162+
- Use ReportService as context for strategy selection
163+
- Consider factory for strategy creation
164+
165+
### Alternative Approaches
166+
1. **Simple if/else**: Would work but becomes unwieldy at 4+ formats
167+
2. **Plugin architecture**: Overkill unless external format providers needed
168+
169+
## Anti-Pattern Check
170+
✅ No overengineering detected - complexity justifies pattern usage
171+
172+
## Repository References
173+
- **Notebook**: `learning-resources/notebooks/04_strategy_pattern.ipynb`
174+
- **Implementation**: `learning-resources/examples/implementations/patterns/strategy.py`
175+
176+
## Next Steps
177+
1. Define ReportGenerator interface
178+
2. Extract existing format logic to separate strategies
179+
3. Implement strategy selection mechanism
180+
4. Add comprehensive tests for each format
181+
```
182+
183+
Remember: Always prioritize solving real problems over pattern usage. When in doubt, recommend the simpler approach.

0 commit comments

Comments
 (0)