PHP library which helps you build UML diagrams.

1.0.0-rc.2 2020-09-10 11:05 UTC

This package is auto-updated.

Last update: 2021-08-24 11:37:03 UTC


Stable Upcoming
Latest Stable Version Unstable Version
Minimum PHP Version Minimum PHP Version
License License

Generate UML diagrams by reflection for your PHP projects

Note: This project is in beta stage! Feel free to report any issues you encounter.


The main features provided by this library are:

  • build UML statements of a class diagram
  • build image in one of the supported formats with local dot executable (when GraphVizGenerator is used)


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/graph-uml

Additionally, you'll have to install GraphViz (dot executable). Users of Debian/Ubuntu-based distributions may simply invoke:

$ sudo apt update
$ sudo apt-get install graphviz

while remaining users should install from GraphViz Download page.

Quick Start

Once installed, you can use the following code to build UML class diagram for your existing classes:

use Bartlett\GraphUml;

use Graphp\Graph\Graph;
use Graphp\GraphViz\GraphViz;

$generator = new GraphUml\Generator\GraphVizGenerator(new GraphViz());
$graph = new Graph();
$builder = new GraphUml\ClassDiagramBuilder(
        'label_format' => 'html',
        'show_constants' => false,
        'show_private' => false,
        'show_protected' => false


// For large graph, orientation is recommended
$graph->setAttribute($generator->getPrefix() . 'graph.rankdir', 'LR');
$graph->setAttribute($generator->getPrefix() . 'graph.bgcolor', 'transparent');
$graph->setAttribute($generator->getPrefix() . 'node.fillcolor', 'lightgrey');
$graph->setAttribute($generator->getPrefix() . '', 'filled');

// To use this feature, use my fork of graphp/graphviz project (see composer.json)
$graph->setAttribute($generator->getPrefix() . 'cluster.2.graph.bgcolor', 'lightblue');
// Either numeric or class namespace is allowed (2 = Bartlett\GraphUml)
$graph->setAttribute($generator->getPrefix() . 'cluster.Bartlett\\GraphUml\\', 'filled');
$graph->setAttribute($generator->getPrefix() . 'cluster.Bartlett\\GraphUml\\Generator.graph.fillcolor', 'yellow:blue');
$graph->setAttribute($generator->getPrefix() . 'cluster.Bartlett\\GraphUml\\Generator.graph.gradientangle', 45);
$graph->setAttribute($generator->getPrefix() . 'cluster.Bartlett\\GraphUml\\', 'radial');
$graph->setAttribute($generator->getPrefix() . 'cluster.Bartlett\\GraphUml\\Formatter.graph.fillcolor', 'yellow:blue');
$graph->setAttribute($generator->getPrefix() . 'cluster.Bartlett\\GraphUml\\Formatter.graph.gradientangle', 180);

// show UML diagram statements
echo $generator->createScript($graph);
// default format is PNG
echo $generator->createImageFile($graph) . ' file generated' . PHP_EOL;

That should give such output:

GraPHP UML Application


Full documentation is written in MarkDown format, and HTML export is possible with See output results at or raw *.md files in docs folder.

Table of Contents



  • Laurent Laville (Lead Developer)


This code is a refactored version of clue/graph-uml project, licensed under MIT.