Skip to content
https://structurizr.com library for PHP
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows
docs/images
examples
src/StructurizrPHP
tests/StructurizrPHP/Tests/Core/Unit
.gitignore
.php_cs
README.md
composer.json
depfile.yml
phpstan.neon
phpunit.xml.dist
psalm.xml

README.md

Structurizr for PHP

This repository is a port of Structirizr for Java. All credits for creating C4 goes of course to Simon Brown this library is nothing more that simple port of the code that already exists in other language.

How to Use

Careful, this port is still under heavy development, API might change over time, it's not recommended for production usage yet.

Installation

Because package does not have yet stable release you might need to use @dev stability flag to not get into minimum stability composer error.

composer require struturizr-php/structurizr-php:@dev --dev

A quick example

As an example, the following PHP code can be used to create a software architecture model and an associated view that describes a user using a software system.

<?php 

$workspace = new Workspace(
    $id = (string)\getenv('STRUCTURIZR_WORKSPACE_ID'),
    $name = 'Getting Started',
    $description = 'This is a model of my software system. by structurizr-php/structurizr-php'
);
$workspace->getModel()->setEnterprise(new Enterprise('Structurizr PHP'));
$person = $workspace->getModel()->addPerson(
    $name = 'User',
    $description = 'A user of my software system.',
    Location::internal()
);
$softwareSystem = $workspace->getModel()->addSoftwareSystem(
    $name = 'Software System',
    $description = 'My software system.',
    Location::internal()
);
$person->usesSoftwareSystem($softwareSystem, 'Uses', 'Http');

$contextView = $workspace->getViews()->createSystemContextView($softwareSystem, 'System Context', 'system01', 'An example of a System Context diagram.');
$contextView->addAllElements();
$contextView->setAutomaticLayout(true);

$styles = $workspace->getViews()->getConfiguration()->getStyles();

$styles->addElementStyle(Tags::SOFTWARE_SYSTEM)->background("#1168bd")->color('#ffffff');
$styles->addElementStyle(Tags::PERSON)->background("#08427b")->color('#ffffff')->shape(Shape::person());

$client = new Client(
    new Credentials((string) \getenv('STRUCTURIZR_API_KEY'), (string) \getenv('STRUCTURIZR_API_SECRET')),
    new UrlMap('https://api.structurizr.com'),
    new Psr18Client(),
    new SymfonyRequestFactory(),
);
$client->put($workspace);

The view can then be exported to be visualised in a number of different ways; e.g. PlantUML, Structurizr and Graphviz:

Views can be exported and visualised in many ways; e.g. PlantUML, Structurizr and Graphviz

You can’t perform that action at this time.