Dependency graph visualization for composer.json (PHP + Composer)

Overview

clue/graph-composer

CI status downloads on GitHub installs on Packagist

Graph visualization for your project's composer.json and its dependencies:

dependency graph for clue/graph-composer

Table of contents

Usage

Once clue/graph-composer is installed, you can use it via command line like this.

graph-composer show

The show command creates a dependency graph for the given project path and opens the default desktop image viewer for you:

$ php graph-composer.phar show ~/path/to/your/project
  • It accepts an optional argument which is the path to your project directory or composer.json file (defaults to checking the current directory for a composer.json file).

  • You may optionally pass an --format=[svg/svgz/png/jpeg/...] option to set the image type (defaults to svg).

graph-composer export

The export command works very much like the show command, but instead of opening your default image viewer, it will write the resulting graph to STDOUT or into an image file:

$ php graph-composer.phar export ~/path/to/your/project
  • It accepts an optional argument which is the path to your project directory or composer.json file (defaults to checking the current directory for a composer.json file).

  • It accepts an additional optional argument which is the path to write the resulting image to. Its file extension also sets the image format (unless you also explicitly pass the --format option). Example call:

    $ php graph-composer.phar export ~/path/to/your/project export.png

    If this argument is not given, it defaults to writing to STDOUT, which may be useful for scripting purposes:

    $ php graph-composer.phar export ~/path/to/your/project | base64
  • You may optionally pass an --format=[svg/svgz/png/jpeg/...] option to set the image type (defaults to svg).

Install

You can grab a copy of clue/graph-composer in either of the following ways.

This project aims to run on any platform and thus does not require any PHP extensions and supports running on legacy PHP 5.3 through current PHP 7+ and HHVM. It's highly recommended to use PHP 7+ for this project.

The graph drawing feature is powered by the excellent GraphViz software. This means you'll have to install GraphViz (dot executable). The Graphviz homepage includes complete installation instructions for most common platforms, users of Debian/Ubuntu-based distributions may simply invoke:

$ sudo apt install graphviz

As a phar (recommended)

Once you have PHP and GraphViz installed, you can simply download a pre-packaged and ready-to-use version of this project as a Phar to any directory. You can simply download the latest graph-composer.phar file from our releases page. The latest release can always be downloaded like this:

$ curl -JOL https://clue.engineering/graph-composer-latest.phar

That's it already. Once downloaded, you can verify everything works by running this:

$ cd ~/Downloads
$ php graph-composer.phar --version

If you prefer a global (system-wide) installation without having to type the .phar extension each time, you may simply invoke:

$ chmod +x graph-composer.phar
$ sudo mv graph-composer.phar /usr/local/bin/graph-composer

You can verify everything works by running:

$ graph-composer --version

There's no separate update procedure, simply download the latest release again and overwrite the existing phar.

Installation using Composer

Alternatively, you can also install clue/graph-composer as part of your development dependencies. You will likely want to use the require-dev section to exclude clue/graph-composer in your production environment.

This method also requires PHP 5.3+, GraphViz and, of course, Composer.

You can either modify your composer.json manually or run the following command to include the latest tagged release:

$ composer require --dev clue/graph-composer

Now you should be able to invoke the following command in your project root:

$ ./vendor/bin/graph-composer show

Alternatively, you can install this globally for your user by running:

$ composer global require clue/graph-composer

Now, assuming you have ~/.composer/vendor/bin in your path, you can invoke the following command:

$ graph-composer show ~/path/to/your/project

Note: You should only invoke and rely on the main graph-composer bin file. Installing this project as a non-dev dependency in order to use its source code as a library is not supported.

To update to the latest release, just run composer update clue/graph-composer. If you installed it globally via composer you can run composer global update clue/graph-composer instead.

Development

clue/graph-composer is an open-source project and encourages everybody to participate in its development. You're interested in checking out how clue/graph-composer works under the hood and/or want to contribute to the development of clue/graph-composer? Then this section is for you!

The recommended way to install clue/graph-composer is to clone (or download) this repository and use Composer to download its dependencies. Therefore you'll need PHP, Composer, GraphViz, git and curl installed. For example, on a recent Ubuntu/debian system, simply run:

$ sudo apt install php7.2-cli git curl graphviz

$ git clone https://github.com/clue/graph-composer.git
$ cd graph-composer

$ curl -s https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer

$ composer install

You can now verify everything works by running clue/graph-composer like this:

$ php bin/graph-composer show

If you want to distribute clue/graph-composer as a single standalone release file, you may compile the project into a single graph-composer.phar file like this:

$ composer build

Note that compiling will temporarily install a copy of this project to the local build/ directory and install all non-development dependencies for distribution. This should only take a second or two if you've previously installed its dependencies already. The build script optionally accepts the version number (VERSION env) and an output file name or will otherwise try to look up the last release tag, such as graph-composer-1.0.0.phar.

You can now verify the resulting graph-composer.phar file works by running it like this:

$ ./graph-composer.phar --version

To update your development version to the latest version, just run this:

$ git pull
$ php composer.phar install

Made some changes to your local development version?

Make sure to let the world know! :shipit: We welcome PRs and would love to hear from you!

Happy hacking!

Tests

To run the test suite, you first need to clone this repo and then install all dependencies through Composer:

$ composer install

To run the test suite, go to the project root and run:

$ php vendor/bin/phpunit

License

This project is released under the permissive MIT license.

Did you know that I offer custom development services and issuing invoices for sponsorships of releases and for contributions? Contact me (@clue) for details.

Comments
  • Refactor the autoload process in the bin script.

    Refactor the autoload process in the bin script.

    This is a bit easier to understand I think.

    It also uses require rather than include, so that failure to properly load the file terminates the script.

    It also removes the error suppression which can silence unwanted errors (It will silence any errors that occur while parsing the related class (and any other files included in the process)).

    opened by nubs 7
  • composer install doesn't work

    composer install doesn't work

    Ran this to install:

    composer require --dev clue/graph-composer

    Tried this but there is no vendor/bin folder even: ./vendor/bin/graph-composer show

    Tried this but get error message: ./vendor/clue/graph-composer/bin/graph-composer show

    sh: dot: command not found
    
      [Fhaculty\Graph\Exception\UnexpectedValueException]
      Unable to invoke "dot" to create image file (code 127)
    

    Need to update installation directions to require dot even if installing via composer. Also fix or update installation directions for the vendor/bin problem.

    bug easy pick help wanted maintenance 
    opened by MECU 5
  • Add Search for a composer autoload file when installed using Composer

    Add Search for a composer autoload file when installed using Composer

    Hi, I just tried installing graph-composer using Composer - an option which is not even mentioned in then install documentation, but which is doing pretty well. Unfortunately graph-composer isn't prepared for that case (yet), so this is how it might be fixed.

    new feature 
    opened by elkuku 5
  • Added options to filter production / development dependencies (supersedes #19)

    Added options to filter production / development dependencies (supersedes #19)

    I added the options

    • --no-dev to exclude development dependencies from the graph,
    • --dev-only to visualize the root package and its dev dependencies only.

    This PR supersedes #19 which didn't work correctly for me. While it deleted the vertices from the root package to its immediate dev dependencies, the production dependencies of dev dependencies still kept them in the graph (resulting in multiple root nodes, e.g. the root package plus PHPUnit).

    Please consider merging soon (before the package base changes again). Thanks!

    new feature help wanted 
    opened by jkphl 4
  • How to tweak the layout?

    How to tweak the layout?

    I just played around with your phar and created a graph of my project (phundament/app).

    bildschirmfoto 2013-10-21 um 19 58 16

    How could I stretch or expand the nodes so that the connections become more clearly visible? Or adjust the layout so that the nodes are distributed more into a vertical direction.

    opened by schmunk42 4
  • add dockerfile/example to ease usage

    add dockerfile/example to ease usage

    I created the following dockerfile to test this project

    FROM alpine:3.13
    
    RUN apk add --no-cache curl
    
    WORKDIR /app
    
    RUN curl -o graph-composer -L https://clue.engineering/graph-composer-latest.phar && chmod +x graph-composer
    
    FROM php:8.0-cli-alpine
    
    COPY --from=0 /app/graph-composer /usr/local/bin/graph-composer
    
    RUN sed -i '/edge/s/^#//' /etc/apk/repositories \
        && apk add --no-cache graphviz
    
    WORKDIR /app
    
    ENTRYPOINT ["/usr/local/bin/graph-composer"]
    

    Would you be interested in connecting it to your project in any way ? It can of course be modified.

    question help wanted 
    opened by babaorum 3
  • Add GraphML export for manual positioning

    Add GraphML export for manual positioning

    Actually exporting to GraphML should be implemented in clue/graph#3.

    This ticket serves both as a valid use case for its implementation and as a reminder to add the necessary glue code to take advantage of it within this project.

    new feature help wanted 
    opened by clue 2
  • Add warning when GraphViz is not installed

    Add warning when GraphViz is not installed

    Currently, generating a graph image just fails if GraphViz (dot executable) is not installed. Instead, we should check for the existence and fail gracefully with a concise, readable error message. On Debian-based systems, we could perhaps also offer to install it via sudo apt-get install graphviz.

    easy pick new feature help wanted 
    opened by clue 2
  • PHP 8+ support

    PHP 8+ support

    The following deprecation notices are generated when I run the latest release on PHP 8.1

    php graph-composer-1.1.0.phar export ./
    [12-Sep-2022 07:56:11 UTC] PHP Deprecated:  Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/symfony/console/Symfony/Component/Console/Helper/HelperSet.php on line 104
    
    Deprecated: Return type of Symfony\Component\Console\Helper\HelperSet::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/symfony/console/Symfony/Component/Console/Helper/HelperSet.php on line 104
    [12-Sep-2022 07:56:11 UTC] PHP Deprecated:  Return type of Fhaculty\Graph\Set\Vertices::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/clue/graph/src/Set/Vertices.php on line 414
    
    Deprecated: Return type of Fhaculty\Graph\Set\Vertices::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/clue/graph/src/Set/Vertices.php on line 414
    [12-Sep-2022 07:56:11 UTC] PHP Deprecated:  Return type of Fhaculty\Graph\Set\Vertices::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/clue/graph/src/Set/Vertices.php on line 451
    
    Deprecated: Return type of Fhaculty\Graph\Set\Vertices::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/clue/graph/src/Set/Vertices.php on line 451
    [12-Sep-2022 07:56:11 UTC] PHP Deprecated:  Return type of Fhaculty\Graph\Set\Edges::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/clue/graph/src/Set/Edges.php on line 386
    
    Deprecated: Return type of Fhaculty\Graph\Set\Edges::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/clue/graph/src/Set/Edges.php on line 386
    [12-Sep-2022 07:56:11 UTC] PHP Deprecated:  Return type of Fhaculty\Graph\Set\Edges::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/clue/graph/src/Set/Edges.php on line 412
    
    Deprecated: Return type of Fhaculty\Graph\Set\Edges::getIterator() should either be compatible with IteratorAggregate::getIterator(): Traversable, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in phar:///mnt/files/local_mount/build/graph-composer-1.1.0.phar/vendor/clue/graph/src/Set/Edges.php on line 412
    
    question 
    opened by mxr576 1
  • Compatibility with composer v2

    Compatibility with composer v2

    Looks like composer build is not compatible with composer v2.

    $ composer build
    
    [1/1] Creating phar graph-composer-1.1.0-5-g25ea081.phar
      - Adding main package "clue/graph-composer"
      - Adding composer base files
    
    Catchable fatal error: Argument 1 passed to Clue\PharComposer\Package\Package::__construct() must be of the type array, boolean given, called in /root/graph-composer/vendor/clue/phar-composer/src/Clue/PharComposer/Phar/PharComposer.php on line 136 and defined in /root/graph-composer/vendor/clue/phar-composer/src/Clue/PharComposer/Package/Package.php on line 21
    Script @php build.php handling the build event returned with error code 255
    

    Build still works fine however in composer v1 (now deprecated). I noticed this when attempting to containerize this (see https://github.com/patricknelson/graph-composer-docker). Step to reproduce:

    # Get graph-composer-docker repository and work from the 'composer-2' branch
    git clone [email protected]:patricknelson/graph-composer-docker.git
    cd graph-composer-docker
    git checkout composer-2
    
    # Tries to build container, but will fail
    docker-compose up -d --build
    

    Basically, what the Dockerfile does:

    • Install composer 2
    • Clone down https://github.com/clue/graph-composer.git
    • Installs dev dependencies
    • Runs composer build (and fails)

    EDIT: You can see the diff in Dockerfile now in this PR: https://github.com/patricknelson/graph-composer-docker/pull/1

    maintenance 
    opened by patricknelson 1
  • Highlight outdated packages (`--outdated`)

    Highlight outdated packages (`--outdated`)

    @wol-soft has implemented an up-to-date check based on #45 in https://github.com/wol-soft/graph-composer/pull/1 which colorizes the graph.

    MicrosoftTeams-image

    Colorized graphs work like:

    • green: latest version
    • lemon-green: patch available
    • yellow: minor patch available
    • orange: new major version available
    • red: package is abandoned

    Originally posted by @wol-soft in https://github.com/clue/graph-composer/issues/45#issuecomment-539617615

    new feature help wanted 
    opened by clue 0
  • Add options to exclude packages and dependencies from graph.

    Add options to exclude packages and dependencies from graph.

    Dev dependencies of dependencies are not shown anymore, because they are not relevant for the current package.

    • --no-dev will hide dev dependencies
    • --no-php will hide the constraints regarding the PHP version
    • --no-ext will hide PHP extensions
    • --depth will limit the depth of the generated graph
    • --exclude-regex allows to apply regular expressions to hide packages
    • --only-regex show only packages with their name matching the expression
    • --exclude-type exclude pacakges with given type
    • --only-type only show packages of given type

    The filters are never applied to the root packge.

    To apply these filters the packages must be rendered in the correct order. Before the packages were drawn "randomly" and were connected later on. Now packages are drawn from root package and only if they are a dependency of a package. This allow filtering for dependencies and packages. If a package (node) is missing, then the dependency (edge) is not shown. Vice versa the dependency (edge) is not shown when the package (node) is not available.

    New output_exfsyf

    Old output_n3qgvf

    Open TODOs:

    • [x] Update documentation (add examples etc.)
    • [x] Fix PHPUnit tests (they are surprisingly still working ;-))
    • [x] Cleanup code / code style etc.
    • [x] Update CHANGELOG
    • [x] Visualize rendering process so that new algo to render graph is understood (compare old vs. new)
    new feature help wanted 
    opened by markuspoerschke 8
  • What about left to right direction? (horizontal layout)

    What about left to right direction? (horizontal layout)

    The default exported image is from up to down. So, when the dependence packages go large, the width of the image goes wide. I think it would be better to make it left to right (Or you can do an option), at least as a tree, the depth wouldn't go so far. It is more convenience to scroll from up to down than scroll left to right... ( :) a lot of directions may not confuse you )

    new feature help wanted 
    opened by yarcowang 1
  • Add option to limit depth of the graph

    Add option to limit depth of the graph

    Some projects have many dependencies and the graphs can get too large (#11). One option would be to add a --depth option in order to limit the depth of the resulting graph.

    For example, the following could be used to display only direct dependencies (i.e. no sub-dependencies):

    $ graph-composer show --depth=1
    

    Special care may have to be taken with regards to loops/circles in the graph.

    new feature help wanted 
    opened by clue 4
  • Add a filter to not display all dependencies from whole graph

    Add a filter to not display all dependencies from whole graph

    My graph is just to large. I want to use it for documentation purposes and don't want to show up third party graph-nodes. So a regular expression filter would help me here.

    Would you merge this?

    Best regards Philipp

    new feature help wanted 
    opened by pscheit 14
  • Add --dev argument and behave similar to composer by ignoring development dependencies

    Add --dev argument and behave similar to composer by ignoring development dependencies

    The current behavior is to also visualize development dependencies. This should be changed to ignore them by default and add a new --dev argument flag which enables showing development dependencies.

    new feature help wanted 
    opened by clue 8
Releases(v1.1.0)
  • v1.1.0(Mar 26, 2020)

    • Feature: Forward compatibility with symfony/console v5, v4, v3 and legacy v2. (#34 by @keradus and #48 by @clue)

    • Feature / Fix: Update all dependencies and fix handling non-lowercase package names. (#50 and #52 by @clue)

    • Improve documentation and installation instructions and add support / sponsorship info. (#32 by @xavismeh and #43 and #49 by @clue)

    • Improve build setup, add clue/phar-composer to require-dev, add build script and update development docs. (#44 by @clue)

    • Improve test suite by adding PHPUnit to require-dev, support legacy PHP 5.3 through PHP 7.4 and legacy HHVM and simplify test matrix. (#42 and #51 by @clue)

    Source code(tar.gz)
    Source code(zip)
    graph-composer-1.1.0.phar(511.37 KB)
  • v1.0.0(Nov 17, 2015)

    • First stable release, now following SemVer.
    • Feature: Can now be installed as a require-dev Composer dependency and supports running as ./vendor/bin/graph-composer. (#12 by @elkuku)
    • Fix: Update dependencies in order to improve error reporting and MS Windows support. (#23 by @clue)
    • Updated documentation, test suite and project structure. (#18, #16 by @nubs and #24, #25, #26, #27 by @clue)
    Source code(tar.gz)
    Source code(zip)
    graph-composer.phar(906.51 KB)
  • v0.1.1(Mar 6, 2014)

  • v0.1.0(Mar 6, 2014)

    • BC break: Whole new command line interface
    • Feature: Proper command line arguments and help
    • Feature: Image format can now be selected (svg, png, jpg/jpeg, etc.)
    Source code(tar.gz)
    Source code(zip)
  • v0.0.2(Mar 6, 2014)

  • v0.0.1(Mar 6, 2014)

Owner
Christian Lück
@reactphp maintainer / Freelance Software Engineer, all things web, passionate about coaching others building awesome things… Reach out if you need help
Christian Lück
Data visualization for NASA's DSNNow public data

DSN Monitor Data visualization for NASA's DSNNow public data. A live version of the project can be accessed at http://dsnmonitor.ddns.net. Description

Vinz 2 Sep 18, 2022
A small CLI tool to check missing dependency declarations in the composer.json and module.xml

Integrity checker Package allows to run static analysis on Magento 2 Module Packages to provide an integrity check of package. Supported tools: Compos

run_as_root GmbH 13 Dec 19, 2022
An installer package that let's you install NodeJS and NPM as a Composer dependency.

NodeJS installer for Composer This is an installer that will download NodeJS and NPM and install them in your Composer dependencies. Installation is s

TheCodingMachine 106 Sep 30, 2022
Microsoft Graph Library for PHP.

Get started with the Microsoft Graph SDK for PHP If your project uses the Microsoft Graph API, you should use this library to make it easier to implem

Huỳnh Mạnh Dần 2 Oct 17, 2022
A composer plugin, to install differenty types of composer packages in custom directories outside the default composer default installation path which is in the vendor folder.

composer-custom-directory-installer A composer plugin, to install differenty types of composer packages in custom directories outside the default comp

Mina Nabil Sami 136 Dec 30, 2022
Allows generate class files parse from json and map json to php object, including multi-level and complex objects;

nixihz/php-object Allows generate class files parse from json and map json to php object, including multi-level and complex objects; Installation You

zhixin 2 Sep 9, 2022
An object graph visualizer

print_o An object graph visualizer for PHP What is object graph ? Object-oriented applications contain complex webs of interrelated objects. Objects a

Akihito Koriyama 139 Jan 1, 2023
Shortest Path - have a function ShortestPath (strArr) take strArr which will be an array of strings which models a non-looping Graph.

Have the function ShortestPath(strArr) take strArr which will be an array of strings which models a non-looping Graph

null 1 Feb 5, 2022
Create eye-catching Open Graph images for each (or some) site pages

Open Graph Image Generator for Laravel Create Open Graph images (og:image, twitter:image, vk:image) for each (or some) site pages. Use page title to c

Pavel Bychko 4 Nov 11, 2022
Json-normalizer: Provides generic and vendor-specific normalizers for normalizing JSON documents

json-normalizer Provides generic and vendor-specific normalizers for normalizing JSON documents. Installation Run $ composer require ergebnis/json-nor

null 64 Dec 31, 2022
PDF API. JSON to PDF. PDF Template Management, Visual HTML Template Editor and API to render PDFS by json data

PDF Template Management, Visual HTML Template Editor and API to render PDFS by json data PDF ENGINE VERSION: development: This is a prerelease version

Ajous Solutions 2 Dec 30, 2022
A simple, type-safe, zero dependency port of the javascript fetch WebApi for PHP.

A simple, type-safe, zero dependency port of the javascript fetch WebApi for PHP.

Matias Navarro Carter 105 Jan 4, 2023
A PHP dependency vulnerabilities scanner based on the Security Advisories Database.

Enlightn Security Checker The Enlightn Security Checker is a command line tool that checks if your application uses dependencies with known security v

Enlightn 242 Dec 26, 2022
Detect flaws in your architecture, before they drag you down into the depths of dependency hell ...

Detect flaws in your architecture before they drag you down into the depths of dependency hell ... What it does System Requirements Installation Phive

Michael Haeuslmann 507 Dec 27, 2022
🪃 Zero-dependency global `kirbylog()` helper for any content

Kirbylog The most simple, Kirby-esque way to log content to file. Most of the time, I just want to log some string or array to a file. That's what thi

Johann Schopplich 11 Nov 9, 2022
Library for check dependency between modules inside projects

PHP Dependency analyzer PHP DA is tool for check and support dependencies inside your project clear. For example: You have project with 3 root namespa

Kir Apukhtin 12 Nov 15, 2022
Simple, single-file and dependency-free AWS S3 client.

Simple, single-file and dependency-free AWS S3 client. Why? In some scenarios we want the simplest and lightest S3 client possible. For example in Bre

Matthieu Napoli 28 Nov 15, 2022
Checks prefer-lowest installation for actually defined min versions in composer.json

Composer Prefer Lowest Validator This validator will strictly compare the specified minimum versions of your composer.json with the ones actually used

Mark Scherer 17 Aug 7, 2022