Skip to main content

CLI tool for explaining unfamiliar codebases.

Project description

Explain Codebase

CLI tool for quickly mapping the architecture of an unfamiliar repository.

explain-codebase is a heuristic static-analysis CLI that helps developers find likely entrypoints, central modules, side-effect files, and risky areas in a codebase.

It is designed for onboarding and architecture review. It works with local folders and public GitHub repositories, and it aims to give you a useful architectural map quickly rather than perfectly understand every code path.

Why

When you open a new repository, the first questions are usually:

  • where execution starts
  • which modules are central
  • which files touch the database, network, filesystem, or cache
  • what files are risky to change
  • where to begin onboarding

explain-codebase scans the project, builds a dependency graph, and turns those signals into a compact CLI summary.

Changelog

v0.1.2

This release improves repository scanning by making the analyzer Git-aware.

What's new:

  • supports .gitignore-aware scanning
  • analyzes only files tracked by Git when the target is a Git repository
  • ignores common noise directories such as .venv, node_modules, dist, build, coverage, and __pycache__
  • produces cleaner dependency graphs and more accurate architecture summaries
  • prevents generated and local-only files from polluting graph and report outputs

This makes the tool much more useful on real-world repositories by excluding ignored, temporary, and untracked files from the analysis.

v0.1.4

Improved dependency graph visualization.

What’s new:

  • Redesigned dependency graph with a cleaner, more readable layout
  • Improved node spacing and reduced visual noise
  • Better handling of large repositories
  • Smoother interactions and graph rendering

The graph is now easier to read and better represents the structure of real-world codebases.

Installation

Requirements

  • Python 3.10+
  • Git, if you want to analyze remote GitHub repositories
  • Best current support: Python, JavaScript, and TypeScript repositories

Install from PyPI

pip install explain-codebase

For local development

pip install -e .[dev]

Commands

Overview

Use this when you want a quick architectural snapshot of a repository:

explain-codebase .

Detailed analysis

Use verbose mode when you want to inspect the likely architecture structure in more detail:

explain-codebase . --verbose

Use deep mode when you want to focus on architectural risks and potential maintenance problems:

explain-codebase . --deep

File explanation

Use this when you want to understand one specific file in project context:

explain-codebase file src/services/api_server.py

Onboarding path

Use this when a new developer needs a suggested reading order:

explain-codebase onboarding .

Graph and report

Generate an interactive dependency graph:

explain-codebase . --graph

Generate a full HTML architecture report:

explain-codebase . --report

CI mode

Use this in CI when you want architecture issues to fail the build:

explain-codebase . --ci

Example Output

Default output

Default output is intentionally compact:

Explain Codebase
--------------------------------

Repository

  Path        C:\Projects\checkout-service
  Type        Python backend service
  Language    python
  Files       7

Architecture

  Entrypoints        1
  Core modules       5
  Side effects       4

Suggested starting point

  api_server.py

Run with --verbose to see full architecture

Verbose output

Verbose mode adds more structure, including a likely execution path:

Execution flow

api_server.py
|- routes/order_routes.py
|- services/order_service.py
|  |- repositories/order_repository.py
|  \- clients/warehouse_client.py
\- middleware/auth_guard.py

This output is heuristic. It reflects likely structure based on static signals such as imports, naming conventions, and folder layout. It should be treated as a high-value map, not as guaranteed truth.

Features

  • analyzes local folders and public GitHub repositories
  • detects project language and project type
  • attempts to detect likely entrypoints automatically
  • ranks central modules by dependency usage
  • surfaces likely execution paths
  • highlights modules that interact with database, network, filesystem, or cache
  • detects common architecture folders such as services, repositories, routes, and models
  • flags large modules and highly coupled files
  • highlights potential architecture issues such as circular dependencies
  • generates dependency graph visualizations
  • generates HTML architecture reports
  • explains a single file in project context
  • suggests onboarding reading paths
  • supports CI mode for architecture checks

Remote Repositories

You can analyze a public GitHub repository directly:

explain-codebase https://github.com/user/repo

For remote repositories, the tool:

  • supports public GitHub repository URLs
  • clones the repository into a temporary workspace
  • cleans up that workspace after analysis

How It Works

At a high level, the tool:

  • scans source files in the target repository
  • detects language and likely project type
  • parses imports and builds a dependency graph
  • scores central modules using graph signals
  • surfaces likely entrypoints, side effects, hotspots, and onboarding hints
  • renders the result in CLI, JSON, and optional HTML outputs

Limitations

  • the analysis is heuristic, not full semantic understanding
  • best results come from Python, JavaScript, and TypeScript projects with conventional layouts
  • dynamic imports, reflection-heavy code, and runtime dependency injection may reduce accuracy
  • generated, vendored, or mirrored code can reduce signal quality
  • large monorepos may need path scoping or --max-files to keep output focused

CI Behavior

CI mode is intended for lightweight architectural checks:

explain-codebase . --ci

Current behavior:

  • exit code 0 when no architecture issues are detected
  • exit code 1 when architecture issues are found
  • current issue types include circular dependencies and utility-style god modules
  • thresholds are currently built into the tool and are not yet configurable through CLI flags

JSON Output

Use JSON output when you want to integrate the tool into scripts or pipelines:

explain-codebase . --json

The JSON output includes fields such as:

  • project_type
  • entrypoints
  • core_modules
  • core_module_rankings
  • side_effect_modules
  • architecture_modules
  • large_files
  • hotspots
  • dangerous_files
  • architecture_issues
  • execution_flow
  • dependency_graph_output
  • html_report_output

Tests

pytest

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

explain_codebase-0.1.4.tar.gz (42.4 kB view details)

Uploaded Source

Built Distribution

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

explain_codebase-0.1.4-py3-none-any.whl (51.5 kB view details)

Uploaded Python 3

File details

Details for the file explain_codebase-0.1.4.tar.gz.

File metadata

  • Download URL: explain_codebase-0.1.4.tar.gz
  • Upload date:
  • Size: 42.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.0

File hashes

Hashes for explain_codebase-0.1.4.tar.gz
Algorithm Hash digest
SHA256 c204f898d56d1411b48ee3ad6d97cd8192652cf20c5edf39e0a217e6edbb909f
MD5 341dc6d534191e5b66e5907a7973c9f6
BLAKE2b-256 8233300b7e9dc9493317f5c67c64cea43633ffce4e786a03e0a2c49df16927aa

See more details on using hashes here.

File details

Details for the file explain_codebase-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for explain_codebase-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c6201608aa5578d0f6fb23042114bfe2ceca96f578f9956e05346441f4fac24c
MD5 26647e54d23f4de1890bca65521a4032
BLAKE2b-256 420a39b86f0ba266a919e55536919e792c41f589cf8dc0e075b6929756ae29d7

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