Prompt Engineering for Code
Prompt Engineering for Code
The art of formulating your requests well
Prompt engineering is the most important skill in Vibe Coding. A good prompt produces functional code on the first try. A bad prompt generates off-topic or buggy code.
Fundamental principles
1. Be specific
Bad prompt:
Make me a form
Good prompt:
Create a registration form in Angular with email, password, and
password confirmation fields. Use Reactive Forms with validation:
valid email, password min 8 characters, confirmation matching
the password. Display errors below each field.
2. Provide context
The AI doesn't know your project. Provide it with:
- The framework being used (Angular, React, NestJS...)
- The project's conventions (file structure, naming)
- The available dependencies (TypeORM, Tailwind, etc.)
- The purpose of the feature in the overall context
3. Break down complex tasks
graph TD
A[Complex task] --> B[Sub-task 1]
A --> C[Sub-task 2]
A --> D[Sub-task 3]
B --> E[Prompt 1]
C --> F[Prompt 2]
D --> G[Prompt 3]
E --> H[Integrated code]
F --> H
G --> H
Rather than asking "build me a complete e-commerce app", break it down:
- Create the data model for products
- Create the CRUD API for products
- Create the catalog page with filters
- Add the cart with quantity management
4. Iterate progressively
Don't aim for perfection on the first try. Proceed by iterations:
- V1: minimal working version
- V2: adding style and UX
- V3: error handling and edge cases
- V4: optimizations and refactoring
Effective prompt patterns
The "role + context + task" prompt
You are a senior NestJS developer.
I'm working on a REST API for an educational platform.
Create a service that manages user progress in programs:
- Mark a chapter as read
- Calculate the progress percentage
- Use TypeORM with a UserProgress entity
The "example + adaptation" prompt
Here is my existing service for programs:
[paste the code]
Create a similar service for quizzes, following the same
conventions and patterns.
The "constraint" prompt
Create an Angular component to display a list of program cards.
Constraints:
- No external library, only Tailwind CSS
- Standalone component
- Responsive: 1 column mobile, 2 tablet, 3 desktop
- Each card displays: title, description, progress, image
Common mistakes
Too vague
"Improve this code" -> The AI doesn't know what you mean by "improve".
Too long
A 500-line prompt will overwhelm the AI. Stay concise and focused.
No verification
Copy-pasting AI code without reading it is dangerous. Always review.
Ignoring errors
When the AI generates code that doesn't compile, don't resubmit the same prompt. Share the exact error with the AI.
Summary
Prompt engineering for code rests on four pillars: specificity, context, decomposition, and iteration. The more you practice, the more effective your prompts become and the higher the quality of generated code.