Upgrade to Pro — share decks privately, control downloads, hide ads and more …

An intro to Deptrac

An intro to Deptrac

Deptrac is an open source, static analysis tool for PHP developed at QOSSMIC. It allows you to freely define your desired architecture and will check if your code adheres to these architectural rules. It makes the output more useful for humans by allowing for graphical representations and can be easily hooked into your pipeline to automate architectural checks in your development process.

This talk focuses on architectural styles and important concepts relevant to Deptrac and gives a quick overview of Deptrac's internals and shows a few examples of configurations for specific projects and what the graphical representation of the architecture looks like.

Denis Brumann

October 27, 2022

More Decks by Denis Brumann

Other Decks in Programming


  1. By segregating an application into tiers, developers acquire the option

    of modifying or adding a specific tier, instead of reworking the entire application.
  2. Under domain-driven design, the structure and language of software code

    (class names, class methods, class variables) should match the business domain.
  3. ! Hot Take Most microservices are just an attempt to

    achieve what Deptrac can give you in a monolithic project.
  4. You can freely define your architectural layers and which rules

    should apply to them. Deptrac is not tied to any architectural pattern.
  5. Deptrac is a static code analysis tool for PHP that

    helps you communicate, visualize and enforce architectural decisions in your projects.
  6. ----------- -------------------------------------------------------------------------------------------------------------------------------- Reason Repository ----------- -------------------------------------------------------------------------------------------------------------------------------- Violation examples\MyNamespace\Repository\SomeRepository must not

    depend on examples\MyNamespace\Controllers\SomeController (Controller) /Users/dbr/workspace/qossmic/deptrac/examples/ControllerServiceRepository1/SomeRepository.php:5 ----------- -------------------------------------------------------------------------------------------------------------------------------- -------------------- ----- Report -------------------- ----- Violations 1 Skipped violations 0 Uncovered 0 Allowed 4 Warnings 0 Errors 0 -------------------- -----
  7. AST Parser reads code from a file and gives us

    a traversable structure telling us what each node represents
  8. Layers In object-oriented design, a layer is a group of

    classes that have the same set of link-time module dependencies to other modules.
  9. Layers In Deptrac a layer is a group of dependencies,

    e.g. class- likes, functions, … pretty much anything that can be referenced in your code and checked against.
  10. Ruleset Assign which layers a layer can interact with. The

    analyser will check if a dependency is from an allowed layer or not based on this list.
  11. Violation Signifies a rule violation, i.e. a dependency from one

    layer interacts with another dependency from a layer that was not allowed.
  12. Warnings/Errors Something went wrong, that is not tied to your

    architecture rules, e.g. a class is assigned to multiple layers or circular references are encountered.
  13. Uncovered A dependency that was found when collecting all dependencies,

    but that is not covered by architecture rules, i.e. is never a depender/ dependee. Unassigned A dependency, which is not assigned to any layer.
  14. Debug Commands debug:layer Checks which tokens belong to the provided

    layer debug:token Checks which layers the provided token belongs to debug:unassigned Lists tokens that are not assigned to any layer
  15. Analyse Options Options: -f, --formatter[=FORMATTER] Format in which to print

    the result of the analysis. -o, --output[=OUTPUT] Output file path for formatter (if applicable) --fail-on-uncovered Fails if any uncovered dependency is found --report-uncovered Report uncovered dependencies --report-skipped Report skipped violations --no-cache Disable caching mechanisms (wins over --cache-file) --clear-cache Clears cache file before run --cache-file=CACHE-FILE Location where cache file will be stored -c, --config-file=CONFIG-FILE Location of Depfile containing the configuration
  16. Create a deptrac.yaml configuration file using the init command or

    manually You can look at Deptrac to get an idea, what is possible.
  17. https://symfony.com/slack #deptrac Feel free to open issues with questions and

    ideas. I often create tickets which can be picked up. Many contributors are around here and can help
  18. Image Credits alberto-frias-5jU39pgAAiw-unsplash.jpg arham-jain-OkiDTYxLo34-unsplash.jpg barn-images-t5YUoHW6zRo-unsplash.jpg benjamin-trosch-k_9alJ82fHw-unsplash.jpg brandable-box-8mCsyImZRGY-unsplash.jpg christian-wiediger-ZQfh9jKN2x0-unsplash.jpg clark-van-der-beken-Tk0B3Dfkf_4- unsplash.jpg

    felipe-lopez-Z1CvnN-62WU-unsplash.jpg jack-monach-5gcM189YA7o-unsplash.jpg jessica-lee-o5GGlwHfff8-unsplash.jpg joel-filipe-RFDP7_80v5A-unsplash.jpg julie-molliver-Z3vFp7szCAY-unsplash.jpg kirill-martynov-ym9Y0JaQV3w-unsplash.jpg krakenimages-376KN_ISplE-unsplash.jpg kwon-junho-XnStUQIto50-unsplash.jpg lucas-hoang-kqgC_6j6AaA-unsplash.jpg markus-spiske-KWQ2kQtxiKE-unsplash.jpg markus-spiske-kK7uPfb2YWU-unsplash.jpg marvin-meyer-HN1roKF-DS4-unsplash.jpg maxim-tajer-x3S1aGQNgro-unsplash.jpg michael-dziedzic-0W4XLGITrHg-unsplash.jpg sebastien-barbieri-7iVlj27eBfM-unsplash.jpg sen-rgP93cPsVEc-unsplash.jpg shubham-dhage-gC_aoAjQl2Q-unsplash.jpg simone-hutsch-8p6pdSkA-6A-unsplash.jpg tingey-injury-law-firm-L4YGuSg0fxs- unsplash.jpg ussama-azam-UsytIKHkAKk-unsplash.jpg