It is a common assumption that production code should not depend on anything from the test code. Or in a layered architecture, a middleware component should not depend from an application component. It should always be the other way around.

Breaking the design sometimes seems like a nice way to workaround or quickly fix an issue. But most often it leads to unnecessary technical debt which needs to be paid back in the future. Debt comes with an interest - it gets often tricky to fix a design issue because new things are building on top of the bad design and bigger and bigger refactoring needs arise. That's why one wants to make dependency rules visible and prevent violations already before new code is merged to the main branch.

How dependency rule violations show up in pull requests

In oneliner impact report comment, you will get a short summary about the impact of your pull request. If there are rule violations, the amount of violations will be shown. Details of the violations can be seen by clicking the violations text.

To prevent intentional and unintentional breaking of the design with bad dependencies, Softagram lets you define dependency rules for your projects.

A dependency rule will automatically give you a warning in the pull request impact report if an unwanted dependency is being added.

How to add dependency rules to your project

You can easily add dependency rules to your project in Softagram. Just add a .softagram.json  file to the root of your repository, or add them on fly from the Softagram project settings.

Please think about the explicit or implicit dependency rules for your project, decide which rules are the most important to cover first, then read the reference for Softagram's dependency rules JSON format.

If you need help setting up good dependency rules for your project, just let us know. We are happy to help.

Sample dependency rules

Here's a simple example of how the design rules JSON could look like in a project. Note that all the file paths are naturally project-specific.

            "DepRule", ".../middleware", "-!->", ".../ui",
            {"description": "Middleware components must not use any UI code"}
            "DepRule", ".../src/models", "-!->", ".../src/view",
            {"description": "There should be no dependencies from business models to presentation views"}
            "DepRule", ".../junit junit of version 4.0.0", "<--", "Nothing",
            {"description": "Junit 4.0.0 should not anymore be used anywhere"}

Softagram does not yet provide an automated mechanism for testing different dependency rules before taking them into use but please ping us in the chat and we can do some tricks for you.

Read next: Full Softagram dependency rules reference

Did this answer your question?