Skip to main content

Convert C/C++ code to PlantUML diagrams with advanced filtering and transformation capabilities

Project description

c2puml - C to PlantUML Converter

C 2 Puml

A Python tool for converting C/C++ source code to PlantUML diagrams. Analyzes C/C++ projects and generates comprehensive PlantUML class diagrams showing structs, enums, unions, functions, global variables, macros, typedefs, and include relationships.

Status

00. Test 02. PlantUML to PNG 01. Test and Coverage 03. Deploy Website

Reports

Documentation

Releases

Features

  • C/C++ Parsing: Comprehensive tokenization-based parsing with preprocessor handling and conditional compilation support
  • Project Analysis: Analyzes entire C/C++ projects with recursive directory scanning and configurable include depth processing
  • PlantUML Generation: Creates organized PlantUML diagrams with proper UML notation and relationship visualization
  • Configuration System: Flexible filtering and transformation capabilities with file-specific settings
  • Enhanced UML Stereotypes: Uses specific stereotypes for different typedef types (<>, <>, <
  • Smart Visibility Detection: Automatically determines public/private visibility based on header file declarations

Installation

Option 1: Install as Python Package (Recommended)

git clone https://github.com/fischerjooo/c2puml.git
cd c2puml
python3 -m pip install -e .

Option 2: Use Standalone Script (No Installation Required)

If you prefer not to install the package, you can use the standalone script directly:

git clone https://github.com/fischerjooo/c2puml.git
cd c2puml
# No installation needed - just run the script directly
python3 main.py --config tests/example/config.json

Prerequisites for standalone usage:

  • Python 3.7 or later
  • The complete c2puml source code (including the src/ directory)

Quick Start

Basic Usage

Using Installed Package

# Full workflow: Parse → Transform → Generate diagrams
c2puml --config tests/example/config.json

# Using current directory configuration (merges all .json files)
c2puml

# Individual steps
c2puml --config tests/example/config.json parse      # Step 1: Parse only
c2puml --config tests/example/config.json transform  # Step 2: Transform only
c2puml --config tests/example/config.json generate   # Step 3: Generate only

# With verbose output for debugging
c2puml --config tests/example/config.json --verbose

# Alternative module syntax
python3 -m c2puml.main --config tests/example/config.json

Using Standalone Script (No Installation)

# Full workflow: Parse → Transform → Generate diagrams
python3 main.py --config tests/example/config.json

# Using current directory configuration (merges all .json files)
python3 main.py

# Individual steps
python3 main.py --config tests/example/config.json parse      # Step 1: Parse only
python3 main.py --config tests/example/config.json transform  # Step 2: Transform only
python3 main.py --config tests/example/config.json generate   # Step 3: Generate only

# With verbose output for debugging
python3 main.py --config tests/example/config.json --verbose

Note: Both methods provide identical functionality. Choose the one that best fits your workflow.

Generate PNG Images

# Linux/macOS
./picgen.sh

# Windows
picgen.bat

The scripts automatically:

  • Download PlantUML.jar if needed
  • Install Graphviz (required for PNG generation)
  • Test the setup before conversion
  • Convert all .puml files to PNG images

Note: The script automatically handles Graphviz installation and testing to resolve the "Dot executable does not exist" error.

Configuration

Create a config.json to customize analysis and output. Minimal example:

{
  "project_name": "my_project",
  "source_folders": ["./src"],
  "output_dir": "./output"
}

Run with a config file:

c2puml --config config.json
# or (merges all .json files in the current directory)
c2puml

For full examples (file-specific include filters, include depth, formatting, and the transformation system), see the Configuration Guide: docs/configuration.md.

Generated Output

The tool creates PlantUML diagrams showing:

  • Source files with functions, structs, enums, unions
  • Header files with declarations
  • Include relationships between files
  • Typedef relationships with enhanced UML stereotypes
  • Color-coded elements (source, headers, typedefs)
  • Dynamic visibility detection (public/private based on header presence)

Troubleshooting

Common Issues

"Command 'c2puml' not found"

  • Solution: Install the package with pip install -e .
  • Alternative: Use the standalone script: python3 main.py --config config.json

"Module 'c2puml' not found"

  • Solution: Ensure you're in the project root directory and the src/ folder exists
  • Alternative: Use the standalone script which handles path setup automatically

"Permission denied" errors

  • Solution: Use the standalone script which doesn't require installation: python3 main.py

"Dot executable does not exist" (PlantUML PNG generation)

  • Solution: Install Graphviz or use the provided scripts: ./scripts/picgen.sh or scripts/picgen.bat

Getting Help

  • Quick Test: Try the standalone script first: python3 main.py --config tests/example/config.json
  • Development: Use the debug script: python scripts/debug.py
  • Examples: Run the example workflow: ./scripts/run_example.sh or scripts/run_example.bat

License

MIT License

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

c2puml-2025.9.14.1.tar.gz (75.6 kB view details)

Uploaded Source

Built Distribution

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

c2puml-2025.9.14.1-py3-none-any.whl (77.8 kB view details)

Uploaded Python 3

File details

Details for the file c2puml-2025.9.14.1.tar.gz.

File metadata

  • Download URL: c2puml-2025.9.14.1.tar.gz
  • Upload date:
  • Size: 75.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for c2puml-2025.9.14.1.tar.gz
Algorithm Hash digest
SHA256 60bdf6a10134e10a5682be61ccdf0b971b836da6d4567867a7168ecec982b133
MD5 1a5d0b05bfee6077cfb4ab26a97411f4
BLAKE2b-256 aa1407f3433c8b33d278ed5eb86cd502c8058154aee60ace6f7f5d481a7c0312

See more details on using hashes here.

File details

Details for the file c2puml-2025.9.14.1-py3-none-any.whl.

File metadata

  • Download URL: c2puml-2025.9.14.1-py3-none-any.whl
  • Upload date:
  • Size: 77.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.23

File hashes

Hashes for c2puml-2025.9.14.1-py3-none-any.whl
Algorithm Hash digest
SHA256 5b231fc8c932034ea4c948e1f6f9f56d93d9bb6bae983ef659a8751aa4e3a26f
MD5 51179b9a07ffd5d225831c0f1856cfe7
BLAKE2b-256 d14388180f825e2d1cdfa39e3070561989dde0456249ab500af0b7df25ba1146

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