Documentation Skill
Use this skill when writing code documentation, API docs, or user guides.
Overview
Write clear, comprehensive documentation that helps users and developers understand and use the code.
When to Use
Use this skill when:
- Documenting code changes
- Writing API documentation
- Creating README files
- Writing user guides
- Updating technical documentation
Workflow
Step 1: Identify Documentation Needs
- What needs to be documented?
- Who is the audience?
- What format is appropriate?
- Where should it live?
Documentation Types:
- Code comments (inline)
- API documentation
- README files
- User guides
- Architecture docs
- Contributing guides
Step 2: Write Code Comments
- Document complex logic
- Explain "why" not "what"
- Document public APIs
- Add JSDoc/TSDoc comments
Comment Guidelines:
- Explain why, not what
- Keep comments up to date
- Remove commented-out code
- Use clear language
JSDoc Example:
/**
* Calculates total price including tax.
*
* @param price - The base price before tax
* @param taxRate - The tax rate as a decimal (e.g., 0.1 for 10%)
* @returns The total price including tax
* @throws {Error} If price is negative or taxRate is invalid
*/
function calculateTotal(price: number, taxRate: number): number {
if (price < 0) throw new Error('Price cannot be negative');
return price * (1 + taxRate);
}
Step 3: Write README
- Project overview
- Installation instructions
- Usage examples
- Configuration options
- Contributing guidelines
README Structure:
- Title and description
- Features
- Installation
- Quick start
- Usage examples
- Configuration
- API reference
- Contributing
- License
Step 4: Write API Documentation
- Document all endpoints
- Request/response examples
- Authentication
- Error codes
- Rate limits
API Doc Structure:
- Endpoint URL and method
- Description
- Parameters
- Request body
- Response format
- Status codes
- Examples
- Error responses
Step 5: Write User Guides
- Getting started
- Common tasks
- Troubleshooting
- FAQ
- Examples
User Guide Structure:
- Introduction
- Prerequisites
- Installation
- Basic usage
- Advanced features
- Troubleshooting
- FAQ
Step 6: Keep Documentation Updated
- Update with code changes
- Review regularly
- Remove outdated info
- Add examples
Documentation Principles
- Clear: Easy to understand
- Complete: Covers all aspects
- Current: Up to date
- Concise: No unnecessary words
- Examples: Show, don't just tell
Documentation Types
- Inline Comments: Explain complex code
- API Docs: Document public interfaces
- README: Project overview and setup
- Guides: Step-by-step instructions
- Architecture: System design
- Contributing: How to contribute
Anti-Patterns
- Outdated documentation
- Missing documentation
- Over-commenting obvious code
- Commented-out code
- No examples
- Jargon without explanation
Verification
- Code comments added
- README complete
- API documented
- Examples provided
- Documentation reviewed
Related Skills
- API Design - API documentation structure
- Component Design - Component docs
- Git Workflow - Documentation in commits
Related Commands
- Design Command - Design documentation structure
- Research Command - Research best practices
Next Steps
- API Design - Document API layer
- Test Driven Development - Write tests