Module 01 · Lesson 1.1
Reading an Unfamiliar Codebase
On this page
Nobody joins an established codebase by reading it from top to bottom, and nobody needs to. What you need is a picture accurate enough to make your first change safely: what the system does, how it is put together, where change and risk concentrate, and which of your beliefs you have actually checked.
This lesson gives you a repeatable way to build that picture. You will read with a specific question in mind, start from the files that describe how the system is built and run, use version history as evidence, and treat an AI assistant as a reading companion whose explanations you confirm before relying on them.
The examples in this program follow Tidewell Wholesale, a fictional supplier of catering goods to cafés and restaurants, and its order-management service tidewell-orders: a Python and Django application with a PostgreSQL database, background workers and years of history. The company, its staff and its data are invented.
What you will learn
- Write a reading question that keeps exploration focused on the change you need to make.
- Inventory a repository from its build files, layout and recent history.
- Keep a reading log that separates facts, hypotheses and questions, with evidence for every fact.
- Use an AI assistant to propose explanations, and verify each one before relying on it.
Before you start
- Comfortable reading code in at least one mainstream language; the examples use Python.
- Git and a POSIX-style shell. On Windows, Git Bash or WSL works for every command shown.
- A repository you are allowed to study, such as an open-source project. If you are unsure what you may share with an AI service, read Sharing Code with an AI Assistant Safely first.
- Any capable AI coding assistant that is approved for the code you will read.
Read for a question, not for coverage
Experienced developers alternate between two moves. Reconnaissance is breadth-first: what the parts are, how they are wired together, and how the system is built, tested and deployed. Tracing is depth-first: following one request or job all the way to the database and back. The map tells you where to trace; tracing corrects the map.
Both moves are steered by a reading question: the specific thing you need to know for your next piece of work. 'How does this system work?' has no finish line. 'Where is an order validated and totalled before it is accepted?' does, and it also tells you which files you can safely ignore for now.
As you read, keep three kinds of note apart in a reading log, a plain text file that travels with you through the module. The most dangerous belief about a legacy system is one you cannot remember having checked.
- Fact
- Something you confirmed by reading code, running it or checking history, recorded with its evidence: a file and line, a command and its output, or a commit.
- Hypothesis
- A plausible explanation you have not confirmed yet, including everything an AI assistant tells you. Note what evidence would settle it.
- Question
- Something the code cannot answer, usually about intent or usage, such as 'Does anyone still use the weekly export?' Questions go to people.
- Hotspot
- A file that changes often or that much of the system depends on. Defects and merge conflicts often gather in hotspots, so they deserve careful reading early.
Worked scenario: first sessions in tidewell-orders
You have joined Tidewell's platform team. Your first task is to add a minimum order value for trade customers on the Standard price band, so that smaller orders are rejected by the trade portal with a clear message. Nobody who wrote the order code is still on the team.
Your reading question is: Where is an order validated and totalled before it is accepted, and what else depends on that total? You allow yourself two sessions of reconnaissance before reading any order code in depth.
The README describes a setup that no longer works: it asks for a Python version that the dependency file does not allow. That is useful in itself. It tells you the README is not maintained, and that the CI configuration, which has to work for every build, is the more honest description of how the service runs. After an inventory and a look at the last year of history, your reading log contains these entries.
| Note | Kind | Evidence |
|---|---|---|
| A Django project with apps for orders, customers, catalogue, stock, invoicing, dispatch and legacy | Fact | INSTALLED_APPS in tidewell/settings/base.py |
| Background work runs on Celery workers with a Redis broker | Fact | tidewell/celery.py; the worker service in docker-compose.yml |
orders/services.py and invoicing/totals.py changed more often than any other files in the last year | Fact | The history command in step 4 of the workflow |
Order totals are calculated in invoicing/totals.py | Hypothesis | Suggested by the assistant from file names; confirm by tracing one order |
legacy/pricing_v1.py is dead code | Refuted | git grep finds an import of it in invoicing/totals.py |
| Is the weekly CSV export to the accounts team still used? | Question | Ask the finance systems contact |
Two things stand out. The belief that the legacy pricing module was unused, which seemed plausible to you and to the assistant, took one search to refute. And both hotspots sit directly on your reading question, so the second session should trace one portal order through orders/services.py into invoicing/totals.py.
Step-by-step workflow
Step 1: Write the reading question down
Tie it to real work. If you have no task yet, pick a behaviour users care about, such as 'How does a customer receive an invoice?' Put the question at the top of your reading log.
What you should see: A question with an obvious finish line.
Step 2: Read the build and run files
Open the dependency manifest, container and compose files, CI pipeline, task scripts and settings. These must work for the system to ship, so they are usually more accurate than prose documentation. Note runtime versions, external services such as databases, queues and email, and how configuration is supplied.
What you should see: A list of runtime components, each with the file that told you about it.
Step 3: Inventory the layout
Count tracked files per top-level directory to see where the code really is.
git ls-fileslists only files under version control, so build output and virtual environments do not distort the picture.Bash # Tracked files per top-level directory, largest first git ls-files | cut -d/ -f1 | sort | uniq -c | sort -rn | head -15What you should see: Directories ranked by the number of tracked files they contain.
Step 4: Find the hotspots
Count how often each file changed in the last year. A small directory that changes every week deserves attention before a large one that nobody touches.
Bash # Files ranked by how many commits touched them in the last year git log --since="12 months ago" --no-merges --format=format: --name-only \ | grep -v '^$' | sort | uniq -c | sort -rn | head -15What you should see: A ranked list of files; the top entries are candidates for careful reading.
Step 5: Take a baseline
Build the service and run its tests before changing anything. Record what passes, fails and is skipped, with the commit hash. A failure that predates you is a fact about the system; without a baseline you will later mistake it for something you broke.
What you should see: A dated note such as 'API tests pass; 3 invoicing tests fail; 27 skipped; commit 4f9c2e1'.
Step 6: Trace one path and consult the assistant
Follow one entry point related to your question down to storage; Mapping Entry Points and Data Flow covers this in depth. Give the assistant what you have gathered, using the prompt card below, and add its explanations to your log as hypotheses.
What you should see: One call sequence with file paths, and new hypotheses to check.
Step 7: Sort your notes
End each session by promoting hypotheses that now have evidence, marking refuted ones, and sending your questions to the people who can answer them.
What you should see: A reading log you could hand to a colleague.
- Reading question
What do I need for this change?
- Build and run files
Versions, services, configuration
- Inventory and hotspots
Where the code is and where it changes
- Baseline
Test results before any change
- Trace and consult
One real path; assistant as companion
- Sorted log
Facts, hypotheses, questions
The next session starts from the open hypotheses and questions this one leaves behind.
Using history and search as evidence
Version history answers questions the code cannot: when a behaviour changed, what changed with it, and who might remember why. git blame attributes each line to the commit that last changed it. Its -w option ignores whitespace-only edits and -C follows lines moved from other files, so a reformatting commit does not hide where the logic really came from. git grep searches only tracked files.
# Where did these lines of the total calculation come from?
git blame -w -C -L 40,80 invoicing/totals.py
# How has the file evolved? One line per commit, newest first.
git log --follow --date=short --format="%h %ad %s" -- invoicing/totals.py
# Is the legacy pricing module really unused?
git grep -n pricing_v1 -- "*.py"Questions answered from history rather than guessed.
invoicing/totals.py:7:from legacy.pricing_v1 import contract_unit_priceHistory is also a good thing to hand an assistant. Paste one commit's message and diff and ask what behaviour it changed: all the evidence is in the prompt, so its answer is easy for you to check.
Reusable prompt
Codebase reading companion
Turns the first material you gather about a repository into tagged facts, checkable hypotheses and a short reading list.
I am new to an existing codebase and need to make a change safely. Act as a careful reading companion, not an authority.
Reading question: Where is an order validated and totalled before it is accepted, and what else depends on that total?
Material (the README may be out of date):
--- Directory tree, two levels ---
api/ catalogue/ customers/ dispatch/ invoicing/ legacy/ orders/ stock/
tidewell/ (celery.py, urls.py, settings/base.py, settings/local.py, settings/production.py)
tests/ scripts/ docker-compose.yml manage.py pyproject.toml README.md
--- pyproject.toml (excerpt) ---
requires-python = ">=3.11"
dependencies: django, psycopg, celery, redis, requests, pytest
--- README.md (excerpt) ---
Tidewell order service. Install Python 3.8, then run make setup. Portal endpoints live under /api/.
Using only this material:
1. Describe what the system appears to do and its main parts. Tag each claim FACT (directly visible; name the file) or HYPOTHESIS (inferred).
2. For each hypothesis, say what evidence would confirm or refute it, and where I should look.
3. List the five files I should read first for my reading question, with one sentence each on why.
4. List what you cannot determine from this material.
Point out any contradictions in the material. Do not invent files that are not in the tree.Show the reusable template
Replace each {{placeholder}} with your own details.
I am new to an existing codebase and need to make a change safely. Act as a careful reading companion, not an authority.
Reading question: {{reading_question}}
Material (documentation may be out of date):
--- Directory tree, two levels ---
{{directory_tree}}
--- Dependency manifest ---
{{dependency_manifest}}
--- README ---
{{readme}}
Using only this material:
1. Describe what the system appears to do and its main parts. Tag each claim FACT (directly visible; name the file) or HYPOTHESIS (inferred).
2. For each hypothesis, say what evidence would confirm or refute it, and where I should look.
3. List the five files I should read first for my reading question, with one sentence each on why.
4. List what you cannot determine from this material.
Point out any contradictions in the material. Do not invent files that are not in the tree.Expected output and limitations
Four labelled parts: a description of the system with every claim tagged FACT or HYPOTHESIS and tied to a file; the evidence that would settle each hypothesis; a prioritised list of about five files with reasons; and an explicit list of unknowns. A useful response names your directories rather than generic layers, and notices contradictions such as the README's Python version.
1. What the system appears to do
- FACT: A Django project (manage.py; django in pyproject.toml) with apps for orders, customers, catalogue, stock, invoicing and dispatch.
- FACT: Background work uses Celery with Redis (tidewell/celery.py; celery and redis in the dependencies).
- HYPOTHESIS: The api app serves the trade portal (README: "Portal endpoints live under /api/").
- HYPOTHESIS: legacy/ holds superseded code that may still be imported.
- Contradiction: the README asks for Python 3.8, but pyproject.toml requires 3.11 or later, so the README is probably stale.
2. How to check the hypotheses
- legacy/ still in use: search for imports of modules in legacy/.
- Totals calculated in invoicing/: find which function the order-creation path calls.
3. Read first
1. orders/services.py - likely order creation and validation.
2. invoicing/totals.py - likely total calculation.
3. api/views.py - the portal's way into order creation.
4. orders/models.py - order fields and statuses.
5. tidewell/settings/base.py - installed apps and integrations.
4. Cannot determine
- Which code paths run in production, and how often.
- Whether anything outside this repository, such as cron jobs or other services, calls in.Limitations to keep in mind
- The assistant sees only what you paste. Scheduled jobs, other services and configuration that live outside the repository are invisible to it.
- Names suggest purpose but do not prove it; a hypothesis built only on file names stays weak until you trace it.
- It describes unused code as confidently as code that runs in production. Only search, history and running the system tell them apart.
- Responses vary between runs and between assistants. Tagging makes an answer easier to check, not automatically correct.
Common errors and how to fix them
Reading files alphabetically, or reading everything
Why it happens: There is no reading question, so every file seems equally important.
Fix: Write a question tied to real work and read only what moves you towards answering it.
Treating the assistant's summary as documentation
Why it happens: The explanation is fluent and plausible, so it gets filed as fact.
Fix: Log every assistant claim as a hypothesis and promote it only with evidence you checked yourself.
Blaming yourself for failures that were already there
Why it happens: No baseline was taken before the first change.
Fix: Run the suite on an untouched checkout and record the results with the commit hash.
Validation checklist
Tick each item once you have confirmed it.
Hands-on exercise
First-session reading log
Choose a repository you have not worked in before and are permitted to study. In one session of about 90 minutes, produce a reading log for a realistic change by following this lesson's workflow.
You will need
- A repository you may study: an open-source application in a language you can read (check its licence first), or your employer's code if policy allows you to use it with your approved assistant.
- A realistic change: a small open issue from the project's tracker, or a plausible feature request you invent.
- The prompt template from this lesson.
Acceptance criteria
Your work is done when every one of these is true.
Hints (2)
- If the build fails, record that as a fact and move on; do not lose the whole session to setup.
- A refuted hypothesis is a good result: it is a mistake you will not make when you change the code.
Show a model answer
A strong log reads like a lab notebook, not an essay. It starts with a narrow question, such as 'Where are uploaded files validated, and what rejects an oversized file?' Its facts are few but precise: the framework version from the manifest, external services from the compose file, and hotspots with the command that produced them, each of which someone else could re-check. Hypotheses are falsifiable ('Validation happens only in the upload view') and name the search or file that would settle them. Strong logs often show an assistant claim being refuted, which is the habit doing its job. The baseline names a commit. Weak logs describe the architecture at length with no evidence column, or list the files that were read without any conclusions.
Knowledge check
Choose an answer, then check it. Nothing is recorded — this is for you.
Show the answer and explanation
Answer: C. The third question is tied to the change and has a finish line, so it tells you what to read and what to skip. 'How does this system work?' is tempting because it sounds thorough, but it never ends and gives you no way to prioritise. Framework and file-size facts are useful inventory, but they are steps towards an answer, not a question.
Show the answer and explanation
Answer: A. From a tree, the assistant can only infer from names, so its claim is a hypothesis that
git grep -n pricing_v1settles in seconds. Agreement between the name and the assistant is tempting, but both are guesses drawn from the same evidence. Deleting the file tests only what the suite covers, which in legacy code may be very little, and asking again simply repeats the guess.Show the answer and explanation
Answer: B. A baseline separates the system's existing problems from the effects of your change. Without one, an old failure looks like a regression you introduced, or a real regression hides among old failures. Coverage reporting is a different activity, and the last two options describe things that are not generally true.
- Written by
- PromptFable Editorial
- Last updated 13 Nov 2026
- Review
- Reviewed by Waseem Nadir, Technical Reviewer
- Last reviewed 27 Nov 2026
References
Primary sources for the technical details in this lesson. Vendor platforms change — check the official page if anything here looks different from what you see.
- git-log Documentation(opens in a new tab)
Git project · Official documentation
- git-blame Documentation(opens in a new tab)
Git project · Official documentation · Options -w, -C and -L used in this lesson.
- git-grep Documentation(opens in a new tab)
Git project · Official documentation
- git-ls-files Documentation(opens in a new tab)
Git project · Official documentation
- git-shortlog Documentation(opens in a new tab)
Git project · Official documentation
PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.