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
Python (uv)
Install via uv (recommended):
Run without installing (ephemeral):
Rust (Cargo)
You can build and run locally with Cargo (Rust toolchain required):
# From the repository root
Or run directly:
Quick Start
Generate documentation for your Rust or Python project:
# Generate dependency graph (default)
# Generate layered architecture
# Generate README summary
# Watch mode: auto-regenerate on file changes
# Python example
Layout Options
Dependency Graph (Default)
Shows how modules depend on each other. Ideal for understanding coupling and module relationships.
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.
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:
[[]]
= "User Interface"
= ["src/cli.rs", "src/ui/**"]
[[]]
= "Engine"
= ["src/engine.rs"]
[[]]
= "Data Layer"
= ["src/db/**", "src/models/**"]
README-Embedded
Compact summary designed for README files. Perfect for GitHub discovery and quick onboarding.
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
= ["src"]
# Output file for generated documentation
= "docs/architecture.md"
# Layout: dependency-graph, folder_markdown, one_per_file, layered, readme-embedded
= "dependency-graph"
# Patterns to exclude from scanning
= [
"**/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)
[[]]
= "Core"
= ["src/lib.rs", "src/ir.rs"]
[[]]
= "Engine"
= ["src/engine.rs"]
Development
- Rust edition: 2024
- Min Rust: 1.93+ stable
- Key deps:
tree-sitter,petgraph,serde,clap
Common tasks:
# Format & lint
# Test
# Release build
# Watch for changes
Release Pipeline
CodeTwin treats cargo-dist binaries as the source of truth for all CLI wrappers. The GitHub Release
artifacts produced by cargo-dist are reused to populate codetwin/_bin/ before uv build, so the
PyPI wheel always ships the exact same binaries that were released.
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