Clean software architecture with Deptrac
If you work on modernizing legacy code, one of the goals you are probably going for is to disentangle the code. Over time, you want to create an architecture where you have cleanly separated layers that have clearly defined dependencies.
Whenever you work on a greenfield project, you try to adhere to a clean architecture from the outset - but features pile up, deadlines loom, and in the later phases of a project, focus shifts from building clean code to building features and fixing bugs.
In both scenarios, a tool to provide some metrics can help - so we built one!
Deptrac helps you keep dependencies between the layers in your architecture under control. It provides you with insight into the current state of these dependencies, and warns you when you introduce new unwanted ones.
Deptrac is a small CLI tool that you can integrate into your toolchain. A single YAML file is used to configure layers and rules, although you can utilize multiple config files to provide different perspectives on you project architecture.
You first configure your layers (such as domain model and application services) and how PHP classes are assigned to them. Often times, matching the FQCN to a pattern will be enough, but more complex setups are possible.
Once layers are configured, Deptrac will be able to render an overview of layer dependencies in your project. We can render dot files and display them using Graphviz, but more complex views are planned - interactively drilling down into the graph using a JS rendered view, for example. Your help is welcome!
Defining rules tells Deptrac if certain dependencies it finds are allowed, or if they violate your layer separation. If Deptrac finds a violation, say, a low- level model that depends on an application service, it will report those violations in its output and exit with an error status. That means dropping Deptrac into your CI pipeline can alert you of any bad dependency someone introduces to the project.
Where to go from here
Deptrac is created and maintained by Tim Glabisch with the help the Sensiolabs Team. It is in an early alpha state, so we appreciate any testing and contributions from the community!
Clean software architecture with Deptrac symfony.com/blog/clean-software-architecture-with-deptracTweet this
Become a certified developer! Exams are online and available in all countries.Register Now
Comments are closed.
To ensure that comments stay relevant, they are closed for old posts.