A Five-Stage AI Coding Workflow That Keeps You in Control
Previous articles covered requirement splitting, code generation, testing, optimization, and code review.
But in real development, we rarely do just one of these things. A feature typically goes through:
Requirement analysis → Implementation → Testing → Code review → Documentation
If you ask AI ad-hoc at each step, the output may contradict itself, and you can easily forget which parts you've verified.
So we need a fixed AI programming workflow.
This article doesn't discuss complex automation platforms. It uses a small feature to illustrate:
How to involve AI in the entire development process while keeping key decisions in your own hands.
1. First, clarify AI's position in the workflow
AI is better suited for:
- Organizing information.
- Spotting omissions.
- Generating code drafts.
- Providing multiple implementation options.
- Supplementing test scenarios.
- Checking modifications.
- Organizing technical documentation.
The developer still needs to:
- Confirm real requirements.
- Choose the right solution.
- Judge whether the code is correct.
- Handle business and security concerns.
- Run and verify in a real environment.
Think of AI as a highly efficient assistant, not an automatic delivery system.
2. Run a small feature through the entire process
Suppose we want to add a "search by keyword" feature to a product list.
Project context:
- Frontend: Vue 3.
- Backend: Node.js and Express.
- Product data stored in MySQL.
- Existing endpoint:
GET /api/products. - This time we only search product names; no database schema changes.
The requirement:
User enters a product name keyword in an input box, clicks search, and sees matching products.
When the keyword is empty, show all products.
When there are no matches, show an empty state.
Now run this requirement through five stages.
3. Stage 1: Let AI help you confirm requirements
Don't ask AI to write code right away.
First, have it check whether the requirements are complete and point out questions that need confirmation.
You can ask like this:
Please analyze the following feature requirement. Do not write code for now.
Project background:
- Frontend: Vue 3
- Backend: Node.js + Express
- Database: MySQL
- Existing endpoint: GET /api/products
Feature requirement:
After the user enters a product name keyword, query and display matching products.
When the keyword is empty, show all products. When there are no results, show an empty state.
Please output:
1. Your understanding of the requirement
2. Questions that need confirmation
3. Frontend tasks
4. Backend tasks
5. Test acceptance criteria
Do not add features like pagination, sorting, or anything beyond fuzzy matching on your own.
AI might remind us to confirm:
- Whether the search is case-insensitive.
- Whether to use fuzzy matching.
- Whether the keyword needs leading/trailing whitespace trimmed.
- What prompt to show when the search fails.
- Whether to prevent users from making frequent requests.
These questions should be confirmed against product and project rules before entering the coding stage.
Output of this stage
Don't just leave chat logs. You can organize a short implementation constraint document:
Feature: Search by product name
Matching method: Contains match, case-insensitive
Empty keyword: Query all products
Whitespace handling: Trim leading and trailing whitespace
No results: Return empty array, frontend shows empty state
Error handling: Show error prompt when the endpoint fails
Scope limit: No pagination or sorting added this time
This constraint document becomes the shared context when you later ask AI to write code and tests.
4. Stage 2: Let AI propose a plan first, then write code
Once requirements are clear, let AI design an implementation plan.
Based on the confirmed requirements, please design a simple implementation plan.
Requirements:
1. Explain which frontend files need to be modified.
2. Explain which backend files need to be modified.
3. Explain the endpoint parameters and return format.
4. Explain key boundary conditions.
5. Prioritize reusing the existing project structure; do not introduce new dependencies.
6. Output the plan first; do not write complete code.
A reasonable plan might be:
1. Frontend maintains a keyword state in the search box.
2. On search click, trim the keyword.
3. Request GET /api/products?keyword=xxx.
4. Backend reads the keyword parameter.
5. When keyword is empty, query all products.
6. When keyword is not empty, use parameterized query for name matching.
7. Frontend handles loading, success, empty data, and failure states separately.
After confirming the plan, let AI generate code in small steps.
Please implement only the backend endpoint part.
Constraints:
- Use existing Express routes and database access methods.
- When keyword is empty, query all products.
- When keyword is not empty, match by product name contains.
- Must use parameterized queries.
- Do not modify database table structure.
- Keep the existing return format.
Please list the files that need to be modified first, then provide the code.
Tackling one part at a time makes problems easier to spot and rollback simpler.
5. Stage 3: Let AI help you supplement tests
After the code is written, don't immediately ask AI to refactor or add more features.
First, have it list test scenarios based on the requirements:
Based on the requirements below, please list test scenarios. Do not write test code for now.
Requirements:
- When keyword is empty, return all products.
- When keyword has leading/trailing whitespace, trim automatically.
- Keyword uses contains matching.
- When no matching products, return empty array.
- When database query fails, return a unified error.
Please output in three categories: normal, boundary, and exception.
Each scenario should include input, expected result, and test purpose.
Test scenarios should at least include:
| Type | Input | Expected result |
|---|---|---|
| Normal | 耳机 |
Return products whose name contains "耳机" |
| Empty | Empty string | Return all products |
| Whitespace | 耳机 |
Query by 耳机 |
| No results | 不存在的商品 |
Return empty array |
| Exception | Database connection failure | Return unified error message |
| Special input | Contains SQL special characters | No dangerous SQL executed |
After confirming the scenarios, let AI generate test code using the project's existing test framework.
Please use the project's existing test framework to generate test code for the confirmed scenarios above.
Requirements:
1. First check how existing test files are written and stay consistent.
2. Each test must have explicit assertions.
3. Do not modify production code.
4. Do not use real databases or real user data.
5. Explain what each test verifies.
Focus on checking whether tests have "false passes":
- Only checks that the endpoint didn't throw an exception, but didn't check the returned data.
- Only checks status codes, not business fields.
- Assertions are too broad; any result passes.
- Tests don't cover empty values and exception cases.
6. Stage 4: Let AI review code and modification scope
After tests pass, proceed to code review.
At this point, it's best to submit the diff of this modification, not the entire project.
git diff -- src/routes/products.js src/views/ProductList.vue test/products.test.js
Give the diff and requirements to AI together:
Please review the following code modification for the product search feature.
Confirmed requirements:
- Match by product name contains.
- Empty keyword returns all products.
- Trim leading/trailing whitespace from keyword.
- No results returns empty array.
- Must use parameterized queries.
- No pagination or sorting added this time.
Please focus on checking:
1. Whether requirements are met.
2. Whether there is SQL injection risk.
3. Whether empty value, exception, and empty result handling are missing.
4. Whether the original product list functionality is affected.
5. Whether content beyond the requirements was modified.
6. Whether tests or documentation are missing.
Please output in the format: "Problem location, severity, impact, suggestion, verification method".
List problems first; do not rewrite code directly.
Code diff:
[Paste git diff content]
During code review, pay attention to AI's specific evidence, not just conclusions like "overall no problems".
If AI points out SQL concatenation risk, go back to the code and confirm whether the query uses parameter placeholders; if it points out missing tests, confirm whether corresponding test files and assertions actually exist for that scenario.
7. Stage 5: Let AI organize documentation
After the feature is verified, update the README or API documentation.
Based on the following verified endpoint information, please supplement the API documentation.
Endpoint: GET /api/products
Query parameters:
- keyword: Product name keyword, optional
Behavior:
- When empty, returns all products.
- When not empty, matches by product name contains.
- Server trims leading/trailing whitespace.
- When no matching results, returns empty array.
Please output in Markdown format, including:
1. Endpoint purpose
2. Request method and URL
3. Parameter description
4. Successful response example
5. Empty result example
6. Error description
Only use the facts provided above. Do not fabricate pagination, sorting, or permission rules.
Documentation should be generated based on already implemented and verified results.
Don't let AI write a "seemingly complete" document first, then force the code to conform to the document.
8. Set a checkpoint for each stage
The easiest place for an AI workflow to go wrong is jumping directly from one stage to the next.
You can set checkpoints for each stage:
| Stage | Work given to AI | Results you must confirm yourself |
|---|---|---|
| Requirements | Extract rules, discover questions | Business rules and scope |
| Plan | Break down tasks, design interface | Plan is simple and achievable |
| Coding | Generate partial code | Code conforms to project structure |
| Testing | Supplement scenarios and test code | Assertions are truly effective |
| Review | Find risks and omissions | Problems have been fixed and verified |
| Documentation | Organize usage instructions | Documentation matches actual behavior |
Only when the current stage is confirmed complete do you enter the next stage.
9. Build your own context template
Every project can prepare a fixed context template:
Project name: [Project name]
Tech stack: [Language, framework, database, and versions]
Directory structure: [Relevant directories]
Code conventions: [Naming, formatting, and testing requirements]
Interface conventions: [Request and response formats]
Current task: [Feature to be completed this time]
Explicit constraints: [Content that cannot be modified]
Acceptance criteria: [What result counts as done]
Each time you start a new task, you only need to fill in "Current task, Explicit constraints, and Acceptance criteria".
This reduces repetitive descriptions and lowers the chance of AI understanding inconsistently across sessions.
Be careful not to put keys, real user data, or production-sensitive information into the context template.
10. A simplified workflow suitable for daily development
If the full workflow seems like a lot, you can first remember this simplified version:
1. Clearly state what you want to do
2. Let AI find unclear points
3. Confirm the plan and modification scope
4. Let AI write only one small part at a time
5. Run and test it yourself
6. Let AI review the diff
7. Update documentation and record results
For a very small utility function, you might only need the requirements, coding, and testing stages.
For high-risk features like payments, permissions, or data deletion, you should execute all five stages completely and add manual review.
11. Three common mistakes
| Wrong practice | Why it's problematic | Better approach |
|---|---|---|
| Let AI complete the entire project at once | Large code volume, hard to understand and verify | Break into small tasks like endpoints, components, and tests |
| Move to the next step without checking | Early errors propagate all the way through | Confirm the output of each stage before proceeding |
| Let AI self-review right after generation | May repeat previous misunderstandings | Re-provide requirements and acceptance criteria; do manual review when necessary |
12. Personal AI programming workflow checklist
When starting a new task each day, you can follow this checklist:
- Have stated the goal for this session in one sentence.
- Have listed uncertain points in the requirements.
- Have confirmed the modification scope and constraints.
- Have let AI output an implementation plan.
- Have broken the task into verifiable small steps.
- Have run the generated code.
- Have tested normal, boundary, and exception scenarios.
- Have let AI review the code diff.
- Have fixed high-priority issues.
- Have updated relevant documentation.
- Have not submitted keys, user data, or unauthorized company code to AI.
Summary
A practical AI programming workflow can be divided into five stages:
Requirements → Coding → Testing → Review → Documentation
AI can help at every stage, but the final check at each stage still needs to be done by the developer.
When using this workflow, it's recommended to remember three principles:
- Confirm requirements first, then start writing code.
- Let AI complete only one clear, small task at a time.
- Run, test, and check every step; don't carry errors into the next stage.
Truly efficient AI programming is not about having AI generate the most code at once, but about making every piece of generated content quickly understandable, verifiable, and usable.
The next article will introduce:
"Real Case: Refactoring Hard-to-Maintain Legacy Code with AI"
✍Insist on original content, seeking follows, likes, and saves