Getting generic, unusable code from your AI? The problem isn't the AI; it's how we ask.
Many of us treat AI like a vague search engine. I was getting bad responses until I stopped 'chatting' and started 'directing'. I developed a 5-step framework that completely changed the quality of my results. If you follow this, you'll see the difference immediately.
The Golden Rule: Always Set the Role First
Before you write a single command, tell the AI 'who it is'. This sets the context for its entire response.
Example:You are a senior full-stack engineer assigned to build a modern web application from scratch.
Now, 5-Step Prompt Framework
I structure my prompts using these five sections. This forces the AI to be specific and build exactly what I need.
1. Objective
State the "big picture" goal in one or two sentences.
- Create a secure REST API for a blog platform. It will handle user authentication and CRUD operations for posts.
2. Structure
Define your tech stack and architecture. Don't let the AI guess.
- Tech Stack: Use the MERN stack (MongoDB, Express.js, React
- Authentication: Use JSON Web Tokens (JWT).
- Backend: Follow a controller-service pattern.
3. Tasks
This is the most critical part. Break the objective down into small, clear, actionable chunks.
- Create 'User' and 'Post' MongoDB models.
- Implement user registration (with password hashing) and login (issuing a JWT).
- Create a middleware to verify the JWT for protected routes.
- Implement full CRUD operations for the 'Post' controller.
4. Output Requirements
Tell the AI *exactly* how you want the answer delivered.
- Provide complete code for each file (models, controllers, middleware).
- Use ES6 module syntax (import/export).
- Add brief inline comments for complex logic.
5. Notes
Add any final rules, constraints, or specifics.
- All async functions must use try/catch blocks for error handling.
- Do not return the user's password in any API response.
Top comments (1)
Example: You are a senior full-stack engineer tasked with building a desktop application from scratch.
Objective
I need a simple 2-page design, like a sidebar and content in the middle.
Structure
I need to use Tailwind CSS for good structure and easy design.
Use React for frontend desktop application design.
Tech Stack: Use TailwindCSS, React
Tasks
First, check my screenshot carefully.
This is a pos system that needs full design as same my screenshot.
Output Requirements
I need just a design and basic functionality.
Provide complete code for each file. (Best folder structure for a desktop application)
Use ES6 module syntax (import/export).
Add brief inline comments for complex logic.
Need production-ready installation file (Mac, Windows, and Ubuntu devices)
Every functionalities and pages need a test case.
Notes
All async functions must use try/catch blocks for error handling.
Handle global error for better ux.
If possible, use a reusable component for a better developer experience.