# karpathy/rendergit architecture

> Architecture diagram of the GitHub repository karpathy/rendergit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/karpathy/rendergit
- Repository: https://github.com/karpathy/rendergit

## Overview

1. **Project shape**
   - This is a very small, single-purpose Python CLI tool.
   - The repository is essentially one implementation file, `rendergit.py`, plus packaging metadata (`pyproject.toml`, `uv.lock`) and documentation.

2. **Primary purpose**
   - The tool takes a GitHub repository URL and turns it into a **single static HTML page** that flattens the repo’s contents for browsing and copying.
   - It is optimized for quick code inspection, not for serving a persistent web app.

3. **Main execution flow**
   - User invokes the CLI with a GitHub repo URL.
   - The tool clones that repo into a **temporary local directory**.
   - It scans the checked-out files, applies filtering, renders content, writes a **temporary HTML file**, and opens it in the user’s browser.

4. **Repository acquisition boundary**
   - The first boundary is the **network / remote source**: the tool depends on GitHub access to clone a repo.
   - The cloned repo is treated as ephemeral input data stored locally only long enough to render output.

5. **Content processing subsystem**
   - After cloning, the code walks the repository tree and decides what to include.
   - It skips binaries and oversized files, so the output is intentionally a curated subset of the repo rather than a byte-for-byte dump.

6. **Rendering subsystem**
   - Source files are rendered with **syntax highlighting** via Pygments.
   - Markdown files such as README/docs are rendered as formatted content rather than plain text.
   - This rendering step converts heterogeneous file types into one consistent HTML document.

7. **Page structure and navigation**
   - The generated HTML contains a **directory tree summary** and a **sidebar navigation** with file links and sizes.
   - The page is designed for in-page navigation and Ctrl+F search across all content, so the final artifact is a single document rather than a multi-page site.

8. **Dual-view output model**
   - The page supports two modes:
     - **Human View**: styled HTML for browsing code.
     - **LLM View**: raw **CXML text** intended to be copied into chat-based AI tools.
   - Both views are derived from the same scanned repository data, but optimized for different consumers.

9. **Output boundary**
   - The final artifact is a **static HTML file** in a temp location.
   - There is no backend service, database, authentication layer, or persistent storage; the browser is the only UI runtime after generation.

10. **External dependencies that matter architecturally**
   - The tool relies on:
     - **Git** for cloning repositories.
     - **Pygments** for syntax highlighting.
     - Markdown rendering support for docs.
     - **uv / pip packaging** for distribution and installation.
   - These are implementation-enabling dependencies, but the architecture remains a local transform pipeline from remote repo to static HTML.

11. **Important architectural takeaway**
   - The repo’s architecture is best viewed as a **one-shot local rendering pipeline**:
     - input: GitHub repository URL
     - intermediate: temporary clone + file scan/filter
     - transform: syntax-highlighted / markdown-rendered HTML
     - output: static browser page with human and LLM views

Main entry points: [`rendergit.py`](https://github.com/karpathy/rendergit/blob/master/rendergit.py) (rendergit.py), [`pyproject.toml`](https://github.com/karpathy/rendergit/blob/master/pyproject.toml) (uv/pip)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_cli_pipeline["CLI pipeline"]
  node_rendergit_py["rendergit.py<br/>CLI entrypoint<br/>[rendergit.py]"]
  node_repo_url(("Repo URL<br/>input"))
  node_git_clone["Clone repo<br/>fetch stage"]
  node_temp_checkout["Temp checkout<br/>ephemeral workspace"]
  node_html_output["Static HTML<br/>final artifact"]
  node_browser(("Browser<br/>runtime UI"))
end

subgraph group_rendering["Rendering"]
  node_scan_filter["Scan & filter<br/>content selection"]
  node_file_selection["Included files<br/>curated input set"]
  node_render_engine["Render content<br/>transform stage"]
  node_syntax_highlight["Code view<br/>source renderer"]
  node_markdown_render["Docs view<br/>markdown renderer"]
  node_page_builder["Page layout<br/>html assembly"]
  node_human_view["Human view<br/>browsing mode"]
  node_llm_view["LLM view<br/>text mode"]
end

subgraph group_dependencies["Dependencies"]
  node_git["Git<br/>external tool"]
  node_pygments["Pygments"]
  node_markdown_support["Markdown"]
  node_uv_packaging["uv/pip<br/>packaging<br/>[pyproject.toml]"]
end

node_rendergit_py -->|"accepts"| node_repo_url
node_repo_url -->|"fetches"| node_git_clone
node_git_clone -->|"uses"| node_git
node_git_clone -->|"creates"| node_temp_checkout
node_temp_checkout -->|"scanned by"| node_scan_filter
node_scan_filter -->|"produces"| node_file_selection
node_file_selection -->|"feeds"| node_render_engine
node_render_engine -->|"routes code to"| node_syntax_highlight
node_render_engine -->|"routes docs to"| node_markdown_render
node_syntax_highlight -->|"uses"| node_pygments
node_markdown_render -->|"uses"| node_markdown_support
node_render_engine -->|"assembles into"| node_page_builder
node_page_builder -->|"includes"| node_human_view
node_page_builder -->|"includes"| node_llm_view
node_page_builder -->|"writes"| node_html_output
node_html_output -->|"opens in"| node_browser
node_rendergit_py -.->|"distributed via"| node_uv_packaging

click node_rendergit_py "https://github.com/karpathy/rendergit/blob/master/rendergit.py"
click node_uv_packaging "https://github.com/karpathy/rendergit/blob/master/pyproject.toml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_rendergit_py,node_repo_url,node_git_clone,node_temp_checkout,node_html_output,node_browser toneBlue
class node_scan_filter,node_file_selection,node_render_engine,node_syntax_highlight,node_markdown_render,node_page_builder,node_human_view,node_llm_view toneAmber
class node_git,node_pygments,node_markdown_support,node_uv_packaging toneMint
```

## Components

### CLI pipeline

One-shot flow from repo URL to opened HTML page.

- [rendergit.py](https://github.com/karpathy/rendergit/blob/master/rendergit.py): CLI entrypoint · Main implementation file containing the command-line tool and pipeline orchestration. · `rendergit.py`
- **Repo URL**: input · GitHub repository URL provided by the user.
- **Clone repo**: fetch stage · Clones the remote repository into a temporary local directory.
- **Temp checkout**: ephemeral workspace · Transient local copy of the repository used only during rendering.
- **Static HTML**: final artifact · Temporary HTML file written locally and opened in the browser.
- **Browser**: runtime UI · The only UI runtime after generation; displays the finished static page.

### Rendering

File scanning and content transformation into a single document.

- **Scan & filter**: content selection · Walks the repository tree and excludes binaries and oversized files.
- **Included files**: curated input set · The subset of files selected for rendering after filtering.
- **Render content**: transform stage · Converts heterogeneous source files into HTML-ready representations.
- **Code view**: source renderer · Renders source files with syntax highlighting.
- **Docs view**: markdown renderer · Formats README and documentation files as readable content.
- **Page layout**: html assembly · Builds the single static HTML document with directory summary and sidebar navigation.
- **Human view**: browsing mode · Styled browser-friendly view for code inspection and copying.
- **LLM view**: text mode · Raw CXML text optimized for copying into chat-based AI tools.

### Dependencies

External tools and libraries the pipeline relies on.

- **Git**: external tool · Used to clone the remote repository.
- **Pygments**: library · Provides syntax highlighting for source files.
- **Markdown**: library · Renders markdown documentation into formatted HTML.
- [uv/pip](https://github.com/karpathy/rendergit/blob/master/pyproject.toml): packaging · Installation and distribution tooling for the Python CLI. · `pyproject.toml`

## Connections

- rendergit.py → Repo URL: accepts · The CLI starts from a GitHub repository URL.
- Repo URL → Clone repo: fetches · The remote repository is cloned from GitHub.
- Clone repo → Git: uses · Cloning is delegated to Git.
- Clone repo → Temp checkout: creates · A temporary local checkout is created for processing.
- Temp checkout → Scan & filter: scanned by · The checked-out tree is walked and filtered.
- Scan & filter → Included files: produces · A curated subset of files remains after filtering.
- Included files → Render content: feeds · Selected files are handed to the rendering pipeline.
- Render content → Code view: routes code to · Source files are rendered with syntax highlighting.
- Render content → Docs view: routes docs to · Markdown documents are formatted as prose.
- Code view → Pygments: uses · Syntax highlighting is powered by Pygments.
- Docs view → Markdown: uses · Documentation rendering relies on markdown support.
- Render content → Page layout: assembles into · Rendered file fragments are composed into one HTML page.
- Page layout → Human view: includes · The page presents a styled browsing view.
- Page layout → LLM view: includes · The page also embeds a raw CXML text view.
- Page layout → Static HTML: writes · A temporary static HTML artifact is written locally.
- Static HTML → Browser: opens in · The generated page is opened in the user's browser.
- rendergit.py → uv/pip: distributed via · The tool is packaged for installation with Python packaging tooling.
