Modul master Level 3 VibeKoding: Alur Kerja Praktik Terbaik Berbantuan AI.Modul master Level 3 VibeKoding: Alur Kerja Praktik Terbaik Berbantuan AI.
In the previous chapters, we learned how to use AI IDEs to write code, how to manage code versions with Git, and how to design and implement API interfaces. But when you face a real development task, you may run into questions like these:In the previous chapters, we learned how to use AI IDEs to write code, how to manage code versions with Git, and how to design and implement API interfaces. But when you face a real development task, you may run into questions like these:
The essence of these questions is: how do you use AI tools efficiently in real development scenarios to get work done?The essence of these questions is: how do you use AI tools efficiently in real development scenarios to get work done?
In this lesson, we will learn how to build a systematic AI-assisted development workflow so that you can use AI efficiently across different development scenarios. Through concrete examples, we will show how to use AI in new feature development, bug fixing, code refactoring, and more.In this lesson, we will learn how to build a systematic AI-assisted development workflow so that you can use AI efficiently across different development scenarios. Through concrete examples, we will show how to use AI in new feature development, bug fixing, code refactoring, and more.
> π‘ Prerequisites> π‘ Prerequisites
>>
> Before studying this section, it is recommended that you first understand:> Before studying this section, it is recommended that you first understand:
> - [AI IDE Basics](../../stage-1/ai-ide/) - master the basic use of AI IDEs> - [AI IDE Basics](../../stage-1/ai-ide/) - master the basic use of AI IDEs
> - [Git and GitHub Workflow](../../stage-2/backend/git-workflow/) - understand code version management> - [Git and GitHub Workflow](../../stage-2/backend/git-workflow/) - understand code version management
> - [Using Large Models to Help Write API Code](../../stage-2/backend/ai-interface-code/) - understand the basic concept of AI-assisted development> - [Using Large Models to Help Write API Code](../../stage-2/backend/ai-interface-code/) - understand the basic concept of AI-assisted development
1. Understand AI's role in the development process and its capability boundaries 2. Master AI-assisted development strategies for different project types 3. Learn how to use Claude Code in scenarios such as new feature development, bug fixing, and code refactoring 4. Build a project knowledge base to improve collaboration efficiency with Claude Code 5. Master practical techniques for improving AI collaboration efficiency1. Understand AI's role in the development process and its capability boundaries 2. Master AI-assisted development strategies for different project types 3. Learn how to use Claude Code in scenarios such as new feature development, bug fixing, and code refactoring 4. Build a project knowledge base to improve collaboration efficiency with Claude Code 5. Master practical techniques for improving AI collaboration efficiency
Before we start using AI to assist development, we first need to understand what AI can and cannot do. Only then can we build the right collaboration model.Before we start using AI to assist development, we first need to understand what AI can and cannot do. Only then can we build the right collaboration model.
Think of AI as a very smart assistant that still needs clear instructions. It can quickly generate a code skeleton based on your description, and it can also read thousands of lines of code in seconds to find the part you need. If there are obvious syntax errors or common security vulnerabilities, it can help you discover them too. Repetitive tasks such as batch-renaming variables, formatting code, and generating documentation comments are especially suitable to hand over to AI.Think of AI as a very smart assistant that still needs clear instructions. It can quickly generate a code skeleton based on your description, and it can also read thousands of lines of code in seconds to find the part you need. If there are obvious syntax errors or common security vulnerabilities, it can help you discover them too. Repetitive tasks such as batch-renaming variables, formatting code, and generating documentation comments are especially suitable to hand over to AI.
Put simply, AI is good at work that has clear rules and can be automated.Put simply, AI is good at work that has clear rules and can be automated.
But AI also has its limitations. It does not understand your business logic. Unless you tell it in detail, it will not know how your company's order flow works. It also cannot make decisions such as technical selection or architecture design that require weighing trade-offs, because those depend on your experience and understanding of the project. AI also does not know your team's special conventions, such as "all APIs must have logging" or "error codes must use enums." You need to configure those rules or tell it explicitly.But AI also has its limitations. It does not understand your business logic. Unless you tell it in detail, it will not know how your company's order flow works. It also cannot make decisions such as technical selection or architecture design that require weighing trade-offs, because those depend on your experience and understanding of the project. AI also does not know your team's special conventions, such as "all APIs must have logging" or "error codes must use enums." You need to configure those rules or tell it explicitly.
Most importantly, code generated by AI cannot be used directly. You must review and test it. It may generate code that looks correct but is actually problematic, and it may ignore certain edge cases.Most importantly, code generated by AI cannot be used directly. You must review and test it. It may generate code that looks correct but is actually problematic, and it may ignore certain edge cases.
Once you understand AI's capability boundaries, the collaboration model becomes clear: you are responsible for deciding what to build, making decisions, and ensuring quality; AI is responsible for executing concrete coding work, finding information, and surfacing obvious problems.Once you understand AI's capability boundaries, the collaboration model becomes clear: you are responsible for deciding what to build, making decisions, and ensuring quality; AI is responsible for executing concrete coding work, finding information, and surfacing obvious problems.
It is like working with a junior developer. You tell them what needs to be done, they implement it, and then you review the code. The difference is that AI executes much faster, but its judgment is weaker than a human's.It is like working with a junior developer. You tell them what needs to be done, they implement it, and then you review the code. The difference is that AI executes much faster, but its judgment is weaker than a human's.
Different types of projects require different development styles and AI usage strategies. Choosing the right strategy can greatly improve development efficiency.Different types of projects require different development styles and AI usage strategies. Choosing the right strategy can greatly improve development efficiency.
Project characteristics:Project characteristics:
Recommended workflow:Recommended workflow:
Step 1: Plan the project structureStep 1: Plan the project structure
Before you start coding, first ask AI to help you plan the project structure and technical choices:Before you start coding, first ask AI to help you plan the project structure and technical choices:
text I want to build a task management app with these features: - User registration and login - Create, edit, and delete tasks - Task categories and tags - Task reminders Please help me: 1. Recommend a suitable tech stack 2. Design the project directory structure 3. Plan the database schema
Step 2: Build the basic frameworkStep 2: Build the basic framework
Based on the plan, ask AI to create the basic project structure:Based on the plan, ask AI to create the basic project structure:
text Based on the plan we just discussed, help me: 1. Create the project directory structure 2. Initialize config files (package.json, .env, etc.) 3. Create the basic server code
Step 3: Implement features one by oneStep 3: Implement features one by one
Implement feature modules one at a time by priority:Implement feature modules one at a time by priority:
text Now implement the user registration feature with these requirements: - Register with email and password - Store passwords in encrypted form - Email verification
Key points:Key points:
Project characteristics:Project characteristics:
Recommended workflow:Recommended workflow:
Step 1: Understand the project structureStep 1: Understand the project structure
Before changing code, first ask AI to help you understand the project:Before changing code, first ask AI to help you understand the project:
text This is an e-commerce project, and I need to add a coupon feature. Please help me: 1. Analyze the overall project structure 2. Find the order-related code 3. See how other similar features are implemented
Step 2: Find reference codeStep 2: Find reference code
Ask AI to find similar implementations in the project as references:Ask AI to find similar implementations in the project as references:
text Find how other promotional features in the project, such as full reduction and discounts, are implemented
Step 3: Follow the existing styleStep 3: Follow the existing style
Ask AI to implement the new feature in the style of the existing code:Ask AI to implement the new feature in the style of the existing code:
text Please implement the coupon feature by referring to how the full-reduction promotion is implemented. Keep the same code style and directory structure.
Key points:Key points:
Project characteristics:Project characteristics:
Recommended workflow:Recommended workflow:
Describe the requirement directly and implement quickly:Describe the requirement directly and implement quickly:
text Build a simple todo app with these requirements: - Add, delete, and mark tasks as completed - Store data locally - Keep the UI simple, as long as it works
Iterate quickly:Iterate quickly:
text Add search Switch it to a dark theme Add task categories
Key points:Key points:
Project characteristics:Project characteristics:
Recommended workflow:Recommended workflow:
Step 1: Locate the problemStep 1: Locate the problem
text User feedback: after clicking the "Submit Order" button, the page freezes Console error: TypeError: Cannot read property 'id' of undefined Please help me: 1. Analyze possible causes 2. Find the relevant code
Step 2: Analyze the root causeStep 2: Analyze the root cause
text Check in what situations this error occurs Inspect the data flow
Step 3: Apply the fixStep 3: Apply the fix
text Fix this problem, and: 1. Add defensive code to avoid similar issues 2. Add error messages to improve user experience
Key points:Key points:
In day-to-day development, we encounter many different types of tasks. Below are several of the most common AI-assisted workflows.In day-to-day development, we encounter many different types of tasks. Below are several of the most common AI-assisted workflows.
Scenario: the product manager gives you a new requirement, and you need to implement a new feature.Scenario: the product manager gives you a new requirement, and you need to implement a new feature.
Complete workflow:Complete workflow:
Step 1: Understand the requirement (done by you)Step 1: Understand the requirement (done by you)
Before you start coding, first clarify:Before you start coding, first clarify:
Step 2: Understand the existing code (ask AI to help)Step 2: Understand the existing code (ask AI to help)
text I need to implement a user comment feature. Please help me: 1. Check whether there is anything similar in the project 2. Find how user data and article data are stored 3. Understand the database operation conventions in this project
Step 3: Make an implementation plan (with AI)Step 3: Make an implementation plan (with AI)
text Based on the analysis we just did, implementing the comment feature requires: 1. Creating a comment data model 2. Implementing CRUD APIs for comments 3. Adding comment display and posting functionality to the frontend Please help me confirm whether this plan is reasonable and whether anything is missing
Step 4: Implement the feature (AI generates, you review)Step 4: Implement the feature (AI generates, you review)
text According to the plan, first implement the comment data model. Requirements: - Include comment content, author, article ID, and creation time - Support nested comment replies - Add necessary indexes
text Now implement the comment API endpoints. Requirements: - Post a comment - Delete a comment (only your own comments can be deleted) - Get all comments for an article - Support pagination
text Finally implement the frontend comment component. Requirements: - Show the comment list - Comment posting form - Support replying to comments
Step 5: Test and verify (done by you)Step 5: Test and verify (done by you)
Real conversation example:Real conversation example:
text You: I want to add a user comment feature so users can post comments on articles AI: Okay, let me first understand the project structure. [AI analyzes the project code] I see that the project already has a user system (models/user.js) and an article system (models/article.js). Implementing the comment feature requires: 1. Creating a comment data model (models/comment.js) 2. Adding comment-related APIs (routes/comment.js) 3. Adding comment display and posting functionality to the article detail page Should I start implementing it? You: Yes, let's start. Create the data model first AI: [Generates models/comment.js] I have created the comment data model with these fields: - id: comment ID - content: comment content - userId: author ID - articleId: article ID - parentId: parent comment ID (for nested replies) - createdAt: creation time Should I implement the API next? You: Yes, implement the API
Scenario: a user reports a problem, and you need to locate and fix it quickly.Scenario: a user reports a problem, and you need to locate and fix it quickly.
Complete workflow:Complete workflow:
Step 1: Gather information (done by you)Step 1: Gather information (done by you)
Record the following information:Record the following information:
Step 2: Locate the problem (ask AI to help)Step 2: Locate the problem (ask AI to help)
text User feedback: after clicking the "Submit Order" button, the page freezes Browser console error: TypeError: Cannot read property 'id' of undefined The error occurs on line 45 of checkout.js Please help me: 1. Analyze possible causes 2. Find the relevant code 3. Check the data flow
Step 3: Analyze the root cause (with AI)Step 3: Analyze the root cause (with AI)
text Check where this user object comes from Inspect under what circumstances user could be undefined
Step 4: Implement the fix (AI generates, you review)Step 4: Implement the fix (AI generates, you review)
text Fix this problem with these requirements: 1. Add defensive code to check whether user exists 2. If user does not exist, redirect to the login page 3. Add a friendly error message
Step 5: Verify the fix (done by you)Step 5: Verify the fix (done by you)
Real conversation example:Real conversation example:
text You: A user reported that after logging in, refreshing the page logs them out AI: This is usually a token storage or validation issue. Let me check: 1. Where is the token stored, localStorage or cookies? 2. Is the token reloaded when the page refreshes? Please tell me which file contains the token-related code You: utils/auth.js AI: [Analyzes utils/auth.js] I found the issue: the token is stored in sessionStorage, and sessionStorage is cleared when the page is refreshed. Solution: use localStorage instead Would you like me to change it? You: Yes, change it AI: [Modifies the code] The change is complete. The token is now stored in localStorage, so it will not be lost after a page refresh. I recommend that you test: 1. Log in and refresh the page to confirm the user stays logged in 2. Close and reopen the browser to confirm the user stays logged in
Scenario: the code has become hard to maintain, and it needs refactoring to improve code quality.Scenario: the code has become hard to maintain, and it needs refactoring to improve code quality.
Complete workflow:Complete workflow:
Step 1: Define the refactoring goal (done by you)Step 1: Define the refactoring goal (done by you)
Clarify the following:Clarify the following:
Step 2: Make a refactoring plan (with AI)Step 2: Make a refactoring plan (with AI)
text These three functions (getUserList, getArticleList, getCommentList) contain a lot of duplicated code for pagination, sorting, and filtering. Please help me: 1. Analyze the duplicated parts 2. Propose a refactoring plan 3. Evaluate the risk of the refactor
Step 3: Prepare a safety net (ask AI to help)Step 3: Prepare a safety net (ask AI to help)
text Before refactoring, please write test cases for me first so that the behavior stays the same after the refactor
Step 4: Refactor step by step (AI executes, you verify)Step 4: Refactor step by step (AI executes, you verify)
text According to the plan we just discussed, first extract the shared function
text Now optimize the data structure
text Finally update the call sites
Step 5: Verify the result (done by you)Step 5: Verify the result (done by you)
Real conversation example:Real conversation example:
text You: These three functions have a lot of duplicate code. Can you help me refactor them? [Paste the code of the three functions] AI: I analyzed them, and the main differences are: - getUserList: gets the user list - getArticleList: gets the article list - getCommentList: gets the comment list Their common logic is pagination, sorting, and filtering. Refactoring plan: 1. Extract a generic getList function 2. Pass the different parts as parameters This can reduce 80% of the duplicated code. Should I implement it? You: Yes, but first help me write test cases AI: [Generates tests] I have written tests for all three functions, covering the main use cases. Can I start refactoring now? You: Yes, start refactoring AI: [Refactors the code] Refactoring is complete. I created a generic getList function, and the original three functions now all call that shared function. Please run the tests to confirm everything works: npm test
Scenario: a teammate submitted code, and you need to review it.Scenario: a teammate submitted code, and you need to review it.
Complete workflow:Complete workflow:
Step 1: Quickly understand the change (ask AI to help)Step 1: Quickly understand the change (ask AI to help)
text Summarize what this PR changed Which files were mainly modified
Step 2: Check common issues (ask AI to help)Step 2: Check common issues (ask AI to help)
text Check this change for: 1. Security issues (SQL injection, XSS, etc.) 2. Performance problems (N+1 queries, memory leaks, etc.) 3. Obvious bugs 4. Whether the coding style follows the project conventions
Step 3: Deep review (done by you)Step 3: Deep review (done by you)
Step 4: Give feedback (done by you)Step 4: Give feedback (done by you)
Real conversation example:Real conversation example:
text You: Help me review this PR [Provide the PR link or code] AI: I reviewed the change and found these issues: 1. Security issues: - Line 23: user input is not escaped, which may lead to XSS risk - Line 45: the SQL query is built by string concatenation, which risks injection 2. Performance problems: - Line 67: the database is queried inside a loop, which creates an N+1 problem 3. Code quality: - The handleSubmit function is too long (200 lines); consider splitting it - Error handling is missing Would you like me to explain any of these in more detail? You: Explain the SQL injection issue in detail AI: On line 45:
const query = SELECT * FROM users WHERE name = '${userName}';const query = SELECT * FROM users WHERE name = '${userName}';
CODE This directly concatenates user input into the SQL statement. If a user enters `' OR '1'='1`, it becomes:
SELECT * FROM users WHERE name = '' OR '1'='1'SELECT * FROM users WHERE name = '' OR '1'='1'
CODE This would return all user data. The correct approach is to use a parameterized query:
const query = 'SELECT * FROM users WHERE name = ?';const query = 'SELECT * FROM users WHERE name = ?';
db.query(query, [userName]);db.query(query, [userName]);
CODE Would you like me to fix it?
To help AI understand your project better, it is recommended to build a knowledge base inside the project. That way AI can work according to your conventions and habits.To help AI understand your project better, it is recommended to build a knowledge base inside the project. That way AI can work according to your conventions and habits.
Create a CLAUDE.md or AGENTS.md file in the project root to record key project information:Create a CLAUDE.md or AGENTS.md file in the project root to record key project information:
markdown # Project Overview ## Project Summary This is an online learning platform that provides course management, user learning, assignment submission, and other features. ## Tech Stack - Frontend: React 18 + TypeScript + Vite - Backend: Node.js + Express + PostgreSQL - Deployment: Vercel (frontend) + Railway (backend) ## Project Structure
src/src/
βββ components/ # React componentsβββ components/ # React components
βββ pages/ # Page componentsβββ pages/ # Page components
βββ api/ # API callsβββ api/ # API calls
βββ utils/ # Utility functionsβββ utils/ # Utility functions
βββ types/ # TypeScript type definitionsβββ types/ # TypeScript type definitions
CODE ## Code Conventions - Use ESLint and Prettier to format code - Component files use PascalCase (such as UserProfile.tsx) - Utility functions use camelCase (such as formatDate.ts) - Constants use UPPER_SNAKE_CASE (such as API_BASE_URL) ## Development Flow 1. Create a feature branch from main 2. Submit a PR after development is complete 3. Merge after code review passes ## Common Tasks - Start the development server: `npm run dev` - Run tests: `npm test` - Build for production: `npm run build` - Format code: `npm run format` ## Notes - All API calls must include error handling - User input must be validated and escaped - Use parameterized queries for database operations to avoid SQL injection - Sensitive information (passwords, tokens) must not be written to logs ## Database Schema - users: user table (id, email, password_hash, created_at) - courses: course table (id, title, description, teacher_id) - enrollments: enrollment table (id, user_id, course_id, enrolled_at)
Create docs/troubleshooting.md in the project to record common problems:Create docs/troubleshooting.md in the project to record common problems:
markdown # Common Problems ## Development Environment Problems ### Problem: npm install fails **Cause:** Node version is incompatible **Solution:** Use Node.js 18 or higher ### Problem: database connection fails **Cause:** environment variables are not configured **Solution:** Copy .env.example to .env and fill in the database connection info ## Feature Problems ### Problem: after users log in, refreshing the page logs them out **Cause:** the token is stored in sessionStorage **Solution:** switch to localStorage ### Problem: image upload fails **Cause:** file size exceeds the limit **Solution:** add a file size check on the frontend and limit it to 5MB
Create a docs/decisions/ directory to record important technical decisions:Create a docs/decisions/ directory to record important technical decisions:
markdown # ADR-001: Choosing PostgreSQL as the Database ## Status Accepted ## Background The project needs to choose a relational database. The candidates are MySQL and PostgreSQL. ## Decision Choose PostgreSQL ## Rationale 1. Better JSON support, suitable for storing course content 2. Stronger full-text search 3. The team is more familiar with PostgreSQL ## Consequences - We need to learn PostgreSQL-specific features - Deployment requires a PostgreSQL environment
By mastering some practical techniques, you can make your collaboration with AI more efficient.By mastering some practical techniques, you can make your collaboration with AI more efficient.
Bad description:Bad description:
text This feature has a problem Help me optimize it
Good description:Good description:
text After the user clicks the "Submit" button, the form is not submitted The browser console reports: Uncaught TypeError: Cannot read property 'value' of null The error occurs on line 23 of form.js This list loads very slowly and has 1000 items Please help me add pagination with 20 items per page
Key points:Key points:
Bad approach:Bad approach:
text Help me implement login, registration, password recovery, profile center, password change, and email verification
Good approach:Good approach:
text Implement the login feature first, with these requirements: - Email and password login - Remember login state - Error messages (After it is done) Now implement the registration feature (After it is done) Now implement the password recovery feature
Key points:Key points:
Bad approach:Bad approach:
Good approach:Good approach:
Key points:Key points:
Technique 1: refer to previous conversationTechnique 1: refer to previous conversation
text Implement according to the plan we just discussed Refer to the previous getUserList function
Technique 2: provide related codeTechnique 2: provide related code
text This is the existing user model code: [paste code] Please implement the article model in the same style
Technique 3: explain project backgroundTechnique 3: explain project background
text This is an e-commerce project using React + Node.js It already has a user system and a product system Now we need to add a shopping cart feature
Scenario: you solved a complex problemScenario: you solved a complex problem
How to do it:How to do it:
Example:Example:
Create a document under docs/solutions/:Create a document under docs/solutions/:
markdown # Solving the N+1 Query Problem ## Problem Description When fetching the article list, the system queries the author information once per article, which causes a performance problem. ## Solution Use a JOIN query to fetch all the data in one go:
SELECT articles.*, users.name as author_nameSELECT articles.*, users.name as author_name
FROM articlesFROM articles
LEFT JOIN users ON articles.author_id = users.idLEFT JOIN users ON articles.author_id = users.id
CODE **Result:** query time dropped from 2000ms to 50ms ## 5.6 Learn the Art of Asking Questions **Technique 1: ask "why" first**
Why does this code cause a memory leak?Why does this code cause a memory leak?
Why should we use useCallback instead of a normal function?Why should we use useCallback instead of a normal function?
CODE **Technique 2: ask for multiple options**
What are the different ways to implement user authentication?What are the different ways to implement user authentication?
What are the pros and cons of each?What are the pros and cons of each?
CODE **Technique 3: ask for explanations**
How does this code work?How does this code work?
Can you explain this algorithm in detail?Can you explain this algorithm in detail?
CODE # 6. Frequently Asked Questions ## Q1: Can I use AI-generated code directly? **A:** No, not directly. It needs review and testing. AI-generated code may have the following problems: - logical errors or poor handling of edge cases - failure to match the project's coding conventions - security risks - insufficient performance optimization You need to: - carefully read the generated code - understand its logic - test different scenarios - confirm that it follows the project conventions ## Q2: What if AI misunderstands what I mean? **A:** Correct it in time and describe the requirement again.
That's not what I meant. What I mean is...That's not what I meant. What I mean is...
This understanding is incorrect. It should be...This understanding is incorrect. It should be...
Let me describe the requirement again...Let me describe the requirement again...