Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
183 changes: 183 additions & 0 deletions .claude/commands/dp/analyze.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
# /dp::analyze - Comprehensive Design Pattern Analysis

**Purpose**: Deep analysis using sequential thinking for complex pattern decisions

## Command Usage
```
/dp::analyze <problem description>
```

## Execution Strategy

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.

### Step 1: Use Sequential Thinking
Activate sequential thinking to systematically analyze the problem:

```
Use the mcp__sequential-thinking__sequentialthinking tool with these thoughts:

Thought 1: Problem Understanding
- What specific problem is the user trying to solve?
- What are the constraints, requirements, and context?
- What's the expected scale and complexity?

Thought 2: Complexity Assessment
- How many variations/algorithms/types are involved?
- What's the growth potential and change frequency?
- What are the performance and threading requirements?
- What's the team's expertise level?

Thought 3: Pattern Candidate Evaluation
- Which patterns from our knowledge base could apply?
- What are the specific threshold criteria each pattern requires?
- How do the candidates compare against our complexity thresholds?

Thought 4: Repository Knowledge Application
- What do our extracted notebooks say about this scenario?
- Are there specific use cases or examples that match?
- What are the threading/performance considerations?

Thought 5: Simple Alternative Analysis
- Could a non-pattern approach solve this effectively?
- What would the simple Python solution look like?
- Would the pattern add real value or just complexity?

Thought 6: Anti-Pattern Detection
- Do I see any red flags from our anti-pattern knowledge?
- Is this a case of overengineering or premature optimization?
- Are there better architectural approaches?

Thought 7: Advanced Scenario Considerations
- Does this require thread-safety considerations?
- What are the testing implications?
- Are there performance trade-offs to consider?
- How does this fit into larger architectural patterns?

Thought 8: Confidence and Recommendation
- What's my confidence level in the recommendation?
- What are the key deciding factors?
- What alternatives should be mentioned?
- What implementation guidance should I provide?
```

### Step 2: Apply Repository Knowledge
Reference the specific patterns and their thresholds from this repository:

#### Pattern Thresholds (from pattern_knowledge.py):
- **Singleton**: Use for expensive objects, global access, shared state. Avoid for data models.
- **Factory**: Use for 3+ similar classes, complex creation logic. Avoid for simple cases.
- **Observer**: Use for 2+ observers, event-driven architecture. Consider thread safety.
- **Strategy**: Use for 3+ algorithms, runtime switching. Consider if/else for 2-3 cases.
- **Command**: Use for undo/redo, queuing, macros. Avoid for simple operations.
- **Builder**: Use for 5+ parameters, complex construction. Consider dataclasses for simple cases.
- **Repository**: Use for multiple data sources, complex queries. Avoid generic repository anti-pattern.
- **Adapter**: Use for incompatible interfaces, third-party integration. Simplest pattern when you can't modify interfaces.
- **Decorator**: Use for 3+ optional features, multiple combinations. Consider inheritance for 2-3 features.
- **State**: Use for 3+ states, different behaviors per state. Consider enum for simple states.

### Step 3: Provide Structured Response
Format your final response as:

```
๐Ÿง  **Pattern Analysis: [Problem Summary]**

## Problem Assessment
- **Complexity**: [Low/Medium/High]
- **Scale**: [Number of components/algorithms/states]
- **Growth Potential**: [Expected evolution]

## Pattern Evaluation
### Primary Recommendation: **[Pattern Name]**
**Confidence**: [LOW/MEDIUM/HIGH/CRITICAL]

**Why this pattern fits**:
- [Specific threshold criteria met]
- [Repository use case match]
- [Expected benefits]

**Implementation approach**:
- [Key design decisions]
- [Threading considerations if applicable]
- [Performance implications]

### Alternative Approaches
1. **[Alternative 1]**: [Brief description and trade-offs]
2. **[Alternative 2]**: [Brief description and trade-offs]

## Anti-Pattern Check
[Any warnings about overengineering or misuse]

## Repository References
- **Notebook**: `learning-resources/notebooks/[XX]_[pattern]_pattern.ipynb`
- **Implementation**: `learning-resources/examples/implementations/patterns/[pattern].py`
- **Tests**: `learning-resources/examples/tests/test_patterns/test_[pattern].py`

## Next Steps
1. [Immediate implementation guidance]
2. [Testing strategy]
3. [Future considerations]
```

### Step 4: Handle Edge Cases
- **Multiple viable patterns**: Provide comparison matrix
- **No pattern needed**: Explain why simple approach is better
- **Borderline cases**: Discuss decision factors and thresholds
- **Anti-pattern detected**: Provide strong warning and alternatives

## Pattern Recognition Triggers
Auto-activate deeper analysis when detecting:
- Multiple pattern keywords in problem description
- Complex scenarios with >3 components
- Growth/scalability requirements mentioned
- Performance or threading concerns
- Team experience level mentioned
- Legacy system integration
- "Future-proofing" or "extensibility" mentioned

## Examples of Quality Analysis

### High-Quality Response Pattern:
```
๐Ÿง  **Pattern Analysis: Multi-format Report Generation System**

## Problem Assessment
- **Complexity**: High (4+ formats, different logic per format)
- **Scale**: 4 current formats, growth expected
- **Growth Potential**: High (customer requests for new formats)

## Pattern Evaluation
### Primary Recommendation: **Strategy Pattern**
**Confidence**: HIGH

**Why this pattern fits**:
โœ“ 4+ algorithms (exceeds threshold of 3)
โœ“ Runtime selection needed
โœ“ Expected growth potential
โœ“ Different logic per format

**Implementation approach**:
- Create ReportGenerator interface
- Implement strategy for each format (PDF, Excel, CSV, Word)
- Use ReportService as context for strategy selection
- Consider factory for strategy creation

### Alternative Approaches
1. **Simple if/else**: Would work but becomes unwieldy at 4+ formats
2. **Plugin architecture**: Overkill unless external format providers needed

## Anti-Pattern Check
โœ… No overengineering detected - complexity justifies pattern usage

## Repository References
- **Notebook**: `learning-resources/notebooks/04_strategy_pattern.ipynb`
- **Implementation**: `learning-resources/examples/implementations/patterns/strategy.py`

## Next Steps
1. Define ReportGenerator interface
2. Extract existing format logic to separate strategies
3. Implement strategy selection mechanism
4. Add comprehensive tests for each format
```

Remember: Always prioritize solving real problems over pattern usage. When in doubt, recommend the simpler approach.
Loading