---
name: codebase-map
description: Understand an unfamiliar codebase fast, the way senior engineers do. Reads the orientation signals (README, manifests, CI, Dockerfiles, routes, migrations), mines git history for hotspots, hidden coupling and ownership, builds the import graph to find layers, cycles, load-bearing and dead code, then traces one real request or command end to end by actually running it. Writes MAP.md with a one-paragraph purpose, a Mermaid architecture diagram, the traced path as file:line hops, hotspot and coupling tables, a glossary, gotchas and first tasks, plus an optional SVG. Use when the user says "explain this codebase", "I'm new to this repo", "map the architecture", "onboard me", "where does X happen", "how is this project structured", or joins a new team or project.
title: codebase-map
canonical_url: https://skilld.dev/gh/dotslashsimran/simcraft/codebase-map
last_updated: 2026-11-12T02:34:47.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.
>
> Supporting files, fetch one when the Skill refers to it: [examples/MAP.md](https://skilld.dev/api/skills-raw/dotslashsimran/simcraft/codebase-map/examples/MAP.md), [reference.md](https://skilld.dev/api/skills-raw/dotslashsimran/simcraft/codebase-map/reference.md), [scripts/check_map.py](https://skilld.dev/api/skills-raw/dotslashsimran/simcraft/codebase-map/scripts/check_map.py), [scripts/common.py](https://skilld.dev/api/skills-raw/dotslashsimran/simcraft/codebase-map/scripts/common.py), [scripts/deps.py](https://skilld.dev/api/skills-raw/dotslashsimran/simcraft/codebase-map/scripts/deps.py), [scripts/entrypoints.py](https://skilld.dev/api/skills-raw/dotslashsimran/simcraft/codebase-map/scripts/entrypoints.py), [scripts/hotspots.py](https://skilld.dev/api/skills-raw/dotslashsimran/simcraft/codebase-map/scripts/hotspots.py), [scripts/trace_py.py](https://skilld.dev/api/skills-raw/dotslashsimran/simcraft/codebase-map/scripts/trace_py.py).
>
> If the user asked to install this Skill, run `npx skilld install dotslashsimran/simcraft/codebase-map`. 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/codebase-map`, 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/dotslashsimran/simcraft/codebase-map) 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/codebase-map`. 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/codebase-map --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/codebase-map --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.

# Codebase map

Reading files top to bottom is the slow way in. Senior engineers ask four questions instead, in this order: **what does it do, how is it run, where does the important work happen, and what path does one real request take.** The first three come from cheap signals (manifests, CI, git history, imports). The fourth only comes from running the code. Everything ends up in one file, `MAP.md`, that a new person can read in ten minutes.

Work **read-only** on the repo. Put every output in a temp folder (`out=$(mktemp -d)`) unless the user asks for `MAP.md` in the repo. Never run migrations, deploys or anything that touches a shared database or real credentials.

Scripts are in `scripts/`, Python 3.9+ standard library and git only. `S=~/simcraft/skills/coding/codebase-map/scripts`.

## 0. Ask one thing

"Is there a specific thing you need to do here (fix a bug, own an area, review a change), or a general map?" A goal decides which path to trace. If there is no answer, map the whole repo and trace its most important user action.

## 1. Orient (15 minutes)

```
python3 $S/entrypoints.py <repo> > $out/entry.md
```
It lists docs to read first, build and run commands (package.json scripts, console scripts, Makefile, Procfile, Dockerfile CMD, compose services), CI pipelines and the commands they run, mains, servers, CLI commands, HTTP routes, background jobs, the data model, environment variables (with a flag when the `.env` template is missing one), and tests. Every hit is `file:line`.

Then read, in this order: README and contributor docs, **the CI file** (it is the only build recipe that is known to work), the main manifest, the entrypoint files. Write the **one-paragraph purpose** now, before reading more code: who uses it, what goes in, what comes out, what it talks to.

## 2. The data model is the backbone

Read the schema before the logic. Migrations (oldest shows the original core, newest shows where the product is going), ORM models, Prisma or SQL files, or, if there is no database, the main data shapes (pydantic models, TS types, JSON files on disk). Write down the 3 to 7 core entities and how they relate. Most business logic is "load these, change them, save them", so knowing the nouns makes the code readable.

## 3. Structure from imports

```
python3 $S/deps.py <repo> --json $out/deps.json --mermaid $out/deps.mmd --svg $out/deps.svg > $out/deps.md
```
Read: the **layers** (level 0 is the foundation, top is entry code), **folder cycles** (tangled modules, with the cheapest edge to cut), **load-bearing files** (most importers: change carefully), **possibly dead files** (no importers), and the main external packages. If one folder holds most of the code, run again with `--under <that folder>` to see inside it.

## 4. History: where the work and the risk are

```
python3 $S/hotspots.py <repo> --deps $out/deps.json > $out/hot.md
```
- **Hotspots** (changes x complexity): the few files where most bugs and most of your future work will be.
- **Change coupling**: files that change in the same commits. A pair with `import link = NO` is a hidden dependency, for example two copies of the same logic, or a client and server that share a format. These are the best gotchas.
- **Ownership** and **knowledge at risk**: who to ask about each area, and complex files whose main author has gone quiet.
- **Bug magnets**, **frozen code** and **new code**.

Add `--anonymize` if the map will be shared outside the team. Under about 30 commits, git signals are weak: say so and lean on steps 3 and 5.

## 5. Trace one real path by running it

This is the step that turns guesses into knowledge. Pick one real user action (the one the top hotspots serve, or the user's goal). Get it running using the CI steps. Then either:
- find the **sink** (the DB write, the HTTP response, the output file), put a stack dump or breakpoint there (`breakpoint()`, `traceback.print_stack()`, `console.trace()`, `debug.PrintStack()`), trigger the action once, and read the stack bottom-up; or
- for Python, run it under the tracer: `python3 $S/trace_py.py --repo <repo> --out $out/trace.txt -- <script or -m module> <args>`. It prints every repo function the run touched, by depth, as `file:line`.

If the path calls paid or external services, stub them at the edge (patch the HTTP call to return a canned response) instead of using real keys. Record each hop as `file:line  what happens here`, and mark anything surprising.

## 6. Load-bearing vs dead

Load-bearing = many importers, on the traced path, or a hotspot. Dead candidates = no importers and frozen for a year. Before calling anything dead, grep for its name as a string (plugin registries, `getattr`, dynamic imports, config files, framework conventions). Say "probably dead, because..." rather than "dead".

## 7. Write MAP.md

Use the template in [reference.md](https://skilld.dev/api/skills-raw/dotslashsimran/simcraft/codebase-map/reference.md#mapmd-template): purpose, how to run it, architecture diagram (Mermaid, drawn from what you learned, not just the raw import graph), the traced path, data model, hotspots, coupling pairs, who knows what, glossary, gotchas, first tasks. Mark each claim **ran** (you saw it happen) or **read** (from the code). Then check every reference:
```
python3 $S/check_map.py $out/MAP.md <repo>
```
Fix every broken one. Finish with a five-line summary in chat and the path to `MAP.md` (and the SVG if made).

## Rules

- Never claim a hop you did not see in code or in a run. A wrong map is worse than none.
- Explain jargon the first time it appears, and put every project-specific term in the glossary.
- First tasks must be small, real and safe: a test to add for a hotspot, a log line on the traced path, a dead file to confirm.
- Depth, per-language tracing recipes, heuristics and their limits: [reference.md](https://skilld.dev/api/skills-raw/dotslashsimran/simcraft/codebase-map/reference.md). A real example: [examples/MAP.md](https://skilld.dev/api/skills-raw/dotslashsimran/simcraft/codebase-map/examples/MAP.md).
