Code Generation Cheat Sheet
Complete reference guide for Code Generation with interactive examples and live playground links
Click on any section to jump directly to it
Basic Prompts
Function Generation
Basic function and class generation prompts
# Generate a function with specific requirements
Generate a function that:
- Takes an array of numbers as input
- Returns the sum of all even numbers
- Handles empty arrays and invalid inputs
- Includes error handling
- Has clear documentation
# Generate a class with methods
Create a class that:
- Manages user authentication
- Includes login, logout, and token refresh methods
- Uses secure password hashing
- Implements proper error handling
- Follows OOP principles
API Endpoint Generation
API endpoint generation prompts
# Generate a REST API endpoint
Create a REST API endpoint that:
- Handles user registration
- Validates input data
- Stores user information securely
- Returns appropriate status codes
- Includes input validation
- Follows REST best practices
# Generate a GraphQL resolver
Create a GraphQL resolver that:
- Fetches user profile data
- Includes proper error handling
- Implements data validation
- Uses efficient database queries
- Follows GraphQL best practices
Component Generation
Component generation prompts
# Generate a React component
Create a React component that:
- Displays a user profile
- Handles loading states
- Implements error boundaries
- Uses proper TypeScript types
- Follows React best practices
- Is responsive and accessible
# Generate a Vue component
Create a Vue component that:
- Implements a data table
- Includes sorting and filtering
- Uses Vue 3 Composition API
- Has proper TypeScript support
- Follows Vue best practices
Advanced Prompts
Algorithm Generation
Algorithm generation prompts
# Generate a sorting algorithm
Implement a sorting algorithm that:
- Has O(n log n) time complexity
- Uses minimal memory
- Handles edge cases
- Includes performance optimizations
- Has clear documentation
# Generate a search algorithm
Create a search algorithm that:
- Efficiently finds patterns in text
- Handles large datasets
- Includes proper error handling
- Has clear documentation
- Includes performance analysis
Data Structure Generation
Data structure generation prompts
# Generate a custom data structure
Implement a data structure that:
- Efficiently stores and retrieves data
- Has O(1) time complexity for key operations
- Includes proper error handling
- Has clear documentation
- Includes performance analysis
# Generate a tree structure
Create a tree data structure that:
- Supports efficient traversal
- Handles node insertion and deletion
- Maintains balance
- Includes proper error handling
- Has clear documentation
Design Pattern Implementation
Design pattern implementation prompts
# Generate a design pattern implementation
Implement the Observer pattern that:
- Supports multiple observers
- Handles event propagation
- Includes proper error handling
- Has clear documentation
- Follows SOLID principles
# Generate a factory pattern
Create a factory pattern that:
- Creates different types of objects
- Handles object initialization
- Includes proper error handling
- Has clear documentation
- Follows SOLID principles
Test Generation
Unit Test Generation
Test generation prompts
# Generate unit tests
Create unit tests that:
- Cover all edge cases
- Include proper assertions
- Use mocking where appropriate
- Follow testing best practices
- Have clear documentation
# Generate integration tests
Create integration tests that:
- Test component interactions
- Include proper setup and teardown
- Use appropriate test data
- Follow testing best practices
- Have clear documentation
Test Data Generation
Test data generation prompts
# Generate test data
Create test data that:
- Covers all edge cases
- Includes invalid inputs
- Uses realistic values
- Follows data generation best practices
- Has clear documentation
# Generate mock objects
Create mock objects that:
- Simulate real behavior
- Include proper error cases
- Use realistic data
- Follow mocking best practices
- Have clear documentation
Performance Test Generation
Performance test generation prompts
# Generate performance tests
Create performance tests that:
- Measure response times
- Test under load
- Include proper metrics
- Follow performance testing best practices
- Have clear documentation
# Generate stress tests
Create stress tests that:
- Test system limits
- Include proper monitoring
- Use realistic scenarios
- Follow stress testing best practices
- Have clear documentation
Documentation Generation
Code Documentation
Code documentation generation prompts
# Generate code documentation
Create documentation that:
- Explains the purpose
- Describes parameters
- Includes return values
- Documents exceptions
- Provides usage examples
# Generate API documentation
Create API documentation that:
- Describes endpoints
- Includes request/response examples
- Documents error codes
- Provides authentication details
- Includes rate limiting information
Architecture Documentation
Architecture documentation generation prompts
# Generate architecture documentation
Create architecture documentation that:
- Describes system components
- Explains data flow
- Includes diagrams
- Documents dependencies
- Provides deployment information
# Generate design documentation
Create design documentation that:
- Explains design decisions
- Describes patterns used
- Includes trade-offs
- Documents constraints
- Provides future considerations
User Documentation
User documentation generation prompts
# Generate user documentation
Create user documentation that:
- Explains features
- Provides step-by-step guides
- Includes troubleshooting
- Documents requirements
- Provides examples
# Generate API user guide
Create an API user guide that:
- Explains authentication
- Provides code examples
- Includes best practices
- Documents common issues
- Provides integration guides
Best Practices
Code Quality
Code quality generation prompts
# Generate high-quality code
Create code that:
- Follows style guidelines
- Uses meaningful names
- Includes proper comments
- Has consistent formatting
- Follows SOLID principles
# Generate maintainable code
Create maintainable code that:
- Is modular
- Has clear responsibilities
- Includes proper error handling
- Has good test coverage
- Follows DRY principles
Security
Security-focused generation prompts
# Generate secure code
Create secure code that:
- Validates input
- Handles sensitive data
- Uses proper encryption
- Implements authentication
- Follows security best practices
# Generate secure API
Create a secure API that:
- Uses proper authentication
- Implements rate limiting
- Validates input
- Handles errors securely
- Follows security best practices
Performance
Performance-focused generation prompts
# Generate performant code
Create performant code that:
- Uses efficient algorithms
- Minimizes memory usage
- Implements caching
- Optimizes database queries
- Follows performance best practices
# Generate scalable code
Create scalable code that:
- Handles concurrent requests
- Uses proper data structures
- Implements proper error handling
- Has good resource management
- Follows scalability best practices
Code Generation - Interactive Developer Reference
Hover over code blocks to copy or run in live playground