Create UML class diagrams from your PHP source.

2.0.0-rc.2 2020-09-10 12:36 UTC


Stable Upcoming
Latest Stable Version Unstable Version
Minimum PHP Version) Minimum PHP Version)

CAUTION Major rewrite 2.0 is still in beta stage. For a stable version, check branch 1.3

UmlWriter is a library that adds the ability to generate UML class diagrams.

Source code analysed by this parser Reflection API


  • Parse one to many PHP file
  • Parse one to many directory
  • Configuration is handle by a YAML file or console command arguments
  • build UML statements of a class diagram
  • draw png/svg image formats if backends installed (graphviz, plantuml server)
  • two generators provided by default: GraphViz and PlantUML

Currently, the following language features are supported:

  • Property and method visibility
  • Static properties and methods
  • Method return types natively and from doc comment
  • Parameter types from type hinting and doc comment
  • Parameter default values
  • Class constants with value
  • Property types from doc comment
  • Property default values
  • Implemented interfaces and parent classes
  • Abstract classes


The recommended way to install this library is through composer. If you don't know yet what is composer, have a look on introduction.

composer require bartlett/umlwriter

Additionally, you'll have to install GraphViz (dot executable) and/or PlantUML jar with Java Runtime (java executable). Users of Debian/Ubuntu-based distributions may simply invoke:

$ sudo apt update
$ sudo apt-get install graphviz
$ sudo apt-get install openjdk-11-jre-headless

PHAR distribution

You can build yourself a PHAR version of this library. Use the Box project.

Invoke the following command

php box.phar compile --config=box.json.dist

// or simply

php box.phar compile

And find the umlwriter.phar file in bin directory.

Quick Start

Once installed, you can use the following code to draw an UML class diagram for your existing source code (single php file or folder):

use Bartlett\UmlWriter\Generator\GeneratorFactory;
use Bartlett\UmlWriter\Service\ClassDiagramRenderer;
use Symfony\Component\Finder\Finder;

// path to directory where to find PHP source code
$dataSource = dirname(__DIR__) . '/src';

$finder = new Finder();

// use GraphViz as back-end generator
$generatorFactory = new GeneratorFactory('graphviz');
// creates instance of Bartlett\GraphUml\Generator\GraphVizGenerator
$generator = $generatorFactory->getGenerator();

$renderer = new ClassDiagramRenderer();
// generates UML class diagram of all objects found in dataSource
$script = $renderer($finder, $generator);
// show UML diagram statements
echo $script;

// default format is PNG
echo $generator->createImageFile($renderer->getGraph()) . ' file generated' . PHP_EOL;


This library includes a console CLI version with only one command: diagram:class

bin/umlwriter diagram:class src/ --generator graphviz

NOTE use verbose level 1 or 2 for more details.


Visit for documentation of v2.x

Visit for documentation of v1.x


  • Laurent Laville (Lead Developer)


bartlett/graph-uml is a refactored version (with more features) of clue/graph-uml project, licensed under MIT.


This library is licensed under the BSD-3-clauses License - see the LICENSE file for details