Skip to main content

LLM plugin for automatically mapping and describing a codebase or project

Project description

llm-cartographer

A plugin for Simon Willison's LLM tool that automatically maps and describes a codebase or project structure in a way which is token-efficient and ready to be consumed by an LLM.

Installation

pip install llm-cartographer

Or directly from the repository:

pip install git+https://github.com/yourusername/llm-cartographer.git

Usage

Basic usage:

llm cartographer /path/to/your/project

This will analyze the project directory and generate a comprehensive description of the codebase structure, which is then processed by an LLM to provide insights.

Options

Options:
  -e, --exclude TEXT             Patterns to exclude (gitignore format)
  --max-files INTEGER            Maximum number of files to analyze (default: 100)
  --max-file-size INTEGER        Maximum file size in bytes (default: 102400)
  -o, --output PATH              Output file path or directory
  -m, --model TEXT               LLM model to use
  --follow-symlinks              Follow symbolic links
  --json                         Output as JSON
  -f, --filter-extension TEXT    Only include files with these extensions
  --cache-dir TEXT               Cache directory path
  --mode [overview|components|architecture|flows]
                                 Analysis mode (default: overview)
  --focus TEXT                   Focus analysis on a specific subdirectory
  --reasoning INTEGER RANGE      Reasoning depth (0-9, where 0=minimal and 9=maximum) (default: 5)
  --visual                       Generate visual diagram of codebase architecture
  --diagram-format [graphviz|mermaid|plantuml]
                                 Format for diagram generation (default: graphviz)
  --llm-nav                      Enable LLM-based codebase navigation
  --help                         Show this message and exit.

Codebase Architecture Diagram

graph LR
    A[CLI] --> B[Core Module]
    B --> C[Directory Scanner]
    B --> D[Map Generator]
    D --Visual Diagram--> E[Visualization Module]
    B --> F[LLM Integration]
    B --> G[Output Formatter]
    G --> H[File Output]

    classDef module fill:#bbf,stroke:#333,stroke-width:1px;
    classDef cli fill:#f96,stroke:#333,stroke-width:1px;
    classDef output fill:#9f6,stroke:#333,stroke-width:1px;

    class A,G,H cli;
    class B,C,D,E,F module;
    class G,H output;

Examples

Analyze current directory with default settings:

llm cartographer .

Analyze a specific project and save results:

llm cartographer /path/to/project --output analysis.md

Analyze only Python files:

llm cartographer . --filter-extension py

Use a specific LLM model:

llm cartographer . --model gpt-4o

Focus on a specific subdirectory:

llm cartographer . --focus src/core

Use component-focused analysis mode:

llm cartographer . --mode components

Increase reasoning depth for more detailed analysis:

llm cartographer . --reasoning 8

Generate a visual diagram of the codebase architecture:

llm cartographer . --visual

Generate a Mermaid diagram (Markdown-compatible):

llm cartographer . --visual --diagram-format mermaid

Generate a PlantUML diagram:

llm cartographer . --visual --diagram-format plantuml

Save output to a directory (creates analysis.md and diagram file):

llm cartographer . --visual --output ./results

Features

  • 🔍 Comprehensive Analysis: Scans directory structure, important files, language statistics
  • 📊 Token Efficiency: Creates a compact representation optimized for LLM consumption
  • 🧩 Component Identification: Identifies key components and their relationships
  • 💡 Insights: Provides architectural patterns and code organization insights
  • 📝 Caching: Caches results to avoid unnecessary re-processing
  • 🎯 Analysis Modes: Different modes for varying analysis approaches (overview, components, architecture, flows)
  • 🔎 Subdirectory Focus: Ability to analyze specific subdirectories
  • 🧠 Reasoning Depth: Control over the level of detail in analysis explanations
  • 📈 Visual Diagrams: Generate visual representations of codebase architecture using various formats
  • 🎨 Rich Formatting: Enhanced output using rich library with improved readability
  • 📁 Output Directory: Support for saving multiple output files to a specified directory
  • 📊 Markdown Diagrams: Support for Mermaid and PlantUML diagrams that display directly in Markdown
  • 🧭 Codebase Navigation: Navigate through the codebase using LLM for better understanding and insights

Analysis Modes

  • overview: General analysis of the entire codebase structure and functionality
  • components: Focus on identifying and explaining the main components and modules
  • architecture: Analysis of architectural patterns and system organization
  • flows: Identification of key data and control flows through the system

Diagram Formats

The --visual flag generates architecture diagrams in the format specified by --diagram-format:

  • graphviz: Standard DOT format diagrams (requires Graphviz installation for PNG rendering)
  • mermaid: Markdown-compatible diagrams that render in GitHub, VS Code, and other Markdown viewers
  • plantuml: UML diagrams that can be rendered with PlantUML tools

Mermaid Diagrams

When using the Mermaid format, the diagram is embedded directly in the Markdown output and will render automatically on platforms that support Mermaid syntax, such as GitHub, GitLab, and VS Code with the right extensions.

Example of a Mermaid diagram in Markdown:

```mermaid
graph TD
    A[Core Module] --> B[Utils]
    A --> C[Database]
    B --> D[External APIs]
    C --> D
```

PlantUML Diagrams

PlantUML diagrams provide more advanced UML capabilities and are saved as Markdown files with PlantUML code blocks:

```plantuml
@startuml
package "Core" {
  [Component A] as A
  [Component B] as B
}
A --> B
@enduml
```

How It Works

  1. Scanning: The plugin scans the directory structure and collects information about files, directories, and languages.
  2. Mapping: It creates a token-efficient representation of the codebase.
  3. Analysis: The map is sent to an LLM for analysis of architecture, components, and workflows.
  4. Visualization: If requested, a diagram of the codebase architecture is generated in the specified format.
  5. Output: Results are formatted and returned, optionally saved to a file or directory.

License

Apache License 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llm_cartographer-0.1.1.tar.gz (34.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

llm_cartographer-0.1.1-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file llm_cartographer-0.1.1.tar.gz.

File metadata

  • Download URL: llm_cartographer-0.1.1.tar.gz
  • Upload date:
  • Size: 34.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.1

File hashes

Hashes for llm_cartographer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 55f7c3c3c1325eaa4b0ab0b2cca254881f9cb6133369f33ed92dba56992b3ba1
MD5 315885b56e3e8882c73ae3f89b52f6a8
BLAKE2b-256 be77046505b39a799f672eccf00c21e0c148fac1f7b5e7f046a5b1524cf511f2

See more details on using hashes here.

File details

Details for the file llm_cartographer-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for llm_cartographer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4b761faf0d8b26b41cf1ecba74aa7f971096c5aa75e9307db762feda8c159138
MD5 9e2868c6b395a8c36d632bc57ad5bcd0
BLAKE2b-256 0ac97a94a9a2841f756ba2d4dbb79c1f87651b4d3585d13831d30427b5c85175

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page