Code Generation
Templates for creating new code components
Stop typing the same prompts repeatedly. Build a systematic library of reusable prompt templates that ensure consistent, high-quality AI responses while saving hours of typing time.
Without templates, developers often:
With templates, you:
Code Generation
Templates for creating new code components
Debugging
Systematic debugging prompt patterns
Refactoring
Consistent refactoring instructions
Documentation
Templates for various documentation needs
Testing
Test generation and improvement prompts
Reviews
Code review and analysis templates
## Feature: [FEATURE_NAME]
### Context- Current file: [FILE_PATH]- Related files: [RELATED_FILES]- Design reference: [FIGMA_LINK/SPEC]
### Requirements1. [REQUIREMENT_1]2. [REQUIREMENT_2]3. [REQUIREMENT_3]
### Constraints- Must maintain backward compatibility- Follow existing patterns in [EXAMPLE_FILE]- Include proper error handling- Add comprehensive JSDoc comments
### Implementation ApproachPlease implement this feature using [PATTERN/ARCHITECTURE]
Usage Example:
## Feature: User Authentication Modal
### Context- Current file: components/Layout.tsx- Related files: lib/auth.ts, components/Button.tsx- Design reference: @figma authentication-flow
### Requirements1. Modal with email/password inputs2. Social login buttons (Google, GitHub)3. Remember me checkbox4. Forgot password link
### Constraints- Must maintain backward compatibility- Follow existing patterns in components/Modal.tsx- Include proper error handling- Add comprehensive JSDoc comments
### Implementation ApproachPlease implement this feature using our existing Modal component pattern
## Bug Investigation: [ISSUE_DESCRIPTION]
### Symptoms- Error message: [ERROR_MESSAGE]- When it occurs: [TRIGGER_CONDITIONS]- Affected users: [USER_SEGMENT]
### Current Behavior[DESCRIBE_CURRENT]
### Expected Behavior[DESCRIBE_EXPECTED]
### Investigation Steps1. Add strategic console.logs to trace execution flow2. Check for [COMMON_CAUSE_1]3. Verify [ASSUMPTION_1]4. Run tests and report findings
### Context Files@file [RELEVANT_FILE_1]@file [RELEVANT_FILE_2]
## Refactor: [COMPONENT/FUNCTION_NAME]
### Goal[SPECIFIC_REFACTORING_GOAL]
### Current Issues1. [ISSUE_1]2. [ISSUE_2]
### Target Architecture- Pattern: [DESIGN_PATTERN]- Dependencies: [NEW_DEPS]- Breaking changes: [YES/NO]
### Preservation Requirements- All existing tests must pass- Public API remains unchanged- Performance must not degrade
### Step-by-Step Approach1. [STEP_1]2. [STEP_2]3. Run tests after each step
## Generate Tests: [COMPONENT/FUNCTION]
### Test Framework- Framework: [Jest/Vitest/etc]- Style: [describe/it blocks]- Coverage target: [80%+]
### Test Categories Needed- [ ] Happy path scenarios- [ ] Edge cases- [ ] Error conditions- [ ] Performance boundaries- [ ] Integration points
### Specific Scenarios1. [SCENARIO_1]2. [SCENARIO_2]
### Mock Requirements- External APIs: [API_LIST]- Database calls: [DB_OPERATIONS]- Time-dependent operations
Include descriptive test names and comprehensive assertions
Use conditional sections based on context:
## Implement: [FEATURE]
### Base Requirements[ALWAYS_INCLUDE]
{{IF_FRONTEND}}### UI Requirements- Responsive design- Accessibility (WCAG 2.1 AA)- Loading states- Error states{{/IF_FRONTEND}}
{{IF_BACKEND}}### API Requirements- RESTful endpoints- Input validation- Rate limiting- Proper status codes{{/IF_BACKEND}}
{{IF_DATABASE}}### Database Considerations- Migration script- Indexes for performance- Data integrity constraints{{/IF_DATABASE}}
Link templates for complex workflows:
## Workflow: Add New Feature
### Step 1: Planning[Use PLANNING_TEMPLATE]
### Step 2: Implementation[Use FEATURE_TEMPLATE with context from Step 1]
### Step 3: Testing[Use TEST_TEMPLATE with implementation from Step 2]
### Step 4: Documentation[Use DOCS_TEMPLATE with all previous context]
## Create React Component: [COMPONENT_NAME]
### Type- [ ] Functional Component- [ ] Server Component (Next.js 13+)- [ ] Client Component with 'use client'
### Features- [ ] TypeScript props interface- [ ] Memo optimization- [ ] Error boundary- [ ] Loading state- [ ] Storybook story
### Hooks Needed- [ ] useState for: [STATE_DESCRIPTION]- [ ] useEffect for: [EFFECT_PURPOSE]- [ ] Custom hooks: [HOOK_NAMES]
### Performance- [ ] Implement React.memo if pure- [ ] Use useCallback for handlers- [ ] Lazy load if heavy
## Create API Endpoint: [ENDPOINT_PATH]
### HTTP Method: [GET/POST/PUT/DELETE]
### Request- Headers: [REQUIRED_HEADERS]- Body schema: [JSON_SCHEMA]- Query params: [PARAM_LIST]
### Validation- [ ] Input sanitization- [ ] Type checking- [ ] Business rule validation
### Response- Success (200): [RESPONSE_SCHEMA]- Error cases: [ERROR_SCENARIOS]
### Middleware- [ ] Authentication required- [ ] Rate limiting- [ ] Request logging
## Create Python Module: [MODULE_NAME]
### Purpose[MODULE_DESCRIPTION]
### Dependencies- Standard library: [IMPORTS]- External packages: [REQUIREMENTS]
### Classes/Functions- Main class: [CLASS_NAME]- Public methods: [METHOD_LIST]- Type hints: Required
### Testing- [ ] Unit tests with pytest- [ ] Type checking with mypy- [ ] Docstrings (Google style)
### Error Handling- Custom exceptions: [EXCEPTION_NAMES]- Logging level: [INFO/DEBUG/ERROR]
Track your prompts for one week:
## Template Name: [DESCRIPTIVE_NAME]
### Always Include- [CONSTANT_ELEMENT_1]- [CONSTANT_ELEMENT_2]
### Variables- [VARIABLE_1]: [DESCRIPTION]- [VARIABLE_2]: [DESCRIPTION]
### Optional Sections- [CONDITION]: [OPTIONAL_CONTENT]
Store templates in:
.cursor/prompts/
directory.cursor/├── prompts/│ ├── feature/│ │ ├── component.md│ │ ├── api-endpoint.md│ │ └── database-migration.md│ ├── debug/│ │ ├── performance.md│ │ ├── memory-leak.md│ │ └── integration-failure.md│ ├── refactor/│ │ ├── extract-function.md│ │ ├── design-pattern.md│ │ └── performance-optimize.md│ └── team/│ ├── code-review.md│ ├── onboarding.md│ └── documentation.md
{ "Cursor Feature Template": { "prefix": "cursor-feature", "body": [ "## Feature: ${1:FeatureName}", "", "### Context", "- Current file: ${TM_FILEPATH}", "- Related files: ${2:files}", "", "### Requirements", "1. ${3:requirement}", "", "### Constraints", "- ${4:constraint}" ] }}
When implementing new features, always structure the request using our feature template format with Context, Requirements, and Constraints sections.
Track these metrics:
Metric | Before Templates | With Templates | Improvement |
---|---|---|---|
Prompt writing time | 5 min/prompt | 30 sec/prompt | 90% faster |
AI response quality | Variable | Consistent | 40% better |
Rework needed | Often | Rare | 75% less |
Team consistency | Low | High | 3x better |
With your prompt template library established:
Remember: Great templates are living documents. Update them as you learn what produces the best AI responses for your specific needs.