Skip to main content

A code to diagram/documentation generator.

Project description

codetwin

A code-to-diagram/documentation generator in Rust.

Status: Phase 3.1 ✅ - Multi-layout architecture generator with Rust + Python support. Generates documentation in multiple formats (dependency graphs, layered architecture, README summaries).

Overview

CodeTwin transforms your codebase into visual documentation through multiple layout strategies:

  • Dependency Graph: Shows module interdependencies
  • Layered Architecture: Organizes code into logical layers/tiers
  • README-Embedded: Compact summaries perfect for GitHub discovery

Perfect for architecture reviews, onboarding, and design documentation.

Installation

Cargo

cargo install codetwin

Python (uv)

uv tool install codetwin

Run without installing (ephemeral):

uvx codetwin --help

npm

npm install -g codetwin

All three package managers install the same native binary. On first run the npm and PyPI wrappers will bootstrap the binary via the cargo-dist installer if not already present.

Quick Start

Generate documentation for your Rust or Python project:

# Generate dependency graph (default)
codetwin gen

# Generate layered architecture
codetwin gen --layout layered

# Generate README summary
codetwin gen --layout readme-embedded

# Watch mode: auto-regenerate on file changes
codetwin watch

# Python example
codetwin gen --source examples/python_sample.py

Layout Options

Dependency Graph (Default)

Shows how modules depend on each other. Ideal for understanding coupling and module relationships.

codetwin gen --layout dependency-graph --output docs/architecture.md

Output includes:

  • Module-level dependency diagram (Mermaid)
  • List of all modules with functions/structs
  • Circular dependency detection

Layered Architecture

Organizes code into logical tiers (UI, API, Business Logic, Database, etc.). Best for architecture reviews.

codetwin gen --layout layered --output docs/layers.md

Output includes:

  • Layer definitions with glob patterns
  • Modules grouped by layer
  • Inter-layer dependency diagram
  • Layer responsibilities and key functions

Configure layers in codetwin.toml:

[[layers]]
name = "User Interface"
patterns = ["src/cli.rs", "src/ui/**"]

[[layers]]
name = "Engine"
patterns = ["src/engine.rs"]

[[layers]]
name = "Data Layer"
patterns = ["src/db/**", "src/models/**"]

README-Embedded

Compact summary designed for README files. Perfect for GitHub discovery and quick onboarding.

codetwin gen --layout readme-embedded --output docs/architecture.md

Output includes:

  • Component overview table (Module | Purpose | Key Functions)
  • Dependency overview diagram (Mermaid)
  • Data flow explanation (numbered steps)
  • Development guide with key files and contribution guidelines

Keep output under 300 lines for easy README embedding.

Configuration

Create codetwin.toml in your project root:

# Source directories to scan
source_dirs = ["src"]

# Output file for generated documentation
output_file = "docs/architecture.md"

# Layout: dependency-graph, folder_markdown, one_per_file, layered, readme-embedded
layout = "dependency-graph"

# Patterns to exclude from scanning
exclude_patterns = [
  "**/target/**",
  "**/node_modules/**",
  "**/.git/**",
  "**/tests/**"
]

# Discovery respects nested .gitignore files (and .git/info/exclude) in addition to
# exclude_patterns. The ignore rules apply to the directory they live in and below.

# Layer configuration (for layered layout)
[[layers]]
name = "Core"
patterns = ["src/lib.rs", "src/ir.rs"]

[[layers]]
name = "Engine"
patterns = ["src/engine.rs"]

Development

  • Rust edition: 2024
  • Min Rust: 1.93+ stable
  • Key deps: tree-sitter, petgraph, serde, clap

Common tasks:

# Format & lint
cargo fmt --all
cargo clippy --all-targets -- -D warnings

# Test
cargo test --all

# Release build
cargo build --release

# Watch for changes
cargo watch -x test

Release Pipeline

CodeTwin uses cargo-dist to build platform binaries. After a GitHub Release is created, separate workflows publish wrappers to PyPI (uv tool install codetwin) and npm (npm install -g codetwin) that bootstrap the binary on first run via the cargo-dist installer.

Features

Multiple Layouts - Choose the documentation style that fits your needs ✅ Rust + Python Support - Full tree-sitter-based AST parsing ✅ Flexible Configuration - Control layers, patterns, and output formats ✅ Watch Mode - Auto-regenerate on file changes ✅ JSON Export - Structured output for tooling integration ✅ Mermaid Diagrams - Embedded diagrams for visual understanding

Repository

Changelog

See CHANGELOG.md for release history and notable changes.

License

MIT

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

codetwin-0.1.13.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

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

codetwin-0.1.13-py3-none-any.whl (4.2 kB view details)

Uploaded Python 3

File details

Details for the file codetwin-0.1.13.tar.gz.

File metadata

  • Download URL: codetwin-0.1.13.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for codetwin-0.1.13.tar.gz
Algorithm Hash digest
SHA256 1f9c9595f53bed865ed22b4a87c3b6a0708c3e0ae5c81a95980fa7943da696b9
MD5 cb2a7d9cba2f0fda73c3cc1b1f4b0ca9
BLAKE2b-256 c7024318d846d22de9594f05e9af95cd620b60e30231b10412709d20ba669d1b

See more details on using hashes here.

File details

Details for the file codetwin-0.1.13-py3-none-any.whl.

File metadata

  • Download URL: codetwin-0.1.13-py3-none-any.whl
  • Upload date:
  • Size: 4.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for codetwin-0.1.13-py3-none-any.whl
Algorithm Hash digest
SHA256 0d235be48a1f59c18830d0af4c5b45c6bff6b3adb6941b5127dcf629150f76c5
MD5 10e14d18858fe24ae47c0145213f487b
BLAKE2b-256 05fe3cee98c69b85665b9c62dd30ea3a228fe0efc983ac90ef7a44d413d7f65e

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