Lesson 2 of 10 · Own the code AI writes
How to understand a codebase you didn't write
To understand a codebase you didn't write, start with a map: what it's built with, where pages come from, where data goes and where secrets live.
The first job with any code you didn't write isn't to read it. It's to find your way around it. You want a rough map before you look closely at anything: what the project is built with, where the pages come from, where the data goes, and where the secrets are.
Give it twenty minutes. Open the project folder in a code editor (VS Code is free and fine) and keep a notes file open beside it.
Start with the folder list
Look at the top level of the project before you open anything. Most projects an AI builds have some of these:
README.md: how to run the project, if anyone wrote it down. An AI often writes this too, so check it's true before you trust itpackage.json: what the project is built with (more on that next)src/orapp/: where the code lives- Files ending in
.config.jsor.config.ts: settings for the tools, such asnext.config.tsorvite.config.ts .env.example: the names of the secrets the project needs, without their values.gitignore: the files Git is told to leave out of the repo
You don't need to understand them yet. You need to know they're there.
What is package.json?
Open package.json. Two parts of it matter now.
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
},
"dependencies": {
"next": "^16.0.0",
"react": "^19.2.0",
"@supabase/supabase-js": "^2.48.0",
"stripe": "^17.5.0"
}
}
scripts are the commands the project understands. dev usually runs it on your own computer (npm run dev), and build makes the version that goes live.
dependencies are code other people wrote that your project relies on. Some projects also have devDependencies, the tools used only while building it. A few names across the two tell you most of what you need:
nextmeans a Next.js app. Vercel's v0 builds thesevitewithreactmeans a React app built with Vite. Lovable builds these, and so do plenty of others@supabase/supabase-jsmeans the data and the logins live in Supabasestripemeans it takes payments through Stripe
Every name in those lists is someone else's code that your app trusts. Count them. Each new one an AI adds deserves a look, and lesson 5 shows why: sometimes the package it suggests doesn't exist.
Find where a page comes from
Pick a page of the app in your browser and find the file that makes it.
The quickest way works in any project: copy a sentence that appears on the page and search the whole project for it. In VS Code that's Cmd+Shift+F on a Mac, Ctrl+Shift+F on Windows. The file it finds is the page, or a piece of it.
It helps to know the two layouts you'll meet most:
- Next.js keeps pages in an
app/folder, a folder for each address.app/pricing/page.tsxis the page at/pricing, andapp/page.tsxis the home page. Alayout.tsxwraps every page in its folder: the header and footer usually live there. - A React app built with Vite starts at
src/main.tsx. The list of addresses is usually insrc/App.tsx, and the pages are often insrc/pages/.
Find where the data goes
Now look for the places the app talks to something outside itself. Search the project for each of these and note where they turn up:
fetch(: the app calling an address, its own or someone else'ssupabase.: reading or writing the database, or logging someone instripe.: payments/api/: in Next.js, files underapp/api/run on the server, not in the visitor's browser
That last point matters more than it looks. Some code runs on a server you control. Some is sent to every visitor's browser, where anyone can read it. In Next.js, a file that starts with "use client" is sent to the browser, and so is every file it imports. In a Vite app, almost everything is. Lesson 6 is about what must never end up there.
The files that aren't code
Three of them are worth knowing on day one:
.envor.env.localholds the secrets: API keys, database passwords. It must never be in the repo. Check that.gitignorecovers it: a line.env*covers every file whose name starts.env..env.examplelists the names of those secrets without the values, so someone else can set the project up. If it's missing, write one, and if.gitignorehas.env*, add!.env.exampleunder it so the example is saved.- The lockfile (
package-lock.json,pnpm-lock.yamloryarn.lock) pins the exact version of every dependency. It looks like noise. Don't delete it.
One more thing about secrets: a variable whose name starts with NEXT_PUBLIC_ (in Next.js) or VITE_ (in Vite) is sent to the browser on purpose. A secret key with one of those names is a secret no longer.
Write the map down
Finish with a short note, in plain English, that answers six questions:
- How do I run it on my own computer?
- What's it built with?
- Where do the pages live?
- Where does the data go, and which outside services does it use?
- Which code runs on the server, and which in the browser?
- Where are the secrets kept?
Keep that note. It's the first thing a developer you hire will need, and it's useful to the AI too. Claude Code, for one, reads a file called CLAUDE.md at the start of every session, and a map like this is a good start for one.
If you built something with AI
What to check
- Following the README alone, you can run the app on your own computer. If a step is missing, add it.
.gitignorecovers.envand.env.local, and no file in the repo holds a key or a password. Search the project forsk_live_, which is how a live Stripe secret key starts: it should find nothing.- You can say what each dependency in
package.jsonis for. One you can't explain is one to ask about. - For each page of your app, you can find the file that makes it.
- No secret has a name starting
NEXT_PUBLIC_orVITE_.
If you're learning the trade
Try it
Use a project of your own, or make a small one: create a Next.js app with npx create-next-app@latest, then ask an AI tool to add a pricing page and a contact form to it.
- Without asking the AI, write the six-question map for the project. Give yourself twenty minutes.
- Then ask the AI: "Describe the structure of this project: where the pages are, where data is sent, and what runs on the server."
- Compare its answer with your map. Where they differ, open the files and settle it.
Keep the map. The next lesson opens one of the pages on it and reads it line by line.