https://github.com/bkryza/clang-uml Skip to content Toggle navigation Sign up * Product + Actions Automate any workflow + Packages Host and manage packages + Security Find and fix vulnerabilities + Codespaces Instant dev environments + Copilot Write better code with AI + Code review Manage code changes + Issues Plan and track work + Discussions Collaborate outside of code Explore + All features + Documentation + GitHub Skills + Blog * Solutions For + Enterprise + Teams + Startups + Education By Solution + CI/CD & Automation + DevOps + DevSecOps Case Studies + Customer Stories + Resources * Open Source + GitHub Sponsors Fund open source developers + The ReadME Project GitHub community articles Repositories + Topics + Trending + Collections * Pricing [ ] * # In this repository All GitHub | Jump to | * No suggested jump to results * # In this repository All GitHub | Jump to | * # In this user All GitHub | Jump to | * # In this repository All GitHub | Jump to | Sign in Sign up You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. {{ message }} bkryza / clang-uml Public * Notifications * Fork 27 * Star 273 Customizable automatic UML diagram generator for C++ based on Clang. License View license 273 stars 27 forks Star Notifications * Code * Issues 19 * Pull requests 0 * Actions * Projects 0 * Security * Insights More * Code * Issues * Pull requests * Actions * Projects * Security * Insights bkryza/clang-uml This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository. master Switch branches/tags [ ] Branches Tags Could not load branches Nothing to show {{ refName }} default View all branches Could not load tags Nothing to show {{ refName }} default View all tags Name already in use A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch? Cancel Create 14 branches 12 tags Code * Local * Codespaces * Clone HTTPS GitHub CLI [https://github.com/b] Use Git or checkout with SVN using the web URL. [gh repo clone bkryza] Work fast with our official CLI. Learn more about the CLI. * Open with GitHub Desktop * Download ZIP Sign In Required Please sign in to use Codespaces. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching GitHub Desktop If nothing happens, download GitHub Desktop and try again. Launching Xcode If nothing happens, download Xcode and try again. Launching Visual Studio Code Your codespace will open once ready. There was a problem preparing your codespace, please try again. Latest commit @bkryza bkryza Updated test cases documentation ... 9e7b147 Jun 26, 2023 Updated test cases documentation 9e7b147 Git stats * 1,237 commits Files Permalink Failed to load latest commit information. Type Name Latest commit message Commit time .github/workflows Updated test cases documentation May 4, 2023 22:32 cmake Fixed git version extraction March 2, 2023 22:05 docs Updated test cases documentation June 26, 2023 17:11 examples Moved examples to separate repository June 26, 2022 15:36 packaging Updated conda packaging June 11, 2023 17:27 src Fixed class method links in PlantUML diagrams June 26, 2023 16:15 tests Fixed class method links in PlantUML diagrams June 26, 2023 16:15 thirdparty Update Doxygen docs for sequence_diagram namespace June 25, 2023 12:48 uml Update Doxygen docs for sequence_diagram namespace June 25, 2023 12:48 util Updated test cases documentation June 26, 2023 17:11 .clang-format Added generate_method_arguments config option February 6, 2022 18:18 .clang-format-include Added clang-format target February 21, 2021 12:38 .clang-tidy Fixed clang-tidy warnings May 3, 2023 21:38 .clang-uml Added Doxygen documentation June 23, 2023 19:38 .gitignore Updated Doxygen docs June 19, 2023 23:25 .gitmodules Removed cppast dependency August 3, 2022 22:13 AUTHORS.md Added AUTHORS.md January 2, 2023 11:37 CHANGELOG.md Extended source_location with column and translation unit info June 12, 2023 00:42 CMakeLists.txt Improved libraries detection on Apple Silicon Homebrew May 9, 2023 20:01 CODE_OF_CONDUCT.md Added code of conduct October 3, 2021 18:42 CONTRIBUTING.md Updated Doxygen docs June 19, 2023 23:25 Doxyfile Added Doxygen footer June 25, 2023 12:46 LICENSE.md Added Windows installer target using CPack and NSIS January 8, 2023 17:41 Makefile Updated docs links June 23, 2023 19:54 README.md Disbaled dark mode in HTML Doxygen docs style June 24, 2023 17:23 build.ps1 Fixed unit tests on MSVC February 7, 2023 22:18 View code [ ] C++ UML diagram generator based on Clang Features Installation Usage Generating compile commands database Invocation Configuration file format and examples Examples Class diagrams Example Sequence diagrams Example Package diagrams Example Include diagrams Example Default mappings Diagram content filtering Test cases Acknowledgements Contributing LICENSE README.md [clang-uml-logo] C++ UML diagram generator based on Clang Build status Coverage Version Version Doxygen clang-uml is an automatic C++ to UML class, sequence, package and include diagram generator, driven by YAML configuration files. The main idea behind the project is to easily maintain up-to-date diagrams within a code-base or document legacy code. The configuration file or files for clang-uml define the types and contents of each generated diagram. The diagrams can be generated in PlantUML and JSON formats. clang-uml currently supports C++ up to version 17 with partial support for C++ 20. Full documentation can be found at clang-uml.github.io. To see what clang-uml can do, checkout the diagrams generated for unit test cases here or examples in clang-uml-examples repository. Features Main features supported so far include: * Class diagram generation + Class properties and methods including access - example + Class inheritance - example + Other class relationships including associations, aggregations, dependencies and friendship - example + Template instantiation relationships - example + Template specialization and instantiation based on deduced context - example + Relationship inference from C++ containers and smart pointers - example + Diagram content filtering based on namespaces, elements and relationships - example + Optional package generation from namespaces - example + Optional package generation from subdirectories - example + Interactive links to online code to classes, methods and class fields in SVG diagrams - example + Support for plain C99/C11 code (struct and units relationships) - example + C++20 concept constraints - example * Sequence diagram generation + Generation of sequence diagram from specific method or function - example + Generation of loop and conditional statements - example + Generation of switch statements - example + Generation of try/catch blocks - example + Handling of template code including constexpr conditionals - example + Handling of lambda expressions - example + Interactive links to online code to classes and call expressions - example * Package diagram generation + Generation of package diagram based on C++ namespaces - example + Generation of package diagram based on subdirectories - example + Dependencies between packages based on symbols used in the code - example + Interactive links to online code to packages - example * Include graph diagram generation + Show include graph for selected files - example More comprehensive documentation can be at clang-uml.github.io. Installation Installation instructions for Linux, macos and Windows can be found here. Usage Generating compile commands database clang-uml requires an up-to-date compile_commands.json file, containing the list of commands used for compiling the source code. Nowadays, this file can be generated rather easily using multiple methods: * For CMake projects, simply invoke the cmake command as cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=ON ... * For Make projects checkout compiledb or Bear * For Boost-based projects try commands_to_compilation_database * For SCons, invoke compilation_db tool (requires SCons > 4.0.0) * For Microsoft Visual Studio projects try Clang Power Tools Invocation By default, config-uml will assume that the configuration file .clang-uml and compilation database compile_commands.json files are in the current directory, so if they are in the top level directory of a project, simply run: clang-uml The output path for diagrams, as well as alternative location of compilation database can be specified in .clang-uml configuration file. For other options checkout help: clang-uml --help Configuration file format and examples Configuration files are written in YAML, and provide a list of diagrams which should be generated by clang-uml. Basic example is as follows: compilation_database_dir: . output_directory: puml diagrams: myproject_class: type: class glob: - src/*.cc using_namespace: - myproject include: namespaces: - myproject exclude: namespaces: - myproject::detail plantuml: after: - 'note left of {{ alias("MyProjectMain") }}: Main class of myproject library.' See here for detailed configuration file reference guide. Examples To see what clang-uml can do, checkout the test cases documentation here. In order to see diagrams for the clang-uml itself, based on its own config run the following: make clanguml_diagrams and checkout the SVG diagrams in docs/diagrams folder. Class diagrams Example The following C++ code: template struct A { T t; P p; }; struct B { std::string value; }; template using AString = A; template using AStringPtr = A>; template using PairPairBA = std::pair>, long>; template using VectorPtr = std::unique_ptr>; template using APtr = std::unique_ptr>; template using ASharedPtr = std::shared_ptr>; template using AAPtr = std::unique_ptr, A>>; template using SimpleCallback = std::function; template using GenericCallback = std::function; using VoidCallback = GenericCallback; using BVector = std::vector; using BVector2 = BVector; using AIntString = AString; using ACharString = AString; using AStringString = AString; using BStringString = AStringString; template class R { using AWCharString = AString; PairPairBA bapair; APtr abool; AAPtr aboolfloat; ASharedPtr afloat; A boolstring; AStringPtr floatstring; AIntString intstring; AStringString stringstring; BStringString bstringstring; AAPtr atfloat; protected: BVector bs; public: BVector2 bs2; SimpleCallback cb; GenericCallback gcb; VoidCallback vcb; VectorPtr vps; }; results in the following diagram (via PlantUML): class_diagram_example Open the raw image here, and checkout the hover tooltips and hyperlinks to classes and methods. Sequence diagrams Example The following C++ code: #include #include #include #include #include namespace clanguml { namespace t20029 { std::string encode_b64(std::string &&content) { return std::move(content); } template class Encoder : public T { public: bool send(std::string &&msg) { return T::send(std::move(encode(std::move(msg)))); } protected: std::string encode(std::string &&msg) { return encode_b64(std::move(msg)); } }; template class Retrier : public T { public: bool send(std::string &&msg) { std::string buffer{std::move(msg)}; int retryCount = 5; while (retryCount--) { if (T::send(buffer)) return true; } return false; } }; class ConnectionPool { public: void connect() { if (!is_connected_.load()) connect_impl(); } bool send(const std::string &msg) { return true; } private: void connect_impl() { is_connected_ = true; } std::atomic is_connected_; }; int tmain() { auto pool = std::make_shared>>(); pool->connect(); for (std::string line; std::getline(std::cin, line);) { if (!pool->send(std::move(line))) break; } return 0; } } } results in the following diagram (via PlantUML): sequence_diagram_example Package diagrams Example The following C++ code: namespace clanguml { namespace t30003 { namespace ns1 { namespace ns2_v1_0_0 { class A { }; } namespace [[deprecated]] ns2_v0_9_0 { class A { }; } namespace { class Anon final { }; } } namespace [[deprecated]] ns3 { namespace ns1::ns2 { class Anon : public t30003::ns1::ns2_v1_0_0::A { }; } class B : public ns1::ns2::Anon { }; } } } results in the following diagram (via PlantUML): package_diagram_example Include diagrams In case you're looking for a simpler tool to visualize and analyze include graphs checkout my other tool - clang-include-graph Example The following C++ code structure: tests/t40001 +-- include | +-- lib1 | | +-- lib1.h | +-- t40001_include1.h +-- src +-- t40001.cc results in the following diagram (via PlantUML) based on include directives in the code: package_diagram_example Default mappings UML PlantUML Inheritance extension Association association Dependency dependency Aggregation aggregation Composition composition Template specialization/instantiation specialization Nesting (inner class/enum) nesting Include (local) association Include (system) dependency Diagram content filtering For typical code bases, generating a single diagram from entire code or even a single namespace can be too big to be useful, e.g. as part of documentation. clang-uml allows specifying content to be included and excluded from each diagram using simple YAML configuration: include: # Include only elements from these namespaces namespaces: - clanguml::common - clanguml::config # Include all subclasses of ClassA (including ClassA) subclasses: - clanguml::common::ClassA # and specializations of template Class (including Class) specializations: - clanguml::common::ClassT # and all classes depending on Class D dependants: - clanguml::common::ClassD # and all dependencies of ClassE dependencies: - clanguml::common::ClassE # and classes in direct relation to ClassB (including ClassB) context: - clanguml::common::ClassB # Include only inheritance relationships relationships: - inheritance exclude: # Exclude all elements from detail namespace namespaces: - clanguml::common::detail # and also exclude ClassF elements: - clanguml::common::ClassF More details on this can be found in the diagram filters documentation section. Test cases The build-in test cases used for unit testing of the clang-uml, can be browsed here. Acknowledgements This project relies on the following great tools: * Clang LibTooling - a C++ library for creating tools based on Clang * PlantUML - language and diagram for generating UML diagrams * Catch2 - C++ unit test framework * glob - Unix style path expansion for C++ * indicators - Activity indicators for modern C++ * CLI11 - command line parser for C++ * inja - a template engine for modern C++ * backward-cpp - stack trace pretty printer for C++ * yaml-cpp - YAML parser library for C++ * spdlog - Fast C++ logging library * Doxygen - C++ documentation generator * Doxygen Awesome - Doxygen CSS style Contributing If you would like to contribute to the project, please check out contributing guidelines. LICENSE Copyright 2021-present Bartek Kryza Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. About Customizable automatic UML diagram generator for C++ based on Clang. Topics libclang cplusplus cpp uml plantuml clang cpp17 Resources Readme License View license Code of conduct Code of conduct Stars 273 stars Watchers 8 watching Forks 27 forks Report repository Releases 12 0.3.7 Latest Jun 11, 2023 + 11 releases Packages 0 No packages published Contributors 4 * @bkryza bkryza Bartek Kryza * @bram bram Bram * @dgoffredo dgoffredo David Goffredo * @buffyanamin buffyanamin Languages * C++ 98.2% * CMake 0.6% * Python 0.5% * Makefile 0.5% * C 0.1% * Shell 0.1% Footer (c) 2023 GitHub, Inc. Footer navigation * Terms * Privacy * Security * Status * Docs * Contact GitHub * Pricing * API * Training * Blog * About You can't perform that action at this time.