AI coding assistants can 10x your productivity - if you know how to talk to them. Here's a developer's guide to writing prompts that produce production-ready code.
The Developer Prompting Mindset
Think of your AI assistant as a very fast junior developer with encyclopedic knowledge but no context about your project. Your job is to provide:
- Context - Tech stack, project structure, conventions
- Specifics - Exact requirements, constraints, edge cases
- Examples - Show the patterns you want followed
Architecture & Design Prompts
System Design
Design a real-time notification system for a social media app with:
- Tech stack: Node.js, PostgreSQL, Redis, WebSocket
- Scale: 1M daily active users
- Requirements: <100ms delivery, offline queue, read receipts
- Include: architecture diagram (text), database schema, key API endpoints
- Consider: failure modes and graceful degradationDatabase Schema
Design a PostgreSQL schema for a multi-tenant SaaS project management tool.
Entities: Organizations, Users, Projects, Tasks, Comments, Attachments
Requirements:
- Row-level security per organization
- Soft deletes on all entities
- Audit trail (created_by, updated_by, timestamps)
- Optimized for: listing tasks by project and assignee
Include indexes and explain your choices.Code Generation Prompts
API Endpoint
Write a Next.js API route (App Router) that:
- Accepts POST requests with JSON body: { email, plan, paymentMethodId }
- Validates input with Zod
- Creates a Stripe subscription
- Stores the subscription in a PostgreSQL database using Prisma
- Returns the subscription details
- Handles errors with proper HTTP status codes
- Include TypeScript types for request/responseReact Component
Create a React component 'DataTable' with TypeScript that:
- Accepts generic data array and column definitions
- Supports sorting (click column headers)
- Supports pagination (10/25/50 per page)
- Supports row selection with checkboxes
- Uses Tailwind CSS for styling
- Follows the compound component pattern
- Is fully accessible (ARIA attributes, keyboard navigation)
Don't use any external table library.Refactoring
Refactor this code to:
1. Follow SOLID principles
2. Extract reusable utility functions
3. Add proper TypeScript types (no 'any')
4. Improve error handling
5. Add JSDoc comments for public functions
Explain each change and why it improves the code.
[PASTE CODE]Debugging Prompts
Error Diagnosis
I'm getting this error in production:
Error: ECONNREFUSED 127.0.0.1:5432
Context:
- Node.js 20, Express, PostgreSQL 16, Docker Compose
- Works locally, fails in Docker
- Started after adding a new service to docker-compose.yml
- Database container is running (verified with docker ps)
What's causing this and how do I fix it?Performance Investigation
This database query takes 8 seconds on a table with 2M rows:
[PASTE QUERY]
Table schema: [PASTE SCHEMA]
Existing indexes: [LIST]
Analyze the query plan, identify bottlenecks, and suggest:
1. Query optimizations
2. Index recommendations
3. Schema changes if needed
4. Caching strategyTesting Prompts
Comprehensive Test Suite
Write tests for this function using Vitest:
[PASTE FUNCTION]
Include:
- Happy path tests (3-5 cases)
- Edge cases (empty input, boundary values)
- Error cases (invalid input, network failures)
- Type checking for TypeScript
- Use describe/it blocks with clear names
- Mock external dependencies
- Aim for >90% branch coverageGit & DevOps Prompts
Commit Messages
Generate a conventional commit message for these changes. Follow the format: type(scope): description
[PASTE DIFF]CI/CD Pipeline
Write a GitHub Actions workflow that:
- Triggers on push to main and PRs
- Runs linting (ESLint), type checking (tsc), and tests (Vitest)
- Builds the Next.js app
- Deploys to Vercel on main branch only
- Caches node_modules and .next/cache
- Fails fast if any step errorsPro Tips for AI-Assisted Development
- Start with types - Define interfaces first, then ask AI to implement
- Provide examples of your codebase style - Paste a similar component as reference
- Ask for explanations - Understanding AI code is more valuable than just using it
- Review critically - AI can produce plausible but incorrect code
- Iterate incrementally - Build complex features step by step, not all at once
- Use your editor's AI - Copilot/Cursor work best with good file context open