AI coding prompts work best when they include context, specific requirements, and output format. This library contains 50+ battle-tested prompts for feature development, refactoring, testing, and more - ready to copy into Claude, ChatGPT, or Cursor.

Prompt Library

AI Coding Prompts: 50+ Copy-Paste Templates for Developers

Stop writing prompts from scratch. This library contains production-ready AI coding prompts organized by task type. Each template includes context placeholders, clear instructions, and output format specifications. Copy, customize with your details, and get better results immediately.

50+
Prompts
7
Categories
100%
Copy-Paste Ready
All
AI Models
๐Ÿš€ Feature Development 12 prompts
๐Ÿ”ง Refactoring 8 prompts
๐Ÿงช Testing 8 prompts
๐Ÿ“ Documentation 6 prompts
๐Ÿ‘€ Code Review 6 prompts
๐Ÿ› Debugging 6 prompts
โšก Performance 4 prompts

Feature Development Prompts

Prompts for building new features from scratch or extending existing functionality.

New Feature Implementation

Foundation Any Stack
Prompt
I need to implement [FEATURE_NAME] in my [FRAMEWORK] application.

## Current Setup
- Framework: [Next.js 15 / React / SvelteKit / etc.]
- Language: [TypeScript / JavaScript]
- Database: [Supabase / Prisma / MongoDB / etc.]
- Relevant files: [list key files]

## Feature Requirements
[Describe what the feature should do in 2-3 sentences]

## Acceptance Criteria
1. [Specific requirement 1]
2. [Specific requirement 2]
3. [Specific requirement 3]

## Constraints
- Must follow existing code patterns in the project
- Must include proper error handling
- Must validate user input
- No hardcoded secrets or API keys

## Expected Output
Provide the implementation with:
1. File path for each code block
2. Complete, runnable code (not snippets)
3. Brief explanation of key decisions

API Endpoint Creation

Backend REST/GraphQL
Prompt
Create a [REST/GraphQL] API endpoint for [RESOURCE_NAME].

## Endpoint Details
- Method: [GET/POST/PATCH/DELETE]
- Path: /api/[path]
- Authentication: [Required/Optional/None]

## Request
- Body/Params: [describe expected input]
- Validation rules: [list validation requirements]

## Response
- Success: [describe success response shape]
- Errors: [list error cases and response codes]

## Security Requirements
- Validate all input with Zod
- Check authentication before processing
- Use parameterized queries (no SQL injection)
- Rate limit: [X requests per minute]

## Framework
[Next.js App Router / Express / FastAPI / etc.]

Provide complete implementation with error handling and types.

React Component with State

Frontend React
Prompt
Create a React component for [COMPONENT_PURPOSE].

## Component Requirements
- Name: [ComponentName]
- Props: [list props with types]
- State: [list state variables needed]
- Events: [list events to handle]

## Behavior
[Describe how the component should behave]

## Styling
- Use [Tailwind CSS / CSS Modules / styled-components]
- Follow existing design system patterns
- Must be responsive

## Code Standards
- TypeScript with strict types
- Props interface exported
- Use functional component with hooks
- Accessible (proper ARIA labels, keyboard navigation)

## Output Format
Provide:
1. Component file with full implementation
2. Types/interfaces
3. Usage example

Form with Validation

Frontend Forms
Prompt
Create a form for [FORM_PURPOSE] with client and server validation.

## Form Fields
| Field | Type | Validation |
|-------|------|------------|
| [field1] | [text/email/number] | [required, min length, etc.] |
| [field2] | [select/checkbox] | [validation rules] |

## Behavior
- Show inline validation errors
- Disable submit while processing
- Show success/error toast on completion
- Clear form on success (optional)

## Tech Stack
- Framework: [Next.js / React / SvelteKit]
- Validation: [Zod / React Hook Form / native]
- Form library: [React Hook Form / native / etc.]

## Security
- Validate on client AND server
- CSRF protection if needed
- Sanitize inputs before database

Provide complete form component with validation schema.

Database Schema Design

Backend Database
Prompt
Design a database schema for [FEATURE/DOMAIN].

## Requirements
[Describe what data needs to be stored and relationships]

## Entities
1. [Entity1]: [brief description]
2. [Entity2]: [brief description]

## Relationships
- [Entity1] has many [Entity2]
- [etc.]

## Constraints
- Soft deletes required: [yes/no]
- Audit fields (created_at, updated_at): [yes/no]
- Multi-tenant: [yes/no]

## ORM/Database
- [Prisma / Drizzle / raw SQL]
- Database: [PostgreSQL / MySQL / MongoDB]

## Output
Provide:
1. Schema definition in [Prisma schema / SQL / etc.]
2. Indexes for common queries
3. Migration file if applicable

Refactoring Prompts

Prompts for improving existing code without changing functionality.

Extract Reusable Function

DRY Any Language
Prompt
Refactor this code to extract reusable functions:

```[language]
[paste your code here]
```

## Goals
- Identify repeated patterns
- Extract into well-named functions
- Maintain exact same behavior
- Improve readability

## Constraints
- Keep functions small (under 20 lines)
- Use descriptive names that explain purpose
- Add JSDoc/docstring comments
- Preserve all error handling

## Output
1. Refactored code with extracted functions
2. Brief explanation of what was extracted and why

Improve Code Readability

Clean Code Maintainability
Prompt
Improve the readability of this code without changing functionality:

```[language]
[paste your code here]
```

## Focus Areas
- Variable and function naming
- Code structure and flow
- Comment where logic is complex
- Remove unnecessary complexity
- Use early returns to reduce nesting

## Style Guide
[Link to your style guide or describe preferences]

## Constraints
- Must maintain exact same behavior
- Must pass existing tests
- No new dependencies

Show before/after for each change with explanation.

Convert to TypeScript

TypeScript Migration
Prompt
Convert this JavaScript code to TypeScript with strict types:

```javascript
[paste your JavaScript code here]
```

## Requirements
- Add proper types for all variables and functions
- Create interfaces for object shapes
- Use strict mode compatible types
- No 'any' types - use 'unknown' and type guards if needed
- Export types that might be reused

## Output
1. TypeScript code with full type annotations
2. Separate types/interfaces file if complex
3. Note any type decisions that need review

Modernize Legacy Code

Modernization Best Practices
Prompt
Modernize this code using current best practices:

```[language]
[paste legacy code here]
```

## Current Version
- Language/Runtime: [Node 20 / Python 3.12 / etc.]
- Framework: [if applicable]

## Modernization Goals
- Use modern syntax (async/await, optional chaining, etc.)
- Replace deprecated APIs
- Improve error handling
- Add proper typing if applicable

## Constraints
- Maintain backward compatibility with: [list any constraints]
- Must work with: [list dependencies/systems]

Provide modernized code with comments explaining major changes.

Testing Prompts

Prompts for writing comprehensive tests.

Unit Tests for Function

Unit Testing Jest/Vitest
Prompt
Write comprehensive unit tests for this function:

```[language]
[paste function code here]
```

## Test Framework
[Jest / Vitest / pytest / etc.]

## Test Coverage Requirements
- Happy path (normal inputs)
- Edge cases (empty, null, undefined)
- Error cases (invalid inputs)
- Boundary conditions

## Mocking
- External dependencies to mock: [list them]
- Database calls: [mock/use test DB]

## Output Format
```typescript
describe('[FunctionName]', () => {
  describe('when [scenario]', () => {
    it('should [expected behavior]', () => {
      // Arrange, Act, Assert
    })
  })
})
```

Integration Test for API

Integration API Testing
Prompt
Write integration tests for this API endpoint:

## Endpoint
- Method: [GET/POST/etc.]
- Path: [/api/...]
- Auth: [required/optional]

## Code
```[language]
[paste endpoint code here]
```

## Test Cases
1. Successful request with valid data
2. Authentication failure (401)
3. Validation errors (400)
4. Not found cases (404)
5. Server errors (500)

## Test Framework
[Supertest / httpx / etc.]

## Database
- Use test database or mock
- Clean up after tests

Provide complete test file with setup and teardown.

E2E Test for User Flow

E2E Playwright
Prompt
Write E2E tests for this user flow:

## User Flow
1. [Step 1: User action]
2. [Step 2: Expected result]
3. [Step 3: Next action]
...

## Test Framework
[Playwright / Cypress]

## Page Elements
- Login form: [selectors if known]
- Key buttons: [selectors]

## Test Scenarios
- Happy path (complete flow)
- Error handling (invalid inputs)
- Edge cases (network errors, timeouts)

## Best Practices
- Use page object pattern
- Wait for elements properly (no arbitrary sleeps)
- Clean test data after each test

Provide complete test file with page objects if complex.

Documentation Prompts

Prompts for generating documentation, comments, and README files.

Function Documentation

JSDoc/Docstring API Docs
Prompt
Add comprehensive documentation to this code:

```[language]
[paste code here]
```

## Documentation Style
[JSDoc / TSDoc / Python docstrings / etc.]

## Include
- Function/method description
- Parameter descriptions with types
- Return value description
- Throws/raises documentation
- Example usage
- Edge cases or gotchas

## Output
Code with inline documentation added.

README Generator

README Project Docs
Prompt
Generate a README.md for this project:

## Project Info
- Name: [project name]
- Purpose: [one sentence description]
- Tech Stack: [list technologies]

## Key Features
1. [Feature 1]
2. [Feature 2]
3. [Feature 3]

## Include Sections
- Project description
- Installation instructions
- Environment variables needed
- Usage examples
- API documentation (if applicable)
- Contributing guidelines
- License

## Tone
[Professional / Casual / Technical]

Generate complete README in markdown format.

API Documentation

API Docs OpenAPI
Prompt
Generate API documentation for these endpoints:

```[language]
[paste API route code here]
```

## Format
[OpenAPI/Swagger / Markdown / etc.]

## Include
- Endpoint path and method
- Request parameters/body with types
- Response schemas for success and errors
- Authentication requirements
- Example requests and responses
- Rate limiting info

## Output
Complete API documentation in specified format.

Code Review Prompts

Prompts for reviewing code quality, security, and best practices.

Security Review

Security Critical
Prompt
Review this code for security vulnerabilities:

```[language]
[paste code here]
```

## Check For
- SQL/NoSQL injection
- XSS vulnerabilities
- Missing authentication/authorization
- Hardcoded secrets
- Input validation issues
- CSRF vulnerabilities
- Insecure direct object references
- Path traversal
- Command injection

## Output Format
For each issue found:
1. Severity (Critical/High/Medium/Low)
2. Location (line number)
3. Description of vulnerability
4. Recommended fix with code example

Also note: "No issues found" for categories that pass.

Performance Review

Performance Optimization
Prompt
Review this code for performance issues:

```[language]
[paste code here]
```

## Context
- Expected load: [requests per second / data volume]
- Current issues: [if any known]

## Check For
- N+1 queries
- Missing indexes
- Unnecessary re-renders (React)
- Memory leaks
- Inefficient algorithms
- Missing caching opportunities
- Blocking operations
- Large bundle sizes

## Output
For each issue:
1. Impact (High/Medium/Low)
2. Location and description
3. Recommended optimization with code

General Code Review

Quality Best Practices
Prompt
Review this code as a senior developer would:

```[language]
[paste code here]
```

## Review Areas
- Code correctness
- Error handling
- Edge cases
- Naming and readability
- DRY violations
- SOLID principles
- Testing considerations
- Documentation needs

## Style Guide
[Link or describe your conventions]

## Output
Structured review with:
1. Summary (approve / request changes)
2. Critical issues (must fix)
3. Suggestions (nice to have)
4. Positive observations (what's done well)

Debugging Prompts

Prompts for diagnosing and fixing bugs. See also: Debugging Prompts Library

Debug Error Message

Error Analysis Quick Fix
Prompt
Help me debug this error:

## Error Message
```
[paste full error message and stack trace]
```

## Code That Caused It
```[language]
[paste relevant code]
```

## Context
- When it happens: [always / sometimes / specific conditions]
- Recent changes: [what changed before error started]
- Environment: [dev / prod / specific browser]

## What I've Tried
1. [attempt 1]
2. [attempt 2]

Explain the root cause and provide a fix.

Fix Failing Test

Testing Debug
Prompt
Help me fix this failing test:

## Test Code
```[language]
[paste test code]
```

## Code Being Tested
```[language]
[paste implementation code]
```

## Test Output
```
[paste test failure output]
```

## Question
Is the test wrong or the implementation wrong?
Provide the fix for whichever needs to change.

Performance Prompts

Prompts for optimizing code performance.

Optimize Database Query

Database SQL
Prompt
Optimize this database query:

## Current Query
```sql
[paste query or ORM code]
```

## Schema (relevant tables)
```sql
[paste table definitions]
```

## Current Performance
- Execution time: [X ms]
- Rows scanned: [if known]

## Expected Load
- Frequency: [X queries per second]
- Data size: [X rows in table]

## Provide
1. Optimized query
2. Suggested indexes
3. Explanation of improvements

Reduce Bundle Size

Frontend Build
Prompt
Help reduce the bundle size of this component/page:

## Code
```[language]
[paste component code]
```

## Current Bundle Analysis
[paste output from bundle analyzer if available]

## Framework
[Next.js / Vite / webpack]

## Optimization Goals
- Current size: [X KB]
- Target size: [Y KB]

## Provide
1. Code changes for smaller bundle
2. Dynamic import opportunities
3. Dependencies to replace or remove
4. Tree-shaking improvements

How to Use These Prompts

1

Copy the template

Find the prompt that matches your task and copy it to your clipboard.

2

Fill in the brackets

Replace all [PLACEHOLDER] text with your specific details. Include actual code, file paths, and requirements.

3

Add context

If your codebase has specific patterns or constraints, mention them. More context = better results.

4

Iterate as needed

If the output isn't right, ask for specific changes rather than starting over. Chain prompts for complex tasks.

Frequently Asked Questions

What makes a good AI coding prompt?

Good AI coding prompts have four elements: (1) Clear context about your codebase, (2) Specific task description, (3) Constraints and requirements, (4) Expected output format. Vague prompts get vague results. The templates in this guide include all four elements.

Should I use different prompts for Claude vs ChatGPT?

The core prompts work across models, but Claude handles longer context and structured outputs better, while ChatGPT excels at creative solutions. Claude prefers XML tags for structure. ChatGPT responds well to role-playing ("Act as a senior developer"). Adjust based on results.

How do I get AI to follow my coding standards?

Include your standards directly in the prompt or reference a style guide. Show examples of your preferred patterns. For Cursor, use .cursorrules to enforce standards automatically. For Claude Code, use CLAUDE.md. The prompt templates include placeholders for your conventions.

Why does AI sometimes ignore my prompt instructions?

Three common causes: (1) Prompt is too long - models lose focus after ~2000 words, (2) Conflicting instructions - simplify and prioritize, (3) Asking for too much at once - break into smaller prompts. Use the focused templates in this guide to avoid these issues.

How do I prompt AI to write secure code?

Explicitly state security requirements: "Use parameterized queries, validate all inputs, never hardcode secrets." Include security constraints in every prompt. Better yet, use our security-prompts library which has pre-built security-focused templates.

Can I chain multiple AI prompts together?

Yes, prompt chaining is powerful for complex tasks. Example flow: (1) Analyze existing code, (2) Plan the changes, (3) Implement changes, (4) Write tests, (5) Review for issues. Each prompt builds on the previous output. The templates include chaining suggestions.

Related Content