The quality of your AI output is directly proportional to the quality of your prompts. Vague prompts produce vague results; specific, contextual prompts with clear output format requirements produce production-ready outputs. This resource provides proven, tested prompts for code review, debugging, generation, testing, documentation, and architecture.
On this page
How to Write Effective Prompts
- 1
Provide context
Tell the AI: what language/framework you are using, what the code does, what constraints exist, and what you are trying to achieve. "Fix this React bug" is weak. "Fix this React 18 Server Component — it needs to fetch from an API route and handle loading states with Suspense, Next.js 14 App Router" is much stronger.
- 2
Specify output format
Tell the AI exactly what format you want: "Return only the TypeScript function, no explanation", or "Explain the change first, then provide the full modified file".
- 3
Provide the full context
Paste the relevant code, error messages, types, and interfaces. AI works best with complete context — don't make it guess at your data structures.
- 4
Use role framing
Start with: "You are a senior [language] engineer specialising in [domain]..." to prime the model for expert-level responses.
- 5
Iterate and refine
"That's good, but now also add error handling for network failures and ensure it respects the GDPR logging requirements we discussed." AI conversations are iterative — build on previous output.
Code Review Prompts
- "You are a senior security engineer. Review this code for OWASP Top 10 vulnerabilities, with particular attention to SQL injection, XSS, and insecure authentication. Provide specific line references and remediation examples."
- "Review this TypeScript code for type safety issues. Identify any use of 'any', weak type assertions, missing null checks, or cases where stricter typing would prevent runtime errors."
- "Analyse this code for performance bottlenecks in a Node.js production environment. Consider: blocking event loop operations, N+1 queries, unnecessary synchronous operations, and memory leaks."
- "Review this React component for accessibility issues. Check for: missing ARIA labels, keyboard navigation, colour contrast, focus management, and screen reader compatibility."
- "Review this code against our coding standards: [paste your team standards]. Flag any violations and suggest compliant alternatives."
- "Identify any anti-patterns, code smells, or maintenance concerns in this code. Focus on: tight coupling, missing abstractions, duplicated logic, and unclear naming."
Debugging Prompts
- "Here is a stack trace from my Next.js 14 App Router application: [paste stack trace]. The error occurs when [describe trigger]. The relevant code is: [paste code]. What is the most likely cause and how do I fix it?"
- "This TypeScript function works correctly in isolation but fails in production with [error message]. Here is the function: [code]. What edge cases or environment differences could cause this?"
- "I have a React state update problem: [describe symptoms]. My current code: [paste]. Why might this cause stale state and what is the correct pattern?"
- "My database query is taking 8 seconds on a table with 500,000 rows. Here is the query: [paste SQL]. Here is the EXPLAIN output: [paste]. How do I optimise it?"
- "I'm getting a race condition in this async Node.js code: [paste code]. Identify exactly where the race condition occurs and provide a thread-safe implementation."
Code Generation Prompts
- "Write a TypeScript Zod schema for validating this API request body: [paste example JSON]. Include: type inference export, sensible validation rules, and meaningful error messages for each field."
- "Create a reusable React Server Component for [describe component]. Requirements: [list requirements]. Use Tailwind CSS, lucide-react for icons. Follow Next.js 14 App Router patterns. TypeScript throughout."
- "Write a PostgreSQL migration (SQL) to add [describe change] to this schema: [current schema]. Include: up migration, down migration, and add appropriate indexes."
- "Generate a comprehensive Prisma schema for a [describe domain] application. Include: all required models, relationships, appropriate field types, and indexes on FK and frequently queried fields."
- "Write a complete REST API endpoint in Express.js / Next.js API route for [describe endpoint]. Include: input validation with Zod, error handling, authentication check, and TypeScript types."
- "Create a GitHub Actions workflow for [describe CI/CD requirement]. Include: caching, parallel jobs where possible, and a notify-on-failure step."
- "Write unit tests for this function using Vitest: [paste function]. Cover: happy path, edge cases, error conditions, and boundary values. Aim for 100% branch coverage."
Documentation Prompts
- "Generate a JSDoc comment for this TypeScript function: [paste function]. Include: @param types and descriptions, @returns description, @throws for error cases, and a usage @example."
- "Write a README.md for this project based on the package.json and file structure: [paste]. Include: description, prerequisites, installation, local development, environment variables, and deployment."
- "Create an ADR (Architecture Decision Record) for our decision to use [technology]. Format: Title, Status, Context, Decision, Consequences. Include pros, cons, alternatives considered."
- "Write API documentation in OpenAPI 3.0 YAML for these endpoints: [describe]. Include request/response examples, status codes, and authentication requirements."