Chaos meter measure various metrics of a dependency graph. Those metrics represent the software entropy. Unlike the classic code analyser tools, Chaos Meter focuses on the dependencies between the components of a software project. The goal is to provide a better understanding of an existing software architecture and to identify potential issues.
Steps:
- Build the project graph
- Analyse the graph
Currently, the tool supports building the graph of javascript, typescript and java projects.
To build the graph of a frontend project, you need to install Madge. Madge is a tool that generates a graph of your file dependencies. It works with both CommonJS and ES6 module syntax, and it works with both JavaScript and TypeScript.
Install Madge globally:
npm install -g madge
Execute this command to build the graph:
madge --extensions ts --exclude '.*.spec.ts' ./src > project-name.madge
To build the graph of a backend project, we use jdeps. jdeps is a tool that generates a graph of your file dependencies. jdeps is able to analyse a jar but is not able to recursively analyse a fat jar.
For applications that are not modularized, you can use the following command to generate the graph:
jdeps -verbose:class -e com.example.* application-jar.jar > project-name.jdeps
For applications that are modularized (i.e hexagonal applications), you can use a similar command to generate the graph:
jdeps -verbose:class -e com.example.* **/target/**SNAPSHOT.jar > project-name.jdeps
Note that the -e flag is used to only include the se.hms package in the graph.
Another way could be to unpack the fat jar and target the relevant jars in a single call to jdeps like in the previous example.
usage: Software Entropy calculator [-h] -g GRAPH -m {cycle,in-degree,out-degree,centrality-degree,flow-hierarchy,density,topology} [-e EXCLUDE]
Tool used to measure various metrics of a software dependency graph.
options:
-h, --help show this help message and exit
-g GRAPH, --graph GRAPH
The file containing the dependency graph. Example: "path/to/graph.<jdeps|madge|graph>"
-m {cycle,in-degree,out-degree,centrality-degree,flow-hierarchy,density,topology}, --metric {cycle,in-degree,out-degree,centrality-degree,flow-hierarchy,density,topology}
The metric to output
-e EXCLUDE, --exclude EXCLUDE
Regex to identify the components to be excluded from the analysis. This allows to differentiate models from logical components and have more relevant results. Example: ".*\.model\..*|.*\.entity\..*|.*\.dto\..*"
Compute the density of a graph
python3 chaosmeter.py -g path/to/graph -m density
Compute the topology of a graph by excluding models from the analysis
python chaosmeter.py -g path/to/graph -e ".*\.model\..*|.*\.entity\..*|.*\.dto\..*" -m topology