Skip to content

How to read an unfamiliar codebase: a step-by-step method

A practical method for understanding code you didn't write: start from behaviour, find entry points, trace one path end to end, and build a map you can trust.

October 13, 2026 · 3 min read · RepoGrasp team

Reading a codebase you didn't write is a skill, and most of us were never taught it. The usual approach, opening files in alphabetical order or starting with whichever one looks important, wastes hours. Here is a method that works on almost any repository, from a small library to a large application.

1. Decide what you need to understand

"Understand the codebase" is too big to be a goal. Pick one behaviour: "what happens when a user signs up?", "how does this library parse a config file?", "where is the price of an order calculated?" A concrete question tells you which code matters and lets you ignore the rest for now.

2. Read the outside first

Before any source file, spend ten minutes on:

  • The README and docs folder. What does the project claim to do, and how is it run?
  • package.json. Scripts tell you how it starts and tests. Dependencies tell you the stack: a web framework, an ORM, a queue.
  • The folder structure. Two levels deep is enough. Names like routes, services, models or features reveal the architecture.
  • Configuration files. next.config.ts, docker-compose.yml, .env.example: these describe the environment the code expects.

Our codebase guides list the signals and usual layout for more than 70 JavaScript and TypeScript stacks.

3. Find the entry point for your question

Every behaviour starts somewhere: a route, a CLI command, an event handler, an exported function. Ways to find it:

  • Search for a string the user sees, such as a button label or an error message.
  • Search for the URL path, such as /api/signup.
  • Follow the start script or the main, bin or exports field.

We cover this in detail in how to find the entry point.

4. Trace one path end to end

From the entry point, follow the code in execution order, not file order. At each step, note three things: the file and line, what the step does in one sentence, and what it hands to the next step. Resist detours. When you meet a function you don't understand, write its name down and keep going unless the path depends on it.

The result is a list like this:

  1. routes/signup.ts:14: validates email and password
  2. services/users.ts:40: hashes the password, creates the user
  3. db/users.ts:22: inserts the row
  4. jobs/welcome.ts:8: queues the welcome email

That list is the most valuable artifact of reading. See tracing a request end to end.

5. Read the tests for that path

Tests show how code is meant to be called and what the authors thought could go wrong. They often reveal edge cases you'd never infer from the code. See reading tests as documentation.

6. Run it, if you can

Nothing confirms understanding like running the code and watching it. Set a breakpoint at the entry point, trigger the behaviour, and step through. If running it is hard, a log line at each step of your list works too.

7. Widen the map gradually

Once one path is clear, pick a neighbouring behaviour. Paths share infrastructure (auth, data access, error handling), so each new path is faster to follow than the last. After four or five, you'll have a working model of the architecture.

Where AI helps, and where it doesn't

A tool like RepoGrasp can do steps 3 and 4 for you as a first draft: ask "what happens when a user signs up?" and you get the path with file:line citations. That draft is a hypothesis, not a conclusion. Open each cited line and confirm it, exactly as you would with notes from a colleague. AI saves the searching; the reading is still yours.

Common mistakes

  • Reading breadth-first. Skimming every file gives a vague sense of everything and a working understanding of nothing.
  • Trusting names. validateUser might also send an email. Read the body.
  • Ignoring configuration. Environment variables and feature flags can change which path runs.
  • Not writing anything down. Your memory of a call path fades by tomorrow; your list doesn't.

A checklist

  • One concrete question chosen
  • README, scripts, dependencies and folders skimmed
  • Entry point found
  • Path traced with file:line for each step
  • Tests for the path read
  • Path confirmed by running or logging
  • Notes saved somewhere others can find them

Try asking RepoGrasp your first question to get a cited draft of step 4.