hiearch is a CLI utility that generates multiple diagrams (views) from a
common textual description. hiearch supports node hierarchies that are
automatically expanded, collapsed, or hidden, depending on configuration of a
particular view. In this sense the utility is more similar to visualization
tools like https://structurizr.com than to classic generators such as
graphviz. Currently, hiearch uses graphviz to generate diagrams, but other
backends may be added in the future.
The main purpose of hiearch is graphical representation of complex systems,
but it is meant to be generic and may find other applications.
Why would anyone need another diagram generator when there are many other tools
supporting UML, C4, etc? I believe that the most important aspects of the system
are its decomposition into components and connections between them, hiearch
provides just that, nothing more, so that you can focus on documenting your
system rather than fitting it into a specific design framework.
-
hiearchdoes not use a DSL, but rather parses a set of inputyamlfiles in arbitrary order. The file contents get composed into a single description, which, in turn, gets decomposed into views. -
hiearchalso accepts input files ingraphvizformat withdotorgvextension.graphvizfiles are internally converted tohiearchrepresentation. This wayhiearchviews can be applied tographvizfiles generated by other tools. -
Description files have flat structure without nesting or inclusion and contain lists of the following objects: nodes, edges, and views. Hierarchical relations between nodes are specified using node parameters.
-
Unlike
graphviz,hiearchdoes not have a concept of subgraphs: each node may automatically become a subgraph depending on a view. -
hiearchis also somewhat stricter thangraphviz: for example, all nodes must be defined explicitly and cannot be deduced from edge definitions. -
View is not the same thing as
graphvizlayer https://graphviz.org/docs/attrs/layer/:graphvizplaces all nodes on each layer and simply makes some of them invisible, which results in awkward spacing. -
hiearchallows nodes to have multiple parent nodes, which is referenced here as ‘multiscoping’. The idea is, of course, to show parents in different views, for example, to outline system from logical or hardware point of view. However, it is possible to visualize all parents in the same diagram, which may be a bit kinky. -
hiearchsupports label templates, which facilitates automatic generation of URLs, tables, icon inclusions, etc. -
There are a few predefined styles distributed with the utility, e.g., for generation of state machine graphs.
pipx install hiearch
usage: hiearch [-h] [-o OUTPUT] [-f FORMAT] [-t TEMP_DIR] <filename> [<filename> ...]
Generates diagrams
positional arguments:
<filename> Input files
optional arguments:
-h, --help show this help message and exit
-o OUTPUT, --output OUTPUT
Output directory [./]
-f FORMAT, --format FORMAT
Output format [SVG]
-t TEMP_DIR, --temp-dir TEMP_DIR
Temporary files output directory (defaults to output directory)
-----------------------------------------------------------
nodes:
- id: ["Test 1", test1]
# if no views are specified explicitly, a default one is
# added with 'tags: ["default"]'
|
default |
There are several types on automated node selection:
explicit-- only explicitly specified nodes are selected;direct-- explicitly specified and their direct connections;parent-- similar todirect, but instead of directly connected nodes their top-most parents (scopes) are selected;recursive_in,recursive_out,recursive_all-- recursively expand connections of explicitly selected nodes.
nodes:
- id: ["Test 1", test1]
# https://www.svgrepo.com/svg/479843/duck-toy-illustration-3
# https://www.svgrepo.com/svg/479405/casa-pictogram-5
graphviz:
node_label_format: '<<table><tr><td><img src="https://raw.githubusercontent.com/asherikov/hiearch/master/icon_{id}.svg"/></td><td>{label}</td></tr></table>>'
scope_label_format: '<<table><tr><td><img src="https://raw.githubusercontent.com/asherikov/hiearch/master/icon_{id}.svg"/></td><td>Scope: {label}</td></tr></table>>'
- id: ["Test 2", test2]
scope: test1
- id: ["Test 3", test3]
tags: []
substitutions:
suffix: '!'
graphviz:
node_label_format: '<<table><tr><td><img src="https://raw.githubusercontent.com/asherikov/hiearch/master/icon_{style}.svg"/></td><td>{label}{suffix}</td></tr></table>>'
- id: ["Test 4", test4]
style: test3
views:
- id: view1
nodes: [test1]
- id: view2
nodes: [test1, test2]
- id: view3
nodes: [test4]
Note that SVG with other embedded SVG is not always rendered properly, and
embedded pictures may get lost during conversion to other formats. The PNG files
below were generated with
rsvg-convert view1.svg --format=png --output=view1.png, exporting directly to
PNG using graphviz won’t work. Also, the included images must be present in the
output directory.
view1 |
view2 |
view3 |
- All predefined styles are automatically added to input files on invocation of
hiearch. - Generally it is necessary to override tags inherited from style nodes.


