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 full-size slide

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

    View full-size slide

  3. Architecture

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

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

    View full-size slide

  9. Dependencies

    View full-size slide

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

    View full-size slide

  11. class-likes
    functions
    constants

    View full-size slide

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

    View full-size slide

  13. ----------- --------------------------------------------------------------------------------------------------------------------------------
    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 full-size slide

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

    View full-size slide

  15. 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 full-size slide

  16. 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 full-size slide

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

    View full-size slide

  18. 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 full-size slide

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

    View full-size slide

  20. 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 full-size slide

  21. 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 full-size slide

  22. 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 full-size slide

  23. 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 full-size slide

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

    View full-size slide

  25. 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 full-size slide

  26. Contributing

    View full-size slide

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

    View full-size slide

  28. 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 full-size slide

  29. 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 full-size slide

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

    View full-size slide