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. An intro to Deptrac Denis Brumann [email protected]

  2. Denis Brumann Solutions Architect Current Maintainer of Deptrac [email protected] @dbrumann

  3. Architecture

  4. Component-based Tiers/Layers Domain Driven Design Service Oriented Architecture Microservices

  5. None
  6. By segregating an application into tiers, developers acquire the option

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

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

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

    should apply to them. Deptrac is not tied to any architectural pattern.
  12. Dependencies

  13. Package installed via composer Extensions/Plugins Utilities/Helpers Framework

  14. None
  15. None
  16. class-likes functions constants

  17. Deptrac

  18. Deptrac is a static code analysis tool for PHP that

    helps you communicate, visualize and enforce architectural decisions in your projects.
  19. ----------- -------------------------------------------------------------------------------------------------------------------------------- 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 -------------------- -----
  20. None
  21. Concepts

  22. AST Parser reads code from a file and gives us

    a traversable structure telling us what each node represents
  23. None
  24. 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.
  25. 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.
  26. Collectors Collectors decide which dependencies belong to a layer. Usually,

    you provide a regex for the name here.
  27. None
  28. 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.
  29. None
  30. None
  31. None
  32. Violation Signifies a rule violation, i.e. a dependency from one

    layer interacts with another dependency from a layer that was not allowed.
  33. 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.
  34. 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.
  35. 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
  36. 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
  37. None
  38. None
  39. None
  40. Examples

  41. None
  42. None
  43. None
  44. None
  45. None
  46. None
  47. None
  48. Setup

  49. composer require qossmic/deptrac-shim phive install deptrac Download Release on GitHub

  50. Create a deptrac.yaml configuration file using the init command or

    manually You can look at Deptrac to get an idea, what is possible.
  51. None
  52. Contributing

  53. “Roadmap" Official extension-support Easier configuration (switch to PHP) Improve docs

    Improve E2E-Tests Release automation
  54. None
  55. 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
  56. 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
  57. Links Project: https://github.com/qossmic/deptrac Docs: https://qossmic.github.io/deptrac QOSSMIC: https://qossmic.com