Metadata-Version: 2.5
Name: repo2brief
Version: 0.3.0
Summary: Turn any codebase into an onboarding brief: architecture map, reading order, dependency graph and glossary, as one HTML page.
Project-URL: Homepage, https://github.com/rampangeni/repo2brief
Project-URL: Issues, https://github.com/rampangeni/repo2brief/issues
Author: Ram Pangeni
License: MIT
License-File: LICENSE
Keywords: architecture,codebase,dependency-graph,documentation,onboarding
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Documentation
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: pytest>=8; extra == 'dev'
Requires-Dist: ruff>=0.6; extra == 'dev'
Provides-Extra: parsers
Requires-Dist: tree-sitter-go>=0.23; extra == 'parsers'
Requires-Dist: tree-sitter-java>=0.23; extra == 'parsers'
Requires-Dist: tree-sitter-javascript>=0.23; extra == 'parsers'
Requires-Dist: tree-sitter-kotlin>=1.0; extra == 'parsers'
Requires-Dist: tree-sitter-rust>=0.23; extra == 'parsers'
Requires-Dist: tree-sitter-typescript>=0.23; extra == 'parsers'
Requires-Dist: tree-sitter>=0.23; extra == 'parsers'
Description-Content-Type: text/markdown

# repo2brief

**Understand an unfamiliar codebase in 10 minutes.** Point it at a repo and get one shareable page: where to
start reading, an architecture map, an interactive dependency graph, entry points, hotspots and a glossary of
the project's own vocabulary.

```bash
uvx repo2brief .                 # writes repo2brief-<name>.html, no install needed
repo2brief . --open              # ...and opens it
repo2brief . -s                  # the brief in your terminal, no file
repo2brief . -f md               # BRIEF.md with a Mermaid architecture diagram (renders on GitHub)
```

![repo2brief on Flask: architecture map and module graph](docs/screenshot.png)

Live example, generated from [Flask](https://github.com/pallets/flask):
[`docs/flask-brief.html`](docs/flask-brief.html) and [`docs/flask-BRIEF.md`](docs/flask-BRIEF.md).

## What you get

| Section | What it tells you |
|---|---|
| **Start here** | A reading order: the README, how the program starts, the most depended-on modules, then one file per area |
| **Architecture map** | Directories as bubbles sized by code, arrows for "imports from"; click one to filter the graph |
| **Module graph** | Force-directed import graph; node size = how much of the code depends on it; click a module for its symbols and who imports it; search box |
| **Run it** | Entry points (`pyproject` scripts, `package.json` bin/main, `__main__` blocks, conventional names) and the documented commands (`make`, `npm run`, pytest) |
| **Hotspots** | Files that change often *and* are big or central, with main author and bus factor (from `git log`) |
| **Contributors** | How many people have committed (all-time, name variants merged by e-mail, bots counted separately), how many in the last 90 days, and a table of who does what: commits, share, active period, lines changed and the areas they work in. E-mail addresses are never printed |
| **Glossary** | Domain words that recur in names and docstrings, with where they live and what they mean |
| **Stack** | Languages by lines of code, most-used third-party packages |

No network, no LLM, no API key: it is static analysis (Python `ast`; regexes or, optionally, real tree-sitter parsers for the other languages) and
`git log`. Python 3.10+, standard library only (tree-sitter is an optional extra). A typical repo takes well under a second.

## Options

| Option | Effect |
|---|---|
| `PATH` | Repository or sub-directory to analyze (default `.`); point it at `services/api` inside a monorepo |
| `-f html\|md\|both` | Output format (default `html`) |
| `-o PATH`, `-o -` | Output file; `-` writes to stdout. With `-f both`, the name without extension |
| `-s`, `--summary-only` | Print the brief in the terminal and write no file (`--open` still shows the page) |
| `--json` | Machine-readable JSON (with `-s`: just the summary) |
| `--sections LIST` | Only some parts: `start`, `architecture`, `graph`, `run`, `hotspots`, `contributors`, `glossary`, `stack` |
| `--title TEXT` | HTML page title |
| `--open` | Open the page in your browser |
| `-q`, `--quiet` | Print nothing but the result |
| `--include-tests`, `--include-examples` | Tests and `examples/`/`docs/` code are left out by default so the graph shows the product, not its scaffolding |
| `--max-files N` | Analyze at most N source files, sampled evenly (default 3000); the page says when it sampled |
| `--parser auto\|regex\|tree-sitter` | Source reader for non-Python files (default `auto`: tree-sitter if `repo2brief[parsers]` is installed) |
| `--diff REF` | PR view: what this checkout changes compared with `REF` (branch, tag or commit; uses the merge-base). Lists new/removed modules and imports, new dependencies between areas, new third-party packages, touched hotspots and how many other modules import the changed code. Works with `-f md`, `-s`, `--json`; e.g. `repo2brief --diff main -f md -o PR-BRIEF.md` |
| `--summarize`, `--llm`, `--llm-model`, `--llm-dry-run` | Optional AI-written overview and area descriptions (see below). Off by default |
| `--exclude GLOB` | Leave matching files out (repeatable): `--exclude '**/generated/**' --exclude '*.pb.go'` |
| `--config PATH`, `--no-config`, `--init-config` | Use a settings file, ignore all of them, or write a commented `repo2brief.yml` here |
| `--no-emails` | Leave contributors' e-mail addresses out of the output (worth using before sharing the page publicly) |
| `--no-cache`, `--clear-cache` | Re-analyze instead of reusing the stored result for this commit; delete all stored results |
| `--no-git` | Skip git history (no hotspots, contributors or bus factor) |

## Languages

| Language | Support |
|---|---|
| Python | Imports (absolute, relative, `from pkg import submodule`, `src/` layouts), classes, functions, docstrings, `__main__` blocks |
| JavaScript / TypeScript | `import`/`export`/`require`/dynamic `import()`, relative paths with extension and `index` probing, `.js` specifiers that point at `.ts` files |
| Java / Kotlin | `import` (including wildcards and static imports), same-package references (no import needed in Java), classes and Kotlin top-level functions, `main` and `@SpringBootApplication`, Maven/Gradle commands, Android/Spring/Ktor detection |
| Go | Packages resolved through `go.mod` (a package is represented by its main file), exported types and functions, `package main`, third-party modules |
| Rust | `mod` declarations, `use` trees (`crate::`, `super::`, `self::`, workspace crates), public items, `main.rs`, `Cargo.toml` metadata |
| Everything else | Counted in the language breakdown; no import graph yet. Extractors are small, see [`extract/`](src/repo2brief/extract) |

## Parsers

By default repo2brief uses tree-sitter when the extra is installed and regexes otherwise (`--parser auto`).
`--parser regex` forces the dependency-free path; `--parser tree-sitter` fails with a clear message if
`repo2brief[parsers]` is missing. The terminal summary says which parser read how many files. On real repos
(okhttp, ripgrep) the two agree on almost everything; tree-sitter mainly removes links that came from comments.
Python always uses the standard-library `ast`.

## Configuration

Keep a project's options in a file instead of on the command line:

```bash
repo2brief --init-config        # writes a commented repo2brief.yml
```

```yaml
# repo2brief.yml
format: both
include_tests: false
max_files: 5000
emails: false
exclude:
  - "**/generated/**"
  - "*.pb.go"
llm:
  enabled: false
```

Settings are read from `~/.config/repo2brief/config.yml`, then `repo2brief.yml` or `.repo2brief.yml` in the analysed
folder or a parent (up to the git root), then `--config PATH`; each layer overrides the one before, and command-line
flags override everything (`--no-config` skips all files). Keys: `format`, `title`, `output`, `open`, `quiet`,
`include_tests`, `include_examples`, `max_files`, `parser`, `git`, `emails`, `cache`, `sections`, `exclude`, and
`llm: {enabled, provider, model}`. Unknown keys and bad values are reported with the file name. A file can only turn
options on; to switch one off for a single run, use `--no-config` or edit the file. API keys are refused in the file on purpose: use
`ANTHROPIC_API_KEY` / `OPENAI_API_KEY`. Exclude patterns are gitignore-style: no `/` matches a file name anywhere,
a trailing `/` means a folder, `**` crosses folders. A small YAML subset is built in; if PyYAML is installed it is used instead.

## Optional AI prose

```bash
export ANTHROPIC_API_KEY=...            # or OPENAI_API_KEY (+ OPENAI_BASE_URL for Ollama, vLLM, LM Studio...)
repo2brief --summarize                  # adds an overview paragraph and plainer area descriptions
repo2brief --llm-dry-run                # print exactly what would be sent; sends nothing
repo2brief --summarize --llm openai --llm-model llama3   # any OpenAI-compatible server, including a local one
```

Everything works without it; this is the only feature that can contact a network, and only when you pass
`--summarize`. What is sent is a compact outline: the README excerpt, area names, file paths, the first line of module
docstrings, public symbol names, entry points and framework names. **No source code and no e-mail addresses.** The
text is labelled "AI-written" in the HTML, Markdown and terminal output, and if the call fails you get the normal brief
with a warning. Default model for Anthropic is `claude-haiku-5-5` (override with `--llm-model` or `REPO2BRIEF_MODEL`).

## Reviewing a branch

```bash
repo2brief --diff main          # HTML page: repo2brief-<name>-diff.html
repo2brief --diff main -s       # short terminal version
repo2brief --diff origin/main -f md -o PR-BRIEF.md   # paste into a PR description
```

The base is exported with `git archive` into a temp folder and analysed with the same extractors as your checkout,
so the comparison is like for like and your working tree is never touched. Uncommitted edits to tracked files and
new files count as part of the change.

## Caching

On a clean git checkout (nothing modified, staged or untracked under the folder) the finished analysis is stored
per commit in `~/.cache/repo2brief` (or `$XDG_CACHE_HOME`, or `$REPO2BRIEF_CACHE_DIR`), so running it again on the
same commit is near-instant; the output says when it reused one. The key also covers every option and the
repo2brief version, and a dirty working tree is never cached. Nothing is ever written inside your repository.

## How it works

`git ls-files` (or a filtered walk) finds the files; extractors pull out imports, symbols and doc comments;
imports are resolved to files in the repo; PageRank over the import graph says which modules everything leans on;
directories become architecture clusters; `git log --numstat` adds churn and ownership; a TF-IDF-style score finds
the glossary terms.

## Limits (read before trusting a graph)

- Dynamic imports, plugin registries, dependency injection and generated code are invisible to static analysis.
- Without the `parsers` extra, JavaScript, Java, Kotlin, Go and Rust are read with regexes: unusual syntax can be missed and a class name mentioned only in a comment can add a false link. With it (`pip install "repo2brief[parsers]"`) they are parsed with tree-sitter, which ignores comments and strings; files a grammar cannot parse fall back to the regexes. Webpack/Vite aliases that are not in a tsconfig/jsconfig are not resolved (except `@/` and `~/`).
- Java/Kotlin same-package links come from capitalized names that match a sibling class, so a class named like a common word can add a false link.
- "Hotspots" and "bus factor" reflect the last 3000 non-merge commits and count commits, not effort.
- The glossary is heuristic. Expect a few generic words.

## Development

```bash
pip install -e ".[dev]"
ruff check . && pytest
```

## Roadmap

- [x] Python and JavaScript/TypeScript extractors, ranking, clusters, git signals, glossary
- [x] HTML, Markdown (Mermaid) and terminal output; `--json`; `--sections`
- [x] Java, Kotlin, Go and Rust extractors
- [ ] C#, PHP, Ruby, Swift extractors
- [x] Optional LLM pass for prose summaries (bring your own key)
- [x] Cache keyed by commit hash for instant re-runs
- [x] tsconfig / jsconfig `paths` and `baseUrl` aliases (including `extends`)

## Contributing

Issues and PRs welcome. A new language is one module in `src/repo2brief/extract/` that returns a `Module`
(imports, symbols, doc) plus a resolver in `resolve.py`.

## License

MIT
