---
name: understand-codebase
description: Build a useful map of an unfamiliar codebase area. Use when the user wants to understand how code works, where behavior lives, what calls what, or how a feature/module fits into the bigger picture.
title: understand-codebase
canonical_url: https://skilld.dev/gh/bity-labs/tstack/understand-codebase
last_updated: 2026-09-29T03:52:13.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install bity-labs/tstack/understand-codebase`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/understand-codebase`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/bity-labs/tstack/understand-codebase) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/understand-codebase`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/understand-codebase --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/understand-codebase --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

# Understand Codebase

Map an unfamiliar area of code so the user can reason about it safely before changing, debugging, reviewing, or planning work.

This skill explains the current shape of the code. It does not refactor, diagnose, review, or propose architecture work unless the user explicitly asks for that next step.

## Read These First

1. `docs/context.md` — domain language and project model
2. Relevant `docs/adr/` files — decisions that explain why the code is shaped this way
3. `docs/coding-standards.md` — project conventions
4. Relevant files under `docs/engineering/` only if the question touches a specific risk area:
   - `architecture-boundaries.md` for layers, adapters, or dependency direction
   - `domain-modeling.md` for business terms, states, or rules
   - `data-modeling.md` for schemas, persistence, or ownership
   - `legacy-code.md` for risky or poorly understood code

If a doc is missing, say so and continue from code evidence.

## Workflow

### 1. Clarify the Area

Identify what the user wants to understand.

Examples:

- a feature
- a module or package
- a function or class
- a failing behavior's surrounding code
- a PR's touched area
- an integration with an external system

If the request is broad, pick the smallest useful entry point and say what you are using as the starting point.

### 2. Load Project Language

Read the project context and relevant ADRs before naming concepts.

Look for:

- domain terms the code should use
- important states and invariants
- external systems and integration boundaries
- decisions that explain current tradeoffs
- words that are overloaded or inconsistent between docs and code

Use the project's language. Do not invent new names when the project already has them.

### 3. Find Entry Points

Start from the user's file, route, command, test, issue, or feature name.

Then trace outward:

- callers
- callees
- imports and exports
- public APIs or route handlers
- persistence/schema touchpoints
- external service boundaries
- tests that describe expected behavior

Prefer code search and targeted reads over opening many unrelated files.

### 4. Build the Map

Explain the area at the right level of abstraction.

Include:

- what this area is responsible for
- which files/modules matter and why
- how control flows through the system
- how data flows or changes shape
- which domain terms map to which code concepts
- what boundaries or seams exist
- what behavior is covered by tests
- what is still unknown or ambiguous

Distinguish facts from guesses. If something is inferred, label it as an inference.

### 5. Avoid Scope Drift

Do not turn this into a different workflow by default.

- Do not fix bugs; recommend `debug` if a root-cause investigation is needed.
- Do not review a PR; recommend `code-review` if review is needed.
- Do not refactor; recommend `refactor-safely` if the user wants changes.
- Do not create architecture issues; recommend `inspect-architecture` if broad architecture friction is found.
- Do not write a PRD; recommend `write-prd` if the user wants specification.

It is fine to mention risks, smells, or suspicious areas, but keep them as notes unless the user asks to act.

### 6. Produce the Codebase Map

Output:

```md
# Codebase Understanding Map

## Question / Scope
<what was investigated>

## Short Answer
<the useful high-level explanation in a few sentences>

## Key Files and Modules
- `<path>` — <why it matters>

## Flow
<call flow, data flow, state transitions, or lifecycle>

## Domain Language
- <project term> — <where it appears in code and what it means>

## Boundaries and Seams
<APIs, adapters, persistence boundaries, external systems, test seams>

## Tests / Validation Clues
<tests, fixtures, commands, or missing coverage relevant to understanding behavior>

## Unknowns and Caveats
<what is not yet proven, missing docs, ambiguous names, or assumptions>

## Where To Look Next
<small set of next files/questions depending on what the user wants to do>
```

Keep the report compact. The goal is orientation, not exhaustive documentation.
