Dep-check: The Road to a Cleaner Architecture

A Python & Go dependency checker

Ilan Piperno
LumApps Experts
3 min readSep 11, 2019

--

Why architecture matters

There are many reasons you haven’t considered a project’s architecture — or not enough.

Maybe you never really had to, because you only had to deal with small projects and it worked just fine. Maybe you’re really excited by this particular project and you want to get on with it right away. Or maybe no one in your team really knows anything about architecture.

But with big projects, a strong and reliable architecture becomes essential. Take, for example, LumApps’ monolith. Despite a nice MVC segregation, some problems began to happen.

As the Monolith grew bigger and became more complex, the controllers started to import one another, leading to some circular dependencies, which you absolutely want to avoid. The result is clear: any modification in a single file/function could affect many more, making it difficult to develop new features.

That’s when we decided to chose an architecture principle and stick to it.

Clean Architecture principles

Among the multitude of different existing architectures, we chose to follow the rules of the Clean Architecture by Robert C. Martin. The main idea is to split your code/classes into four layers:

The four layers of Clean Architecture

The Clean Architecture is based on five SOLID principles:

  • Single-responsibility principle: a module should be responsible to one, and only one, actor.
  • Open-closed principle: a software artifact should be open for extension but closed for modification.
  • Liskov substitution principle: subclasses should be substitutable for their base classes.
  • Interface segregation principle: many client specific interfaces are better than one general purpose interface.
  • Dependency inversion principle: source code dependencies should refer only to abstractions, not to concretions.

On top of these principles, each module can only import modules in the layers below it. When applying Clean Architecture, the code becomes very easily testable, scalable and maintainable. Plus, a quick look at the use cases can be enough to understand what the project does, and how it does it.

Dep-check: a helpful tool

If you want to follow Clean Architecture guidelines, it can be hard to keep track of which module imports which, and to determine which layer a particular module belongs to.

This is where dep-check comes on stage. This open-source Python tool browses every relation within your source files and checks that they’re in accordance with the rules you wrote in a configuration file. This way, you can make sure that every dependency in your code is allowed by your rules, as every unauthorized import will be displayed on your screen.

The icing on the cake: if you’re having a hard time picturing your project architecture, dep-check also provides a feature to draw a highly customizable graph of your project dependencies, allowing you to clearly define and identify your architecture levels. You can see some examples here!

--

--