TL;DR - Best AI Prompts for Developers
Looking for ready-to-use AI prompts for coding? This guide contains 40+ copy-paste prompts that work with ChatGPT, Claude, Gemini, Cursor, and GitHub Copilot. Each prompt includes placeholders you can customize for your specific needs. For foundational prompting skills, see the Prompt Engineering Fundamentals guide.
Whatβs included:
- Code Review Prompts β Comprehensive reviews covering security, performance, accessibility, and maintainability
- Debugging Prompts β Turn cryptic errors into clear fixes with step-by-step explanations
- Code Generation Prompts β Create functions, API endpoints, React components, TypeScript types, and SQL queries
- Documentation Prompts β Generate README files, JSDoc comments, and API documentation
- Testing Prompts β Generate unit tests, integration tests, and E2E test scenarios
- Refactoring Prompts β Clean up messy code, modernize legacy codebases, and apply design patterns
- Performance Prompts β Find bottlenecks, optimize algorithms, and fix memory leaks
- Architecture Prompts β Design systems, choose tech stacks, and review architecture decisions
- Learning Prompts β Understand unfamiliar code and learn new concepts
π‘ Pro tip: All prompts support both pasting code directly AND referencing files (using @filename in Cursor, #file: in Copilot, or file uploads in ChatGPT/Claude). For a comparison of AI coding tools, see the AI-Powered IDEs Comparison guide.
How to Use These AI Coding Prompts
Each prompt below is ready to copy and paste. Hereβs how they work:
- Copy the entire prompt from the code block
- Replace the placeholder comments (lines starting with
# REPLACE:) with your actual content - Paste into ChatGPT, Claude, or your preferred AI
- Get your result and iterate if needed
Providing Code to the AI
You have two options for sharing your code:
Option A: Paste Code Directly
=== CODE ===
function calculateTotal(items) {
return items.reduce((sum, item) => sum + item.price, 0);
}
Option B: Reference a File (if your tool supports it)
| Tool | How to Reference Files |
|---|---|
| Cursor | Use @filename or select code in editor |
| GitHub Copilot Chat | Use #file:path/to/file.js or @workspace |
| Claude (browser) | Upload file or drag & drop |
| ChatGPT | Upload file using attachment button |
| VS Code + Continue | Use @file or highlight code |
| Windsurf | Use @filename or Cmd+L on selection |
=== CODE ===
# Using file reference (Cursor example):
See @src/utils/calculate.ts
# Using file reference (Copilot Chat example):
See #file:src/utils/calculate.ts
# Or pasted directly:
[paste your code here]
All prompts in this guide support both approaches. Choose what works best for your workflow.
Code Review Prompts
General Code Review
Use this when you want a comprehensive review of any code before merging. For more on advanced prompting techniques for code review, see the Advanced Prompt Engineering guide.
You are a senior software engineer conducting a code review. Review the code below and identify issues in these categories:
π¨ CRITICAL - Must fix (security vulnerabilities, bugs, data loss risks)
β οΈ WARNING - Should fix (performance issues, code smells, maintainability)
π‘ SUGGESTION - Nice to have (style improvements, minor optimizations)
For each issue found:
1. Quote the specific problematic code
2. Explain WHY it's a problem
3. Show the corrected code
4. Explain the fix
=== CONTEXT ===
Language: [JavaScript / TypeScript / Python / Java / Go / Rust / other]
Framework: [React / Next.js / Express / Django / Spring / None]
What this code does:
# REPLACE: Brief description of the code's purpose
=== CODE ===
# OPTION 1 - Reference file (if your tool supports it):
# See @path/to/your/file.ts
# OPTION 2 - Paste code directly:
# REPLACE: Paste your code here
Example Usage:
=== CONTEXT ===
Language: TypeScript
Framework: Express
What this code does: Handles user login and creates a session
=== CODE ===
See @src/auth/login.ts
Security-Focused Code Review
Use this for authentication, payment, or sensitive data handling code.
You are a security engineer. Perform a security audit of this code.
Check for:
- SQL/NoSQL injection
- XSS vulnerabilities
- Authentication/authorization flaws
- Sensitive data exposure (API keys, passwords, PII)
- Insecure cryptography
- CSRF vulnerabilities
- Path traversal
- Command injection
- Insecure deserialization
- Broken access control
For each vulnerability:
- Severity: CRITICAL / HIGH / MEDIUM / LOW
- OWASP Category: (e.g., A01:2021 - Broken Access Control)
- Attack scenario: How could this be exploited?
- Fix: Show secure code
- Prevention: How to avoid this in the future
=== CONTEXT ===
This is a [web API / frontend / backend service / microservice]
It handles: [user authentication / payments / user data / admin functions]
Authentication method: [JWT / Session / OAuth / API Key]
=== CODE ===
# OPTION 1 - Reference file:
# See @src/auth/login.ts (or your file path)
# OPTION 2 - Paste code directly:
# REPLACE: Paste your security-sensitive code here
Performance-Focused Code Review
Use this to identify performance bottlenecks and optimization opportunities.
You are a performance engineer. Review this code for performance issues.
Check for:
- Algorithm complexity issues (O(nΒ²) or worse)
- Unnecessary memory allocations
- N+1 query problems
- Missing caching opportunities
- Blocking operations in async code
- Inefficient data structures
- Redundant computations
- Large bundle size impacts (frontend)
For each issue:
- Impact: HIGH / MEDIUM / LOW
- Current complexity/cost
- Optimized solution with code
- Expected improvement
- Trade-offs (if any)
=== CONTEXT ===
Language: [JavaScript / TypeScript / Python / Java / Go]
Expected scale:
# REPLACE: e.g., "10K requests/second", "1M records in database"
=== CODE ===
# REPLACE: Paste your code here or reference file
Accessibility Code Review
Use this for frontend code that needs to be accessible.
You are an accessibility (a11y) expert. Review this frontend code for accessibility issues.
Check for:
- Missing ARIA labels and roles
- Keyboard navigation issues
- Color contrast problems
- Missing alt text for images
- Form label associations
- Focus management
- Screen reader compatibility
- Touch target sizes (mobile)
- Motion/animation concerns
Reference: WCAG 2.1 Level AA standards
For each issue:
- WCAG Criterion: (e.g., 1.1.1 Non-text Content)
- Severity: CRITICAL / HIGH / MEDIUM / LOW
- Current code
- Fixed code
- Testing method (how to verify the fix)
=== CODE ===
# REPLACE: Paste your component/HTML code
Pull Request Review
Use this to get a structured PR review summary.
Review this code change and provide a PR review summary.
=== WHAT CHANGED ===
# REPLACE: Describe what was changed and why
=== FILES CHANGED ===
# OPTION 1 - Reference files:
# See @src/components/Button.tsx (modified)
# See @src/hooks/useAuth.ts (new file)
# OPTION 2 - Paste code directly:
# [Old code:]
# REPLACE: Previous version (or "New file, no previous version")
# [New code:]
# REPLACE: New/modified code
=== GENERATE THIS REVIEW FORMAT ===
**Overall: [APPROVE / REQUEST_CHANGES / DISCUSS]**
**Summary:** (2-3 sentence summary of the changes)
**What's Good:**
- (list positives)
**Must Fix Before Merge:**
- (blocking issues with specific line references)
**Suggestions:**
- (non-blocking improvements)
**Questions for Author:**
- (clarifications needed)
**Testing Checklist:**
- [ ] (specific test scenarios to verify)
Review Multiple Files
Use this when reviewing a feature that spans multiple files.
Review these related files that implement a single feature.
=== FEATURE DESCRIPTION ===
# REPLACE: What feature do these files implement?
=== FILES TO REVIEW ===
# OPTION 1 - Reference files:
# @src/api/users.ts - API route handler
# @src/services/userService.ts - Business logic
# @src/db/userRepository.ts - Database queries
# @src/types/user.ts - Type definitions
# OPTION 2 - Paste each file with headers:
# --- File: src/api/users.ts ---
# REPLACE: Paste first file
# --- File: src/services/userService.ts ---
# REPLACE: Paste second file
=== REVIEW FOCUS ===
Check for:
1. Consistency across files
2. Proper separation of concerns
3. Error handling at each layer
4. Type safety between layers
5. Overall architecture
Provide feedback organized by file, then overall architecture assessment.
Debugging Prompts
Debug an Error Message
Use this when you have an error and need help understanding and fixing it.
Help me debug this error.
=== ERROR MESSAGE ===
# REPLACE: Paste the full error message or stack trace
=== CODE ===
# OPTION 1 - Reference file:
# The error occurs in @src/utils/parser.ts around line 45
# OPTION 2 - Paste code directly:
# REPLACE: Paste the relevant code (function/file where error occurs)
=== ENVIRONMENT ===
- Language/Runtime: [e.g., Python 3.11 / Node.js 20 / Java 17]
- Framework: [e.g., React 18 / Django 4 / Spring Boot 3 / None]
- OS: [macOS / Windows / Linux]
- Package versions: [if relevant]
=== WHAT I'M TRYING TO DO ===
# REPLACE: Describe what you expected to happen
=== WHAT ACTUALLY HAPPENS ===
# REPLACE: Describe the actual behavior
=== WHAT I'VE ALREADY TRIED ===
# REPLACE: List debugging steps you've taken (or "Nothing yet")
Please:
1. Explain what this error means in simple terms
2. Identify the root cause
3. Show me the fixed code
4. Explain how to prevent this in the future
Debug: Code Not Working as Expected
Use this when thereβs no error, but behavior is wrong.
My code runs without errors but doesn't work correctly. Help me find the bug.
=== CODE ===
# OPTION 1 - Reference file:
# See @src/utils/calculateDiscount.ts
# OPTION 2 - Paste code directly:
# REPLACE: Paste your code
=== EXPECTED BEHAVIOR ===
# REPLACE: What should happen when this code runs?
=== ACTUAL BEHAVIOR ===
# REPLACE: What actually happens instead?
=== TEST CASE THAT FAILS ===
Input:
# REPLACE: What input did you provide?
Expected output:
# REPLACE: What should the output be?
Actual output:
# REPLACE: What did you actually get?
Please:
1. Trace through the code step-by-step with my test case
2. Identify where the logic goes wrong
3. Explain the bug
4. Show the corrected code
5. Suggest additional test cases to verify the fix
Debug Memory Leaks
Use this when your application has memory issues.
Help me find and fix memory leaks in this code.
=== CODE ===
# REPLACE: Paste your code, or reference files
=== SYMPTOMS ===
# REPLACE: How does the memory issue manifest?
# Example:
# - Memory usage grows over time
# - Application crashes with OOM after X hours
# - Heap snapshots show growing object count
=== CONTEXT ===
Language: [JavaScript / TypeScript / Python / Java / Go]
Runtime: [Node.js / Browser / JVM / etc.]
Framework: [React / Express / Django / etc.]
=== ANALYSIS NEEDED ===
1. Identify potential memory leaks
2. For each leak:
- What objects are being retained?
- Why aren't they being garbage collected?
- Show the fix
3. Suggest monitoring to detect future leaks
Debug Across Multiple Files
Use this when a bug involves code in multiple files.
I have a bug that involves multiple files. Help me trace through and find the issue.
=== THE PROBLEM ===
# REPLACE: Describe the bug
=== CALL CHAIN ===
# Describe how the code flows:
# 1. Request comes into @src/api/orders.ts
# 2. Calls @src/services/orderService.ts
# 3. Which queries @src/db/orderRepository.ts
=== FILES INVOLVED ===
# OPTION 1 - Reference files:
# @src/api/orders.ts - Entry point
# @src/services/orderService.ts - Business logic
# @src/db/orderRepository.ts - Database query
# OPTION 2 - Paste each file:
# --- File: src/api/orders.ts ---
# REPLACE: Paste code
# --- File: src/services/orderService.ts ---
# REPLACE: Paste code
=== WHERE I THINK THE BUG IS ===
# REPLACE: Your hypothesis (or "Not sure")
Please trace through the entire call chain and identify where the bug is.
Debug: Async / Race Condition Issues
Use this for timing-related bugs that happen intermittently.
I have an intermittent bug that seems related to async/timing.
=== CODE ===
# OPTION 1 - Reference files:
# See @src/hooks/useData.ts
# and @src/services/api.ts
# OPTION 2 - Paste code directly:
# REPLACE: Paste your async code (promises, async/await, callbacks, threads)
=== THE PROBLEM ===
# REPLACE: Describe what happens
# (e.g., "sometimes returns stale data", "occasionally crashes with null")
=== WHEN IT HAPPENS ===
- Frequency: [always / sometimes / rarely]
- Trigger:
# REPLACE: Any pattern to when it occurs?
Please:
1. Identify all async operations and their dependencies
2. Diagram possible execution orders
3. Find the race condition or timing issue
4. Provide a fix using proper synchronization
5. Show how to test for this issue
Debug Performance Bottleneck
Use this when code is slow and you need to find why.
This code is running slowly. Help me find the performance bottleneck.
=== CODE ===
# REPLACE: Paste your code or reference file
=== PERFORMANCE SYMPTOMS ===
# REPLACE: Describe the issue
# Example:
# - Function takes 5 seconds when it should take <100ms
# - API endpoint times out after 30 seconds
# - Page takes 10+ seconds to load
=== METRICS (if available) ===
# REPLACE: Any profiling data you have
# - Function X takes Y ms
# - Database query takes Z ms
# - N iterations of loop
=== EXPECTED PERFORMANCE ===
# REPLACE: What should the performance be?
Please:
1. Identify the likely bottleneck(s)
2. Explain why each is slow
3. Provide optimized code
4. Estimate the improvement
5. Suggest how to measure the improvement
Code Generation Prompts
Generate a Function with Tests
Use this to generate a complete, tested function from requirements. For more on AI coding assistants, see the CLI Tools for AI Developers guide.
Generate a function with the following requirements:
=== FUNCTION SPECIFICATION ===
Name:
# REPLACE: functionName
Purpose:
# REPLACE: What should this function do?
Parameters:
# REPLACE: List each parameter with its type and description
# Example:
# - userId (string): The unique identifier for the user
# - options (object, optional): Configuration options
# - includeDeleted (boolean): Whether to include soft-deleted records
Returns:
# REPLACE: What does it return? Include type and description
Error Handling:
# REPLACE: How should errors be handled?
# Example: Throw ValidationError for invalid input, return null if not found
=== EXISTING CODE CONTEXT (optional) ===
# If this function should integrate with existing code:
# See @src/types/user.ts for User type definition
# See @src/utils/validation.ts for validation helpers
=== REQUIREMENTS ===
Language: [JavaScript / TypeScript / Python / Java / Go]
Style: [functional / OOP / procedural]
=== GENERATE ===
1. The function with proper documentation (JSDoc / docstrings)
2. Input validation
3. 5+ unit tests covering:
- Happy path (normal usage)
- Edge cases (empty input, null, etc.)
- Error cases (invalid input)
4. Usage example
Generate a REST API Endpoint
Use this to scaffold a complete API endpoint.
Generate a REST API endpoint.
=== ENDPOINT SPECIFICATION ===
Method: [GET / POST / PUT / PATCH / DELETE]
Path:
# REPLACE: e.g., /api/users/:id
Purpose:
# REPLACE: What does this endpoint do?
=== EXISTING CODE TO INTEGRATE WITH (optional) ===
# Reference existing files your new code should work with:
# See @src/types/user.ts for User type
# See @src/db/index.ts for database connection
# See @src/middleware/auth.ts for authentication middleware
=== REQUEST ===
Headers:
# REPLACE: Required headers (e.g., Authorization: Bearer token)
Path Parameters:
# REPLACE: e.g., id (string) - User ID
Query Parameters:
# REPLACE: e.g., page (number, optional) - Page number
Request Body (for POST/PUT/PATCH):
# REPLACE: Describe the body schema
# {
# "email": "string, required, valid email",
# "name": "string, required, 1-100 chars"
# }
=== RESPONSE ===
Success (200/201):
# REPLACE: Describe successful response
Error Cases:
# REPLACE: List error scenarios
# - 400: Invalid input
# - 401: Unauthorized
# - 404: Not found
# - 500: Server error
=== TECH STACK ===
Framework: [Express.js / FastAPI / Spring Boot / NestJS / Hono / Fastify]
Database: [PostgreSQL / MongoDB / MySQL / none]
ORM: [Prisma / TypeORM / Drizzle / SQLAlchemy / none]
Validation: [Zod / Joi / Pydantic / class-validator]
=== GENERATE ===
1. Route handler with full implementation
2. Input validation with detailed error messages
3. Error handling with proper HTTP status codes
4. TypeScript types or equivalent
5. Example curl commands to test it
6. Basic test file structure
Generate React Component
Use this to create a complete React component.
Generate a React component.
=== COMPONENT SPECIFICATION ===
Name:
# REPLACE: ComponentName
Purpose:
# REPLACE: What does this component do?
Props:
# REPLACE: List props with types and descriptions
# - title (string, required): The card title
# - onClose (() => void, optional): Callback when closed
# - variant ("primary" | "secondary", default: "primary"): Style variant
State:
# REPLACE: What internal state? (or "None - stateless")
Behavior:
# REPLACE: Describe interactions
=== EXISTING CODE CONTEXT (optional) ===
# Reference existing files for consistency:
# See @src/components/Button.tsx for button style patterns
# See @src/hooks/useModal.ts for modal hook to use
# See @src/styles/theme.ts for color tokens
=== REQUIREMENTS ===
- TypeScript: [Yes / No]
- Styling: [Tailwind CSS / CSS Modules / Styled Components]
- Accessibility: Include ARIA labels, keyboard navigation
- Responsive: [Yes / No]
- Tests: Include React Testing Library tests
=== GENERATE ===
1. The component with TypeScript interface
2. Proper accessibility attributes
3. Responsive design considerations
4. 3+ unit tests
5. Storybook story (optional)
6. Usage example
Generate TypeScript Types from Data
Use this when you have data and need types.
Generate TypeScript types/interfaces for this data.
=== SAMPLE DATA ===
# REPLACE: Paste sample JSON or describe the data structure
# Example:
# {
# "id": "user_123",
# "name": "John Doe",
# "email": "john@example.com",
# "createdAt": "2024-01-15T10:30:00Z",
# "roles": ["admin", "user"],
# "settings": {
# "theme": "dark",
# "notifications": true
# }
# }
=== REQUIREMENTS ===
- Use: [interface / type / both as appropriate]
- Naming convention: [PascalCase / with prefix like I or T]
- Optional fields: [mark nullable fields as optional]
- Strictness: [strict - no any / relaxed - allow unknown fields]
=== GENERATE ===
1. Main type/interface
2. Related types (nested objects, enums)
3. Type guards (if useful)
4. Usage examples
5. Zod schema (optional, for runtime validation)
Generate Database Schema and Queries
Use this for database work.
Generate database schema and queries.
=== REQUIREMENTS ===
# REPLACE: Describe what you need to store
# Example: An e-commerce system with users, products, orders, and reviews
=== DATABASE ===
Type: [PostgreSQL / MySQL / MongoDB / SQLite]
ORM: [Prisma / TypeORM / Drizzle / SQLAlchemy / raw SQL]
=== ENTITIES ===
# REPLACE: List main entities and their relationships
# - Users (have many orders)
# - Products (belong to categories)
# - Orders (belong to user, have many items)
=== GENERATE ===
1. Schema definition (SQL or ORM format)
2. Common queries:
- Create/Insert
- Read (by ID, list with pagination, search)
- Update
- Delete
3. Complex queries for common use cases
4. Indexes for performance
5. Migration script (if using migrations)
Generate SQL Query
Use this to get optimized SQL from plain English.
Generate an optimized SQL query.
=== WHAT I NEED ===
# REPLACE: Describe what data you want in plain English
# Example: Get all orders from the last 30 days with customer name,
# total amount, and item count, sorted by amount descending
=== DATABASE SCHEMA ===
# OPTION 1 - Reference schema file:
# See @prisma/schema.prisma
# or See @src/db/migrations/001_initial.sql
# OPTION 2 - Describe or paste schema:
# REPLACE: Describe your tables or paste CREATE TABLE statements
# customers (id, name, email, created_at)
# orders (id, customer_id, total_amount, created_at)
# order_items (id, order_id, product_id, quantity, price)
=== DATABASE ===
Type: [PostgreSQL / MySQL / SQLite / SQL Server]
=== REQUIREMENTS ===
# REPLACE: Any specific needs
# - Must perform well on 1M+ rows
# - Need pagination (page 1, 20 per page)
# - Handle NULL values
=== GENERATE ===
1. The SQL query with comments explaining each part
2. Suggested indexes for performance
3. Explain query execution plan considerations
4. Example output (mock data)
5. Alternative approach if there are tradeoffs
Extend Existing Code
Use this when you need to add features to existing code.
Add a new feature to existing code.
=== EXISTING CODE ===
# OPTION 1 - Reference files:
# See @src/services/userService.ts
# See @src/types/user.ts
# OPTION 2 - Paste existing code:
# REPLACE: Paste the current implementation
=== NEW FEATURE ===
# REPLACE: Describe what to add
# Example: Add a method to soft-delete users instead of hard delete
=== REQUIREMENTS ===
- Maintain backward compatibility: [Yes / No]
- Follow existing code patterns and style
- Add tests for new functionality
=== GENERATE ===
1. Updated code with new feature
2. Only show the parts that changed (use ... for unchanged sections)
3. New tests for the added functionality
4. Migration notes if there are breaking changes
Documentation Prompts
Generate README.md
Use this to create a comprehensive project README.
Generate a README.md for my project.
=== PROJECT INFO ===
Name:
# REPLACE: project-name
One-line description:
# REPLACE: What does this project do?
Problem it solves:
# REPLACE: Why does this project exist?
=== TECH STACK ===
# REPLACE: List technologies
=== KEY FEATURES ===
# REPLACE: List 3-5 main features
=== INSTALLATION ===
Prerequisites:
# REPLACE: What needs to be installed first?
Install commands:
# REPLACE: Commands to install
Run commands:
# REPLACE: Commands to run
=== PROJECT STRUCTURE (optional) ===
# OPTION 1 - Reference actual structure:
# See tree output of project, or reference @package.json
# OPTION 2 - Describe structure:
# REPLACE: Key folders and their purpose
=== GENERATE README WITH ===
1. Project title with badges (build, coverage, npm version, license)
2. Screenshots/GIF demo (placeholder)
3. Quick start (3 commands to get running)
4. Detailed installation
5. Usage examples with code
6. Configuration options (table format)
7. API reference (if applicable)
8. Roadmap (what's planned)
9. Contributing guidelines
10. License and acknowledgments
Generate Documentation for Existing Code
Use this to add documentation to an undocumented codebase.
Add comprehensive documentation to this code.
=== CODE ===
# OPTION 1 - Reference file:
# See @src/utils/parser.ts
# OPTION 2 - Paste code:
# REPLACE: Paste your undocumented code
=== DOCUMENTATION STYLE ===
Format: [JSDoc / TSDoc / Python docstrings / Javadoc / Go doc comments]
=== REQUIREMENTS ===
- Document every public function/method/class
- Include: description, parameters, return value, exceptions
- Add usage examples for complex functions
- Note any non-obvious behavior or edge cases
- Add inline comments for tricky logic
=== OUTPUT FORMAT ===
Return the complete code with documentation added.
Keep the code unchanged, only add documentation.
Document Multiple Related Files
Use this to document a module or feature spanning multiple files.
Document this module/feature that spans multiple files.
=== FILES ===
# OPTION 1 - Reference files:
# @src/auth/index.ts - Main exports
# @src/auth/login.ts - Login functionality
# @src/auth/register.ts - Registration
# @src/auth/types.ts - Type definitions
# OPTION 2 - Paste files with headers:
# --- File: src/auth/index.ts ---
# REPLACE: Paste code
=== GENERATE ===
1. JSDoc/docstrings for each function
2. A README.md for the folder explaining:
- What this module does
- How files relate to each other
- Usage examples
- Public API reference
- Configuration options
Generate API Documentation
Use this to create API reference documentation.
Generate API documentation for these endpoints.
=== ENDPOINTS ===
# OPTION 1 - Reference files:
# See @src/api/*.ts
# OPTION 2 - Describe or paste:
# REPLACE: List endpoints or paste route handler code
=== FORMAT ===
Output format: [Markdown / OpenAPI 3.0 / Both]
=== GENERATE DOCUMENTATION WITH ===
For each endpoint:
1. HTTP method and path
2. Description (what it does)
3. Authentication requirements
4. Request:
- Headers (table)
- Path parameters (table)
- Query parameters (table)
- Request body (JSON example with descriptions)
5. Response:
- Success response (JSON example)
- Error responses (code, message, when it occurs)
6. Example request (curl command)
7. Example response
Generate Technical Decision Record (ADR)
Use this to document architectural decisions.
Create an Architecture Decision Record (ADR).
=== THE DECISION ===
# REPLACE: What did you decide?
# Example: Use PostgreSQL instead of MongoDB for user data
=== CONTEXT ===
# REPLACE: What problem were you solving? What constraints existed?
=== OPTIONS CONSIDERED ===
# REPLACE: What alternatives did you evaluate?
=== RELATED CODE (optional) ===
# Reference files affected by this decision:
# This decision affects @src/db/* and @prisma/schema.prisma
=== GENERATE ADR ===
# ADR-[NUMBER]: [TITLE]
## Status
[Proposed / Accepted / Deprecated / Superseded]
## Date
[YYYY-MM-DD]
## Context
(problem and constraints)
## Decision
(what we decided)
## Consequences
### Positive
### Negative
### Risks
## Alternatives Considered
(options and why rejected)
## References
(links to related docs, issues, discussions)
Testing Prompts
Generate Unit Tests
Use this to generate comprehensive tests for existing code.
Generate unit tests for this code.
=== CODE TO TEST ===
# OPTION 1 - Reference file:
# See @src/utils/validation.ts
# OPTION 2 - Paste code:
# REPLACE: Paste the function/class to test
=== TESTING REQUIREMENTS ===
Framework: [Jest / Vitest / pytest / JUnit / Go testing / Mocha]
Mocking library: [jest.mock / vitest mock / unittest.mock / Mockito / none]
Coverage goal: [line coverage %, branch coverage %]
=== WHAT TO TEST ===
- [ ] Happy path (normal inputs)
- [ ] Edge cases (empty, null, boundary values, zero, negative)
- [ ] Error cases (invalid inputs, exceptions)
- [ ] Async behavior (if applicable)
- [ ] Type checking (TypeScript)
=== GENERATE ===
10+ test cases covering all scenarios.
Each test should have:
- Descriptive name explaining what it tests
- Arrange / Act / Assert structure
- Comments for complex test logic
- Mock setup where needed
Generate Integration Tests
Use this for testing multiple components together.
Generate integration tests.
=== WHAT TO TEST ===
# REPLACE: Describe the integration scenario
# Example: Test user registration flow from API to database
=== COMPONENTS INVOLVED ===
# REPLACE: List components/files involved
# - @src/api/users.ts - API routes
# - @src/services/userService.ts - Business logic
# - @src/db/userRepository.ts - Database
=== TEST SCENARIOS ===
# REPLACE: List specific scenarios
# 1. Successful registration creates user in database
# 2. Duplicate email returns 409 error
# 3. Invalid input returns 400 with validation errors
=== TECH STACK ===
Framework: [Jest / pytest / Go testing]
Database: [PostgreSQL / MongoDB / SQLite in-memory]
HTTP testing: [supertest / httpx / net/http]
=== GENERATE ===
1. Test setup (database, test server)
2. Test teardown (cleanup)
3. Tests for each scenario
4. Helper functions for common operations
5. Mock external services (email, payments)
Generate E2E Test Scenarios
Use this for end-to-end testing with Playwright, Cypress, etc.
Generate E2E test scenarios.
=== FEATURE TO TEST ===
# REPLACE: Describe the user flow to test
# Example: User login β dashboard β create project β invite team member
=== PAGES/COMPONENTS INVOLVED ===
# REPLACE: List URLs and key elements
# - /login - email input, password input, submit button
# - /dashboard - project list, create button
# - /projects/new - project form
# - /projects/:id/team - invite button, email input
=== TEST FRAMEWORK ===
Framework: [Playwright / Cypress / Selenium]
=== GENERATE ===
1. Page object models / selectors
2. Test scenarios:
- Happy path (complete flow)
- Error cases (invalid input, network failure)
- Edge cases (empty states, permissions)
3. Test data setup
4. Assertions for each step
5. Screenshot/video capture on failure
Generate Tests for Existing Code Files
Use this when you want to add tests to an existing file.
Generate a test file for this existing code.
=== CODE FILE ===
# OPTION 1 - Reference:
# See @src/services/userService.ts
# OPTION 2 - Paste:
# REPLACE: Paste the code
=== DEPENDENCIES (optional) ===
# List what needs mocking:
# - @src/db/userRepository.ts - database calls
# - @src/services/emailService.ts - email sending
=== TEST FILE LOCATION ===
# Where should tests go?
# REPLACE: e.g., @src/services/__tests__/userService.test.ts
=== GENERATE ===
A complete test file that:
1. Imports the code under test correctly
2. Mocks external dependencies
3. Tests all public methods
4. Includes setup/teardown as needed
5. Aims for high coverage (line + branch)
Refactoring Prompts
Clean Up Messy Code
Use this to improve code readability and maintainability.
Refactor this code to improve readability and maintainability.
=== CODE TO REFACTOR ===
# OPTION 1 - Reference file:
# See @src/utils/legacy-parser.ts
# OPTION 2 - Paste code:
# REPLACE: Paste your messy code
=== WHAT'S WRONG (optional) ===
# REPLACE: What bothers you about this code?
# - Too many nested if statements
# - Function too long (>50 lines)
# - Unclear variable names
# - Duplicated logic
=== CONSTRAINTS ===
- Keep the same function signature (API must not change)
- Language: [JavaScript / TypeScript / Python / etc.]
- Target audience: [junior dev readable / senior code is fine]
=== REFACTORING GOALS ===
Priority 1: [Readability / Performance / Testability / Type Safety]
Priority 2: [Readability / Performance / Testability / Type Safety]
=== OUTPUT ===
1. Refactored code
2. List of changes made and why
3. Any tradeoffs introduced
4. Before/after comparison for the most significant change
Modernize Legacy Code
Use this to update old code patterns to modern standards.
Modernize this legacy code to current best practices.
=== LEGACY CODE ===
# OPTION 1 - Reference files:
# See @src/legacy/oldModule.js
# OPTION 2 - Paste code:
# REPLACE: Paste your old code
=== CURRENT TECH ===
From:
# REPLACE: e.g., ES5 JavaScript, Python 2, Java 8
To:
# REPLACE: e.g., ES2023, Python 3.12, Java 21
=== MODERNIZATION GOALS ===
# Check what applies:
# - [ ] Update syntax (var β const/let, callbacks β async/await)
# - [ ] Apply modern patterns (hooks, composition)
# - [ ] Improve type safety (add TypeScript)
# - [ ] Use newer language features (optional chaining, nullish coalescing)
# - [ ] Update deprecated APIs
# - [ ] Improve error handling
=== CONSTRAINTS ===
- Must maintain same external behavior
- Breaking changes allowed: [Yes / No]
=== OUTPUT ===
1. Modernized code
2. Complete list of changes
3. Breaking changes to be aware of
4. Migration guide for consumers
Apply Design Pattern
Use this to restructure code with design patterns.
Apply a design pattern to improve this code.
=== CURRENT CODE ===
# REPLACE: Paste your code or reference file
=== THE PROBLEM ===
# REPLACE: What's wrong with the current structure?
# Example:
# - Giant switch statement that keeps growing
# - Hard to test due to tight coupling
# - New requirements keep breaking existing code
=== SUGGESTED PATTERN (or let AI suggest) ===
Pattern: [Strategy / Factory / Observer / Decorator / Repository / Adapter / Let AI recommend]
=== REQUIREMENTS ===
Language: [JavaScript / TypeScript / Python / Java / Go]
Keep it simple: [Yes - readable by juniors / No - full pattern is fine]
=== OUTPUT ===
1. Refactored code using the pattern
2. Diagram/explanation of the new structure
3. How the pattern solves the problem
4. How to extend this in the future
5. Trade-offs of this approach
Refactor for Testability
Use this when code is hard to test.
Refactor this code to make it more testable.
=== CODE ===
# OPTION 1 - Reference file:
# See @src/services/orderService.ts
# OPTION 2 - Paste code:
# REPLACE: Paste hard-to-test code
=== TESTING CHALLENGES ===
# REPLACE: Why is this hard to test?
# Example:
# - Has hardcoded database calls
# - Uses singleton that can't be mocked
# - Has side effects in constructor
# - Depends on global state
# - Makes network calls directly
=== GENERATE ===
1. Refactored code with dependency injection
2. Explain what was changed for testability
3. Interface/type definitions for dependencies
4. Example test showing how to mock dependencies
5. Before/after test complexity comparison
Performance Prompts
Optimize Slow Code
Use this when code is running slower than expected.
Optimize this code for better performance.
=== SLOW CODE ===
# REPLACE: Paste your code or reference file
=== PERFORMANCE ISSUE ===
# REPLACE: Describe the problem
# - Current exec time: X seconds/ms
# - Expected exec time: Y seconds/ms
# - Input size: N items
=== CONSTRAINTS ===
- Memory limit: [unlimited / limited to X MB]
- Can change algorithm: [Yes / No]
- Can change data structure: [Yes / No]
- Can add caching: [Yes / No]
- Must maintain readability: [Yes / No]
=== GENERATE ===
1. Optimized code
2. Explanation of each optimization
3. Time complexity before/after
4. Space complexity before/after
5. Benchmark code to measure improvement
Find Performance Bottlenecks
Use this to identify whatβs making code slow.
Analyze this code for performance bottlenecks.
=== CODE ===
# REPLACE: Paste your code or reference multiple files
=== CONTEXT ===
- Current performance:
# REPLACE: e.g., API takes 3 seconds to respond
- Expected performance:
# REPLACE: e.g., Should be under 200ms
- Scale:
# REPLACE: e.g., 10K concurrent users, 1M database rows
=== ANALYZE FOR ===
1. Algorithm complexity issues (O(nΒ²) or worse)
2. Database query problems (N+1, missing indexes, full scans)
3. Memory issues (large objects, memory leaks)
4. I/O bottlenecks (blocking calls, no batching)
5. Caching opportunities (repeated computation)
6. Network issues (too many requests, no parallelization)
=== GENERATE ===
For each bottleneck found:
- Location (file, line, function)
- Why it's slow
- Expected impact (high/medium/low)
- Solution with code
- Estimated improvement
Optimize Database Queries
Use this for slow database operations.
Optimize these database queries.
=== SLOW QUERIES ===
# REPLACE: Paste your SQL or ORM queries
=== CURRENT PERFORMANCE ===
# REPLACE: Execution time, rows scanned
# - Query takes 5 seconds
# - Scans 1M rows
=== SCHEMA ===
# REPLACE: Relevant tables and existing indexes
# - users (id PK, email, name, created_at)
# - orders (id PK, user_id FK, total, created_at)
# Indexes: users(email), orders(user_id)
=== DATABASE ===
Type: [PostgreSQL / MySQL / MongoDB]
=== GENERATE ===
1. Optimized queries
2. Recommended indexes (CREATE INDEX statements)
3. Query plan analysis (EXPLAIN)
4. Caching strategy (if applicable)
5. Pagination/batching for large results
Architecture Prompts
Design System Architecture
Use this when designing a new system or feature.
Help me design the architecture for this system.
=== REQUIREMENTS ===
# REPLACE: What does the system need to do?
# - Handle user registration and authentication
# - Process payments
# - Send email notifications
# - Generate reports
=== SCALE REQUIREMENTS ===
# REPLACE: Expected load
# - Users: 100K daily active
# - Requests: 1000/second peak
# - Data: 10TB
=== CONSTRAINTS ===
# REPLACE: Limitations
# - Budget: [startup / medium / enterprise]
# - Team size: X developers
# - Timeline: X months
# - Existing tech: [list any required technologies]
=== GENERATE ===
1. High-level architecture diagram (as text/ASCII)
2. Component breakdown:
- Services/modules
- Databases
- Message queues
- Caches
- External services
3. Data flow explanation
4. Technology recommendations for each component
5. Scalability considerations
6. Security considerations
7. Cost estimates (rough)
Review Architecture Decision
Use this to evaluate an architectural choice.
Review this architecture decision.
=== THE DECISION ===
# REPLACE: What was decided?
# Example: Use microservices instead of monolith
=== CONTEXT ===
# REPLACE: Why was this considered?
# - Current system is monolith with 500K LOC
# - Deployments take 2 hours
# - 5 teams working on same codebase
=== PROPOSED ARCHITECTURE ===
# REPLACE: Describe or diagram the proposed solution
=== CONCERNS ===
# REPLACE: What are you worried about?
# - Increased complexity
# - Data consistency across services
# - Team skillset
=== REVIEW FOR ===
1. Does this solve the stated problems?
2. What new problems does this introduce?
3. Is the complexity justified?
4. Alternative approaches
5. Migration path from current state
6. Team/skill requirements
7. Cost implications
8. Recommendation: Proceed / Modify / Reconsider
Choose Tech Stack
Use this when selecting technologies for a new project.
Help me choose the right tech stack.
=== PROJECT REQUIREMENTS ===
# REPLACE: What are you building?
# - Web application for [purpose]
# - Mobile app for [purpose]
# - API for [purpose]
=== FUNCTIONAL REQUIREMENTS ===
# REPLACE: Key features
# - Real-time updates
# - File uploads
# - Payment processing
# - Search functionality
=== NON-FUNCTIONAL REQUIREMENTS ===
# REPLACE: Quality attributes
# - Performance: X requests/second
# - Availability: 99.X%
# - Users: X concurrent
# - Data: X size
=== CONSTRAINTS ===
# REPLACE: Limitations
# - Team expertise: [languages, frameworks team knows]
# - Budget: [startup / medium / enterprise]
# - Timeline: [X months]
# - Hosting: [cloud / on-premise / specific provider]
=== GENERATE ===
1. Recommended stack with justification:
- Frontend
- Backend
- Database
- Cache
- Queue
- Search
- Hosting/infrastructure
2. Alternative options for each layer
3. Trade-offs of recommendations
4. Learning curve estimate
5. Example architecture diagram
6. Estimated costs
Learning Prompts
Explain This Code
Use this when you encounter unfamiliar code.
Explain this code to me like I'm learning.
=== CODE ===
# REPLACE: Paste the code you don't understand
=== MY BACKGROUND ===
# REPLACE: What do you already know?
# - I know JavaScript but not TypeScript
# - I'm new to this framework
# - I understand the basics but not advanced patterns
=== WHAT CONFUSES ME ===
# REPLACE: Specific parts you don't get (or "everything")
=== EXPLAIN ===
1. What does this code do overall? (2-3 sentences)
2. Line-by-line explanation with comments
3. Why was it written this way? (design decisions)
4. Key concepts/patterns used
5. How would you modify it for [common use case]?
6. Related resources to learn more
Compare Approaches
Use this when deciding between implementation options.
Compare these different approaches.
=== WHAT I'M TRYING TO DO ===
# REPLACE: Describe the goal
=== APPROACH 1 ===
# REPLACE: First option (code or description)
=== APPROACH 2 ===
# REPLACE: Second option (code or description)
=== APPROACH 3 (optional) ===
# REPLACE: Third option
=== COMPARE ON ===
- Performance (speed, memory)
- Readability/maintainability
- Testability
- Scalability
- Error handling
- Best practices
- Team familiarity
=== GENERATE ===
Comparison table:
| Aspect | Approach 1 | Approach 2 | Approach 3 |
|--------|------------|------------|------------|
Then: recommendation with reasoning
Teach Me About
Use this to learn a new concept with code examples.
Teach me about [TOPIC] with practical code examples.
=== TOPIC ===
# REPLACE: What do you want to learn?
# Example: React useEffect hook, Python decorators, SQL window functions
=== MY LEVEL ===
# REPLACE: Your experience level
# - Beginner (new to programming)
# - Intermediate (know the basics, learning advanced)
# - Experienced (know related concepts, this is new)
=== LANGUAGE/FRAMEWORK ===
# REPLACE: What tech context
# - JavaScript/TypeScript
# - Python
# - etc.
=== GENERATE ===
1. Simple explanation (ELI5)
2. When to use this (real scenarios)
3. Basic example with comments
4. Intermediate example
5. Common mistakes to avoid
6. Best practices
7. Practice exercises
8. Resources for further learning
Git & Collaboration Prompts
Write Commit Message
Use this to generate proper conventional commit messages.
Write a commit message for these changes.
=== FILES CHANGED ===
# OPTION 1 - Reference files:
# @src/components/Button.tsx (modified)
# @src/components/Modal.tsx (new)
# @src/hooks/useAuth.ts (deleted)
# OPTION 2 - Describe changes:
# REPLACE: List files that changed
=== WHAT CHANGED ===
# REPLACE: Describe what you did
=== WHY ===
# REPLACE: Why was this change needed?
=== BREAKING CHANGES ===
# REPLACE: Any breaking changes? (or "None")
=== GENERATE ===
Conventional Commits format:
type(scope): subject
body (what and why)
footer (breaking changes, issue refs)
Types: feat, fix, docs, style, refactor, perf, test, build, ci, chore
Write PR Description
Use this to create a comprehensive pull request description.
Write a pull request description.
=== TITLE ===
# REPLACE: Brief title
=== CHANGES ===
# OPTION 1 - Reference files:
# See changes in:
# @src/api/users.ts
# @src/services/userService.ts
# OPTION 2 - Describe:
# REPLACE: What changed
=== WHY ===
# REPLACE: Why is this change needed? Link to issue if applicable.
=== TESTING DONE ===
# REPLACE: How did you test this?
=== SCREENSHOTS (if UI) ===
# REPLACE: Describe what screenshots should show
=== GENERATE ===
## Summary
(1-2 sentence overview)
## Problem
(What issue does this solve?)
## Solution
(How does this PR solve it?)
## Changes Made
- (itemized list)
## Type of Change
- [ ] Bug fix
- [ ] New feature
- [ ] Breaking change
- [ ] Documentation
- [ ] Refactor
- [ ] Performance
## Testing
- (how you tested)
- (how reviewer can test)
## Screenshots
(if applicable)
## Checklist
- [ ] Self-reviewed
- [ ] Tests added/updated
- [ ] Docs updated
- [ ] No console.log statements
- [ ] TypeScript types added
## Related Issues
Fixes #(issue number)
Generate Branch Naming
Use this to create consistent branch names.
Generate a branch name for this work.
=== WORK DESCRIPTION ===
# REPLACE: What are you working on?
=== TICKET/ISSUE ID ===
# REPLACE: e.g., JIRA-123, #456
=== BRANCH NAMING CONVENTION ===
# REPLACE: Your team's convention, or use standard:
# type/ticket-short-description
# Types: feature, bugfix, hotfix, refactor, docs, test, chore
=== GENERATE ===
3 branch name options following the convention
Workflow Chains
These are multi-step prompts for complete development tasks.
Workflow: Feature Development
Use this chain for implementing a new feature end-to-end.
WORKFLOW: Complete Feature Development
Follow these steps in order. After each step, I'll review and say "next" to continue.
=== FEATURE ===
# REPLACE: What feature are you building?
=== TECH STACK ===
# REPLACE: Languages, frameworks, etc.
---
STEP 1: Design & Plan
- Break down into tasks
- Identify files to create/modify
- Note any dependencies
---
STEP 2: Generate Types/Interfaces
- Create TypeScript interfaces
- Define data models
- API request/response types
---
STEP 3: Implement Core Logic
- Business logic functions
- Service layer code
- With proper error handling
---
STEP 4: Implement API/UI
- API endpoints OR React components
- Input validation
- Error states
---
STEP 5: Write Tests
- Unit tests for logic
- Integration tests for API
- Component tests for UI
---
STEP 6: Add Documentation
- JSDoc comments
- README updates
- API docs if applicable
---
STEP 7: Review Checklist
- Security review
- Performance review
- Accessibility review
- Code quality review
Start with STEP 1.
Workflow: Bug Fix
Use this chain for systematically fixing bugs.
WORKFLOW: Bug Fix Process
Follow these steps. After each step, I'll provide information and say "next".
=== BUG DESCRIPTION ===
# REPLACE: What's the bug?
=== REPRODUCTION STEPS ===
# REPLACE: How to reproduce
---
STEP 1: Understand & Reproduce
- Confirm reproduction steps
- Identify affected code
- Create a failing test
---
STEP 2: Root Cause Analysis
- Trace through code
- Identify exact cause
- Understand why it happens
---
STEP 3: Develop Fix
- Implement the fix
- Minimal changes needed
- No side effects
---
STEP 4: Test Fix
- Verify failing test passes
- Add regression tests
- Test edge cases
---
STEP 5: Documentation
- Write commit message
- Update docs if needed
- Close related issues
Start with STEP 1.
Quick Reference
| Need | Prompt to Use |
|---|---|
| Code Review | |
| Review code for issues | General Code Review |
| Security vulnerabilities | Security-Focused Review |
| Performance issues | Performance-Focused Review |
| Accessibility issues | Accessibility Review |
| Review a PR | Pull Request Review |
| Review feature across files | Review Multiple Files |
| Debugging | |
| Fix an error | Debug an Error Message |
| Code runs wrong | Debug: Code Not Working |
| Bug spans files | Debug Across Multiple Files |
| Timing/async bugs | Debug: Async Issues |
| Performance slow | Debug Performance Bottleneck |
| Memory issues | Debug Memory Leaks |
| Code Generation | |
| Create a function | Generate Function with Tests |
| Build API endpoint | Generate REST API Endpoint |
| Create React component | Generate React Component |
| Generate types | Generate TypeScript Types |
| Database work | Generate Schema and Queries |
| SQL query | Generate SQL Query |
| Add to existing code | Extend Existing Code |
| Documentation | |
| Create README | Generate README.md |
| Document code | Generate Documentation |
| Document a module | Document Multiple Files |
| API documentation | Generate API Documentation |
| Record decision | Generate ADR |
| Testing | |
| Write unit tests | Generate Unit Tests |
| Integration tests | Generate Integration Tests |
| E2E tests | Generate E2E Test Scenarios |
| Test existing file | Generate Tests for Existing Code |
| Refactoring | |
| Clean up code | Clean Up Messy Code |
| Update old code | Modernize Legacy Code |
| Apply pattern | Apply Design Pattern |
| Make code testable | Refactor for Testability |
| Performance | |
| Optimize code | Optimize Slow Code |
| Find bottlenecks | Find Performance Bottlenecks |
| Optimize queries | Optimize Database Queries |
| Architecture | |
| Design system | Design System Architecture |
| Evaluate decision | Review Architecture Decision |
| Pick technologies | Choose Tech Stack |
| Learning | |
| Understand code | Explain This Code |
| Compare options | Compare Approaches |
| Learn concept | Teach Me About |
| Git | |
| Commit message | Write Commit Message |
| PR description | Write PR Description |
| Branch name | Generate Branch Naming |
Tips for Better Results
1. Reference Files When Possible
Tools like Cursor and Copilot Chat can read your files directly.
Use @filename instead of pasting when you can.
2. Be Specific About Context
β "Review this code"
β
"Review this TypeScript Express.js middleware in @src/auth/validate.ts
that validates JWT tokens. Focus on security and error handling."
3. Include Related Files
"See @src/types/user.ts for type definitions used in this code"
"See @src/utils/errors.ts for error handling patterns we use"
4. Specify Output Format
"For each bug found, show: 1) the line, 2) why it's wrong, 3) the fix"
"Output as a markdown table with columns: Issue, Severity, Fix"
5. Include Constraints
"Must be backward compatible"
"Cannot change the public API"
"Should work with Node 18+"
"Must run in under 100ms for 10K items"
6. Iterate Effectively
First response not perfect? Be specific about what to change:
"Good, but also handle the case where items array is empty"
"The tests are good, add one more for concurrent access"
"Make the code more readable - extract the validation logic into a separate function"
7. Ask for Explanations
"Explain why you chose this approach"
"What are the tradeoffs of this solution?"
"What would you do differently at 10x scale?"
Whatβs Next
- π AI Prompts for Product Managers β PRDs, user stories, roadmaps
- π Advanced Prompt Engineering β Chain-of-thought, few-shot, and more
- π Prompt Engineering Fundamentals β Start with the basics
- π οΈ PRD Generator Tool β Generate product requirements with AI
- π οΈ Test Case Generator β Requirements to test cases
Found these prompts helpful? Share them with your engineering team!