Provide comprehensive explanation of code, architecture, or technical concepts with deep context and examples.
/explain [code snippet, file path, or concept]
When explaining code:
# Understand the context
rg "function_name|class_name" -B 5 -A 5
fd "test.*function_name" --type f
rg "import.*module|require.*module"
# Trace usage patterns
rg "function_name\(" -A 2 -B 2- Purpose: What this code/concept achieves
- Context: Where it fits in the larger system
- Dependencies: What it relies on
// Original code with inline annotations
function example(param1, param2) { // [1] Function signature
const result = process(param1); // [2] Processing step
return transform(result, param2); // [3] Transformation
}
Line-by-line explanation:
- Function accepts two parameters for...
- First parameter undergoes processing to...
- Result is transformed using second parameter...
-
Input Flow
- Data enters through...
- Validation occurs at...
- Preprocessing includes...
-
Core Logic
- Algorithm/pattern used
- Time/space complexity
- Edge cases handled
-
Output Generation
- Result format
- Error conditions
- Side effects
Compare to familiar concept (e.g., "Think of it like a postal sorting facility where...")
- Design pattern identification
- Idioms and conventions
- Best practices demonstrated
// Basic usage
const result = example("input", { option: true });
// Advanced usage with error handling
try {
const result = await example(data, config);
console.log(result);
} catch (error) {
handleError(error);
}
- Links to similar functionality
- Alternative approaches
- Evolution from older patterns
- Common mistakes to avoid
- Performance considerations
- Security implications
- Testing strategies
┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Input │────▶│ Process │────▶│ Output │
└─────────────┘ └─────────────┘ └─────────────┘
│ │ │
▼ ▼ ▼
Validation Transform Format
- Official documentation references
- Tutorial recommendations
- Deep-dive articles
- Video explanations
/explain 'fn longest<'a>(x: &'a str, y: &'a str) -> &'a str'
/explain event-driven architecture in our microservices
/explain the rate limiting implementation in src/middleware/throttle.rs
- Start with the "why" before the "how"
- Use progressive disclosure (simple → detailed)
- Include concrete examples
- Connect to familiar concepts
- Highlight important edge cases
- Explain trade-offs and design decisions