DATEV Nine-Nine | Nx Monorepo Undercover Mission

DATEV eG
DATEV TechBlog
Published in
5 min readAug 26, 2021

Von: Matthias Alt, Stephan Bierwirth und Gerrit Riesch

Let’s get started

We — your “three detectives” Gerrit, Matthias and Stephan — would like to tell you about our mission within a Nx Monorepo, the possibilities and some difficulties the framework comes with.

What is Nx?

Nx is a collection of dev tools developed by Nrwl Technologies designed to help developers to code, test, build and scale a web application inside a monorepo.

By default, supported web application frameworks are:

- Angular
- React
- Node

It is also possible to use other application frameworks like SpringBoot by integrating plugins into your Nx workspace. That said, there is an active community developing a multitude of community plugins. You should definitely check them out! There is even support for Dart and Go.

What is the purpose of Nx?

Nx’s self-proclaimed goal is to support development teams “to develop like Google, Facebook and Microsoft”. That might sound a little extreme but to put it a little less polarizing: Nx can help you to manage big monorepos and enforce rules, just like a lot of big IT companies do and will be useful in small and big repositories alike.

In advance, it should be mentioned that Nx is not an out-of-the-box solution for every kind of project, but also that it is not restricted to huge code bases.

The tools and best practices provided by Nx can be used for projects of any size. They help developers to stick to best practices as well as to simplify common tasks. For example, achieving well documented and adaptable dependency management inside a big application with multiple libs or modules. Those features can also be used for monolithic applications to provide a clean structure.

The following example shows a visualization of the libs and module dependency structure of an app. Here the boxes represent apps and the ovals are all the libs that are used in these apps. Arrows represent dependencies between an app and a lib, where the arrow points to the dependency used. A dashed line indicates a lazy loaded dependency. What lazy loading in this context means, will be explained in a future post.

MicroFrontends vs. MonolithicApp

Sometimes we must decide which project architecture is the best way to go for us. No matter in which direction you are going, the usage of Nx can offer a lot of benefits. To help with a migration, there is a guide on how to migrate an existing angular application into a Nx monorepo.

There is a lot to consider when starting with a new app/project and one thing is to which degree you should separate the codebase and the artifacts. Manfred Steyer — a renowned Angular expert, author and coach — has provided a useful decision tree to help you figure out whether you should go for a monorepo or one of the other choices. That way you can check in advance whether a monorepo is even the best fit for your project.

The graph should also help you decide whether your frontend application should be separated into multiple Single Page Applications (MicroFrontends) or remain a monolithic app which uses libs to provide features for our users.

Monorepo Decision Tree. Adopted from: Steyer, M. S. (2020). Enterprise Angular DDD, Nx Monorepos and Micro Frontends (3rd ed.) [E-book]

Jest instead of Jasmine | Cypress instead of Protractor

By default, Nx uses Jest and Cypress for testing. You can also switch to Jasmine and Protractor in Nx, but they don’t come out of the box.

If you are using Jasmine and want to migrate to Jest, there is a guide leading you through the necessary steps. This is especially useful when you want to migrate an existing Angular application to a Nx monorepo, which is also a topic we will elaborate on in the future.

Furthermore, there are multiple supported plugins for modern tools like Storybook.js, which also provide their own schematics.

Affected-Commands

With a growing number of libs and apps we always have an increased amount of tests and artifacts. This often leads to long running builds and test-suites. Nx helps us to reduce this increase by executing tests and build-processes only for the parts of our application that are affected by our changes.

Nx provides this feature primarily by comparing two commits and determining the changed files. With this information Nx can detect the apps and libs which should be rebuilt or tested.

Set boundaries for your libs

As already mentioned, NX provides a feature to show dependencies inside your application. Furthermore, there is a possibility to provide boundaries and access rules for your libs and modules. This enables you to define rules based on labels to enforce rules like e.g. “libs tagged with ‘type:data-access’ can only access libs tagged with ‘type:data-access’ and ‘type:util’”. These rules can be applied by esLint, which means Nx enables you to lint your software-architecture.

Conclusion

In this blog post we barely scratched the surface of the possibilities Nx provides. In the coming months we will revisit most of the topics we mentioned here and will investigate them further to reveal more benefits of Nx Monorepos. We also want to share our experiences and the learnings we gathered over the past months working with nx.

We hope you enjoyed our first post and we would love to see next time!

Your three DATEV Nine-Nine detectives,

Matthias Alt (LinkedIn)

Stephan Bierwirth (LinkedIn)

Gerrit Riesch

--

--

DATEV eG
DATEV TechBlog

DATEV eG steht für qualitativ hochwertige Softwarelösungen und IT-Dienstleistungen für Steuerberater, Wirtschaftsprüfer, Rechtsanwälte und Unternehmen.