Skip to main content
Reading progress: 0%

Lesson 6.2: Building One Feature at a Time and Reviewing Generated Code

Lesson Quick-Jump (10 Sections)

1. What Are We Learning?​

In this lesson, you will learn how to:

  • Implement one feature at a time using a repeatable workflow (backend -> frontend integration -> testing).
  • Review generated code systematically—even as a beginner.
  • Ask AI to explain unfamiliar code line by line.
  • Stop agents from making unnecessary architectural changes.

2. Why Does It Matter?​

info

Writing code is no longer the bottleneck—reviewing and verifying code is. If you blindly click "Accept All" on every file an AI agent edits, bugs pile up invisibly until the app collapses and neither you nor the AI knows why.

By building one complete vertical slice at a time and reviewing every diff before moving on, you always have a working app—and you actually learn how your own software works.


3. Simple Explanation for a Complete Beginner​

The Repeatable Feature Loop (Vertical Slice)​

For every single feature in your plan, repeat this exact 3-step loop:

  1. Step A — Backend & Data First: Add the database change (if needed) and the backend API endpoint + validation. Test the endpoint directly (or via a quick test) before touching the UI.
  2. Step B — Frontend Integration: Connect the screen/button/form from your wireframe (docs/design-direction.md) to that working backend endpoint, including loading and error states.
  3. Step C — Verify & Review: Test the feature in the browser against every Acceptance Criterion, inspect the diff of changed files, and commit before starting the next feature.

How to Review Code When You Are a Beginner​

You do not need to memorize syntax to review AI code! Look for five practical things in the diff:

  1. File scope: Did it only edit files in our approved plan?
  2. Clarity: Are function and variable names descriptive (createHabit, validateTitle) rather than cryptic (doThing, x2)?
  3. Hardcoded secrets or fake data: Are there any pasted passwords, dummy arrays pretending to be database results, or placeholder URLs?
  4. Error handling: What happens if the input is empty or the server fails? Does it return a clean message instead of crashing silently?
  5. No unapproved rewrites: Did the agent rewrite working code in unrelated files or switch libraries without asking?

Whenever a block of code looks confusing, highlight it and ask the agent: "Explain what these 15 lines do in plain English and why we need them."


4. Practical Example​

Suppose the AI just implemented the "Add Habit" backend endpoint and frontend form.

Reviewing the diff, you spot two subtle issues:

  1. In the backend route, title is saved even if the user submits " " (spaces only), because it checked if (!title) instead of trimming whitespace (title.trim()).
  2. The agent also reformatted and changed colors in an unrelated Header file you didn't ask it to touch.

Your response as the engineering decision-maker:

  • "Revert the unrelated changes in Header."
  • "In the habit creation route, trim whitespace before checking if title is empty, and return a clear 400 error message if it is blank."

That takes 60 seconds and prevents messy regressions!


5. Step-by-Step Instructions​

  1. Approve your plan from Lesson 6.1 and ask the agent to implement Step A (Backend/Data) first.
  2. Verify Step A works (using a quick automated test, terminal request, or server log check).
  3. Ask the agent to implement Step B (Frontend Integration) using your docs/design-direction.md.
  4. Open your browser and test every Acceptance Criterion (normal case + empty/error case + page refresh).
  5. Inspect the git diff (or your IDE's diff view) line by line.
  6. Ask the agent to explain any unfamiliar code, and demand fixes for any unapproved changes or missing checks.
  7. Commit your working feature cleanly before moving to the next feature.

6. Ready-to-Use AI Prompt​

Use this prompt to implement a single approved step, and the follow-up prompt for code explanation:

Context:
We agreed on the implementation plan for Task [number/name].

Objective:
Implement ONLY Step [A: Backend/Data OR B: Frontend Integration] of our approved plan.

Boundaries:
- Only edit the files listed in our approved plan.
- Do NOT make unrelated architectural changes, rename existing working modules, or add unapproved packages.
- Do NOT leave TODOs, mock/fake data, or hardcoded secrets.
- Follow `docs/design-direction.md` for any UI changes.

Expected Output:
1. Make the scoped file edits.
2. Summarize each file changed and why.
3. Tell me the exact commands or browser actions I should run to verify this step works.

Follow-Up Prompt (Understanding Unfamiliar Code):

Explain lines [X-Y] in `[file path]` in plain English for a beginner:
1. What data comes in and what goes out?
2. Why is this code needed for our feature?
3. What happens if something fails on line [X]?
Do NOT edit any files while explaining.

7. What to Expect from the AI Agent​

Good ResponseWarning Sign
The agent makes clean, minimal edits strictly within the planned files, explains them clearly, and lists concrete checks for you to run.The agent says "I also took the liberty of refactoring your folder structure / upgrading packages / adding dark mode" OR claims "I tested everything and it works" without actually showing real command output. Never accept unverified claims or unasked-for rewrites.

8. What You Must Personally Verify​

  • Run the app yourself in the browser and test every Acceptance Criterion (including refreshing the page and submitting bad/empty input).
  • Inspect the diff (git diff) for unintended edits to unrelated files, leftover console.log/print spam, or hardcoded secrets.
  • Understand every new concept introduced: If you don't know what a new file or function is doing, pause and make the agent explain it before accepting.

9. Common Mistakes​

  1. Letting the agent change architecture mid-feature: If an agent hits a small bug and suggests "Let's switch from SQLite to MongoDB" or "Let's rewrite the whole state system," stop! Usually the bug is a tiny 2-line typo, not an architectural flaw.
  2. Skipping backend verification before wiring the frontend: If you build both at once and something breaks, you won't know whether the bug is in the UI or the server.
  3. Leaving broken features half-finished and starting the next one: Never stack a new feature on top of a broken one. Fix or revert first.

10. Small Practical Exercise​

  1. Implement one complete small feature from your docs/development-plan.md using the two-step workflow (Backend/Data first, then Frontend integration).
  2. Run git diff in your terminal (or check your IDE's Source Control diff panel) to read every single changed line.
  3. Pick one function you don't fully understand yet and run the Follow-Up Prompt above so you can explain in your own words what it does.

Completed the exercise? Track your progress

Check off this lesson in PROGRESS-CHECKLIST.md once you have verified every step in Section 8.