Slide 1

Slide 1 text

An intro to Deptrac Denis Brumann [email protected]

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

Architecture

Slide 4

Slide 4 text

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

Slide 5

Slide 5 text

No content

Slide 6

Slide 6 text

By segregating an application into tiers, developers acquire the option of modifying or adding a specific tier, instead of reworking the entire application.

Slide 7

Slide 7 text

No content

Slide 8

Slide 8 text

Under domain-driven design, the structure and language of software code (class names, class methods, class variables) should match the business domain.

Slide 9

Slide 9 text

No content

Slide 10

Slide 10 text

! Hot Take Most microservices are just an attempt to achieve what Deptrac can give you in a monolithic project.

Slide 11

Slide 11 text

You can freely define your architectural layers and which rules should apply to them. Deptrac is not tied to any architectural pattern.

Slide 12

Slide 12 text

Dependencies

Slide 13

Slide 13 text

Package installed via composer Extensions/Plugins Utilities/Helpers Framework

Slide 14

Slide 14 text

No content

Slide 15

Slide 15 text

No content

Slide 16

Slide 16 text

class-likes functions constants

Slide 17

Slide 17 text

Deptrac

Slide 18

Slide 18 text

Deptrac is a static code analysis tool for PHP that helps you communicate, visualize and enforce architectural decisions in your projects.

Slide 19

Slide 19 text

----------- -------------------------------------------------------------------------------------------------------------------------------- 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 -------------------- -----

Slide 20

Slide 20 text

No content

Slide 21

Slide 21 text

Concepts

Slide 22

Slide 22 text

AST Parser reads code from a file and gives us a traversable structure telling us what each node represents

Slide 23

Slide 23 text

No content

Slide 24

Slide 24 text

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.

Slide 25

Slide 25 text

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.

Slide 26

Slide 26 text

Collectors Collectors decide which dependencies belong to a layer. Usually, you provide a regex for the name here.

Slide 27

Slide 27 text

No content

Slide 28

Slide 28 text

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.

Slide 29

Slide 29 text

No content

Slide 30

Slide 30 text

No content

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

Violation Signifies a rule violation, i.e. a dependency from one layer interacts with another dependency from a layer that was not allowed.

Slide 33

Slide 33 text

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.

Slide 34

Slide 34 text

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.

Slide 35

Slide 35 text

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

Slide 36

Slide 36 text

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

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

No content

Slide 39

Slide 39 text

No content

Slide 40

Slide 40 text

Examples

Slide 41

Slide 41 text

No content

Slide 42

Slide 42 text

No content

Slide 43

Slide 43 text

No content

Slide 44

Slide 44 text

No content

Slide 45

Slide 45 text

No content

Slide 46

Slide 46 text

No content

Slide 47

Slide 47 text

No content

Slide 48

Slide 48 text

Setup

Slide 49

Slide 49 text

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

Slide 50

Slide 50 text

Create a deptrac.yaml configuration file using the init command or manually You can look at Deptrac to get an idea, what is possible.

Slide 51

Slide 51 text

No content

Slide 52

Slide 52 text

Contributing

Slide 53

Slide 53 text

“Roadmap" Official extension-support Easier configuration (switch to PHP) Improve docs Improve E2E-Tests Release automation

Slide 54

Slide 54 text

No content

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

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

Slide 57

Slide 57 text

Links Project: https://github.com/qossmic/deptrac Docs: https://qossmic.github.io/deptrac QOSSMIC: https://qossmic.com