Your app is wasting potential

Your app is wasting potential

The benefits of a monorepo and small tooling guide

Don't miss out on the great benefits of a monorepo. This post is about monorepos, it's benefits and how to get started with NX or Turborepo.

Benefits

One merge request per feature

+384 lines added. -39 removed. Check out the branch on one repository and verify it works.

How does that sound? Too good to be true? In my opinion this one of the greatest benefit.

Working with multiple repositories becomes boring very fast, if you need to verify changes of your colleagues.

But not just for that. It's a hustle to keep the dependencies up to date, maintaining several build pipelines with secrets, etc.

By utilising the power of a monorepository you just checkout a branch and verify all the changes made to the app.

Reusability

One module should do one thing. It should have one responsibility.

Breaking the first principle of the SOLID acronym is unavoidable. But that does not mean, we shouldn't try our best to avoid it anyways.

Splitting up a big application into several smaller standalone packages is rather difficult. It doesn't get easier when the friction of creating a new package is high too.

In a polyrepository setup the developer would need to create a new repository in order to share some common code: extracting code into a separate package.

This will either result in code duplication or violating the single responsibility principle.

Inside a monorepo setup this friction is reduced. It even becomes fun. With the correct tooling this might become as easy as running a generator that setups a complete angular library up for you.

In shorter terms: It's about reducing the overhead.

No breaking changes

All packages in your repository have the same major version. If a breaking change occurs the solution is simple: change the client code that uses the API.

Note: Angular is a great example for this.

Transparency

It's a daunting task to switch the current IDE folder to include another repo just to look some line of code up.

Monorepos aim to have all the relevant code at the developers hand and therefore prevent context switching.

Tools

I myself have tried NX and Turborepo. In my opinion those both are great tools and which one to chose depends on the tech stack you're working with.

NX

Although NX supports other libraries, like Vue, React, NextJs, etc. I highly recommend it for every Angular developer, since it seems like Angular is supported best.

It comes with a great plugin system that can not only be used to extend the functionality of NX itself, but also to create custom code generators.

Furthermore I like their aim for remote computation caching.

Remote computation caching

Instead of caching the build artefacts for a specific input file hashsum on the local hard drive, the artefact is uploaded to a server and retrieved by other machines, when the checksums match.

This means: I build the master branch locally and my colleagues does the same thing 3 minutes later with the same input files. He won't actually build it, but rather fetch it from the server.

Easy onboarding for Angular

NX has extensive documentation and tools to migrate existing applications to a monorepo. They work very well.

Somewhat overkill (when not using Angular)...

After my short experience with my Expo project it felt bloated and heavyweight.

Furthermore it felt like, if you do something different things become unsupported real quick.
This does not mean you have to stop there, but invest the time to create custom plugins.

Turborepo

My current go to for Expo setups. I have ported an existing Expo managed React Native app to Turobrepo.

The biggest felt advantage compared to NX is the lightweight.

I would recommed Turborepo to get started with monorepos in the nodejs world, if you are not using Angular.

It utilises npm/yarn workspaces under the hood and provide a simple abstraction to run common tasks.

However Turborepo is lacking a good code generation system. NX is unbeatable from that perspective.

Conclusion

Monorepos in modern day web development have great potential for big applications. If you want to get started with a basic application consider NX or even simpler: Turborepo. Both shine at their spots.

Subscribe to the newsletter

Next weeks post will be about the bad sides of a monorepo. Sounds interesting? Then don't miss it by subscribing to the newsletter. We'll deliver it straight to your inbox.