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
Tweet

More Decks by Denis Brumann

Other Decks in Programming

Transcript

  1. An intro to
    Deptrac
    Denis Brumann
    [email protected]

    View Slide

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

    View Slide

  3. Architecture

    View Slide

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

    View Slide

  5. View Slide

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

    View Slide

  7. View Slide

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

    View Slide

  9. View Slide

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

    View Slide

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

    View Slide

  12. Dependencies

    View Slide

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

    View Slide

  14. View Slide

  15. View Slide

  16. class-likes
    functions
    constants

    View Slide

  17. Deptrac

    View Slide

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

    View Slide

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

    View Slide

  20. View Slide

  21. Concepts

    View Slide

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

    View Slide

  23. View Slide

  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.

    View Slide

  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.

    View Slide

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

    View Slide

  27. View Slide

  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.

    View Slide

  29. View Slide

  30. View Slide

  31. View Slide

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

    View Slide

  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.

    View Slide

  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.

    View Slide

  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

    View Slide

  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

    View Slide

  37. View Slide

  38. View Slide

  39. View Slide

  40. Examples

    View Slide

  41. View Slide

  42. View Slide

  43. View Slide

  44. View Slide

  45. View Slide

  46. View Slide

  47. View Slide

  48. Setup

    View Slide

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

    View Slide

  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.

    View Slide

  51. View Slide

  52. Contributing

    View Slide

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

    View Slide

  54. View Slide

  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

    View Slide

  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

    View Slide

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

    View Slide