Skip to content

Lesson 2 of 9 · 27m

Reading Large Codebases Without Getting Lost

Use execution paths, tests, ownership boundaries, and search discipline to build a working map before changing behavior.

Large codebases are not read like novels. Nobody starts at line one and finishes enlightened. You read them like a city: identify the roads, find the neighborhood you need, learn the local customs, and leave the rest for later. The skill is selective attention under uncertainty.

Start with a concrete behavioral question

"I want to understand the repo" is too vague to finish. Better questions are:

Where does a request enter the system?
Which function validates this input?
Where is this configuration key consumed?
Which test proves the behavior I want to change?
What writes to this database table or cache key?

A concrete question gives search results meaning. It also prevents the classic failure mode: three hours of architecture tourism followed by a speculative refactor.

Build the map with cheap commands

Use fast search before clever tooling:

rg --files | head -100
rg "UserInvite|invite_user|send_invite" -n
rg "TODO|FIXME|HACK" -n src/ | head -40
git log --oneline -- src/server/invites.ts | head -20

Then inspect tests as executable documentation:

rg "invite" tests/ src/**/__tests__ -n
pytest tests/test_invites.py -q

Tests tell you what behavior is contractual, what is incidental, and which fixtures maintainers consider realistic.

Trace one path end to end

Draw the narrow pipeline you care about:

HTTP route -> request schema -> service function -> repository/query -> event/outbox -> test assertion

For each hop, record the file and line. Use runtime evidence when static reading gets circular: add a temporary log line, run a focused test under a debugger, or inspect an existing trace. Do not confuse understanding imports with understanding behavior.

Respect architectural boundaries

Most mature projects hide decisions in names: internal/, domain/, adapters/, generated/, legacy/, api/, workers/. Before editing, ask which layer owns the invariant. Controllers usually own transport parsing, services own workflow invariants, repositories own persistence, schemas own contracts, and workers own asynchronous side effects. A good patch changes the layer that owns the behavior, not merely the first place where the symptom appears.

Use history, but do not worship it

Use git log -L 80,140:src/server/invites.ts --oneline and old PR discussions privately as archaeology. Read them for constraints, not blame; compatibility requirements and incident scars often look like strange code until you find the reason.

Field notes

  • Generated code, vendored dependencies, and migration snapshots are usually not the right edit target.
  • If two subsystems implement similar behavior, the difference may be intentional compatibility debt.
  • Use rg before opening twenty tabs. Search strings users see; error messages are excellent anchors.
  • Write your map in the PR description only when it helps review. Your private archaeology is not the deliverable.

Was this lesson helpful?

Sign in to rate