DEV Community

Cover image for Understanding Monorepo: A Deeper Dive
Ukpai Chukwuemeka
Ukpai Chukwuemeka

Posted on

Understanding Monorepo: A Deeper Dive

Hey Devs! , In our previous chat, we talked about monorepos.

If you missed the previous chat Understanding Monorepo, here’s a quick recap; A monorepo is one big repository that houses all of your projects. These projects, packages, or libraries are typically linked by common rationale or business requirements.

Now, you might be thinking, Why would I want to put all my projects into one big repository? Fair question!

In this post we will be diving a little deeper into the rabbit hole, so grab your favorite caffeinated brew.

Let us look at some of the benefits of monorepo:

Benefits of monorepo

1. Code Sharing: It is super easy to share code, packages, and libraries in a monorepo, the copy-and-paste marathons between projects are no more You can write it once and use it across all platforms. You can even publish directly to a public registry.

2. Code Reuse: Monorepo makes your work efficient, the clever little function you wrote at 2 AM. You can reuse it across apps, packages, or libraries inside a monorepo with just a quick import.

3. Sharing Types: As a typescript fan, your types can now roam free across your codebase like happy little electrons.

4. Easy Bugs Fix: In a monorepo, resolving bugs across multiple projects is easy. It eliminates the need to hop between repositories like a caffeinated kangaroo.

5. Faster Development: Words on the street is that monorepos are flipping software development on its head. Some folks are saying it is like strapping a rocket to your development process — you build, ship, and tweak faster than ever.

Monorepos are pretty sweet, right? But hold up monorepos aren’t all unicorns and rainbows. They’ve got their challenges too.

Monorepo Challenges

  • Managing a large codebase can be complex, especially for new team members.

  • Merging changes and resolving conflicts can be more difficult if not well configured.
    Specialized tools are often needed to manage monorepos effectively.

  • Cloning a large monorepo codebase might take a lot of time, especially with bad connectivity, but i guess this doesn’t count.

  • A monorepo requires a more sophisticated CI setup.
    Lastly, it requires you to think about large-scale changes.

Choosing the Right Monorepo Tool

To mitigate the challenges and fully leverage the benefits of monorepos, selecting the right tools is crucial and there are various tools out there. These tools are also what makes monorepo tick. Some popular options include:

  • NX: A versatile, smart, and fast-build system with features like caching and parallel execution.

  • Bazel: Google’s build system on steroids, A high-performance build system, especially suitable for large-scale projects, it is open source and i believe it is owned and used by Google internally too.

  • NPM, Pnpm, and Yarn: The holy trinity of JavaScript package managers, they are popular package managers that can be used in monorepo setups. I think this too can be challenging to manage.

  • Turbo Repo: A modern monorepo tool with a focus on performance and developer experience. Vercel’s new kid on the block

  • Lerna: The OG monorepo tool with a focus on flexibility.

  • Rush stack: Microsoft’s scalable monorepo manager.

  • Git submodules: A more traditional approach, but can be challenging to manage. Also for those who like to keep it old-school.

Monorepo structure
There are two types of monorepo structures, and the structure is determined by what you plan on building or your use case.

Package-centric is used for developing and publishing an organized collection of reusable packages. This is a common setup in the open-source world and can be seen in repositories such as Angular, React, Vue, and many others. Those repos are characterized by most commonly having a packages folder which are then commonly published to some public registry such as NPM.

App-centric is used mainly for developing applications and products. This is a common setup in companies. Such repos are characterized by having an apps and packages or libs folder, where the apps folder contains the buildable and deployable applications, while the packages or libs folder contains libraries that are specific to one or multiple applications that are being developed within the monorepo. You can still also publish some of these libs to a public registry.

Your Thoughts on Monorepos

Do you think the benefits of monorepos outweigh the challenges? Have you had experience using monorepos in your projects? Share your thoughts and experiences in the comments below.

In our next post, we will dive deeper by setting up a monorepo using just pnpm.

Stay tuned! Happy coding!

Top comments (0)