29, Oct 2022 ~ 6 min read
Universal Monorepos
Truly understand how easy it is to use the monorepo project structure.
Image by Brigad Engineering React Native Monorepos
Listen to something with me đ
Want to listen somewhere else? đ§Table of Contents
- Us JavaScript Developers
- What is a monorepo?
- Disadvantages to using monorepos
- Advantages to using monorepos
- Conclusion
- References
Us JavaScript Developers
Have you ever found yourself thinking, âhow can I easily build my project?â Where you have to use something on the frontend, backend, database or even a mobile app? Well, if using mostly JavaScript for development just like me you might think⌠well Iâll just use what I know best and you end up with something like this
Choose JavaScript, @frontenddude
Well if youâre in that type of predicament, in this article I will go over why you might consider using a monorepo setup to accelerate your development speed. But what is a monorepo?
What is a monorepo?
In version-control systems, a monorepo (âmonoâ meaning âsingleâ and ârepoâ being short for ârepositoryâ) is a software-development strategy in which the code for a number of projects is stored in the same repository. This practice dates back to at least the early 2000s⌠wikipedia
A monorepo is a manner of structuring your project inside one repository, as opposed to having multiple projects that are scattered across multiple repositories. Monorepos are not a one key fits all solution, itâs just a way of structuring your project. Projects structured in this manner have a several pros and cons. Letâs go over them.
Note: Monorepos are not
monoliths
, a monolith project is a project that has all the components of your project in one codebase. Where the application grows in complexity when ever there is an additional feature. Whereas a monorepo is concerned with having your project structured into smaller sub-projects each with their own codebase and sharing them across asshared libraries
.
Disadvantages to using monorepos
Before we go over the good side of using monorepos, I want to first shed light on the challenges of working with monorepos. Most of these I am going to refer to them from my perspective as a TypeScript/JavaScript developer.
-
Project Setup: Project setup in Javascript projects comes with a learning curve and that applies to monorepo projects as well. IMO, itâs even more challenging to setup a monorepo project structure. This comes down to understanding how
NodeJS
,Browsers
andlibraries
behave and how they work with our code. When weâre just starting out, we might be overwhelmed when making all these considerations. I believe itâs better to understand concepts like these before dabbling in monorepos. Here are some of my articles on this topic -
Bad Performance: I guess this is one of the annoying one, because there is going to a performance hit once you have all of your codebase, backend, frontend, libraries and any other application under a single repository. You might not notice it when you start out, but once you get to finalizing your project youâll definitely see some slowness when using
git
, yourIDE
, searching through your code. But that might just be an annoying thing to deal with considering the benefits ormonorepos
. -
Breaking Changes: Imagine youâre working on a project, a NodeJS, where you have multiple custom libraries you built. Assume you have all of these libraries are being shared through a
npm
. The best part about this workflow is you can deploy a working version of library and continue working on it making breaking changes and it wont affect your other codebase that is using that library unless you explicitly push a breaking change ontonpm
. Even assuming you pushed a breaking change tonpm
, if you have versioning properly handled you can still keep working without having to upgrade.This situation is different when using monorepos, if you have a breaking change in one of the sub-projects inside your monorepo, youâre going to have to fix to move on. Everyone else who is working on the project is either going to have wait until the breaking change is fixed, or theyâre going to help out.
-
Ownership: Ownership is also another issue, since everyone has access to all the sub-projects, youâll not be able to stop people from making changes. Either everything or nothing, thatâs kind of the workflow.
Advantages to using monorepos
If youâre here, youâre at least willing to understand the advantages of a monorepo. Well, let me explain.
- Everything is there: Monorepos give you one benefit and everything else is
going to build up on that one benefit, and that is
easier visibility
. This means everyone has access to everything about the project. All your backend API codebase, frontend logic, custom libraries youâve built maybe to share across multiple frontend applications⌠etc. This is the benefit of monorepos really, you canclone
,build
andserve
and youâre set. - Better Collaboration: Collaboration as a consequence of visibility is much better, youâre team can make changes and instantly see whatâs breaking, run unit tests across all of the codebase, you donât have to get a call saying your changes just took down the whole, at least itâs possible to make that kind of feedback happen when youâre working on a monorepo.
- Easier Standardization: Imagine youâre working on a javascript project, using
nx (a monorepo management tool),
eslint
,prettier
,jest
,typescript
. You can configure all of those tools once and each of your sub-project can follow or make changes by overriding specific rules/properties. Imagine yourbackend
,web app
andmobile app
having the same column width. Yhea, you donât have to be angry when some other team is using120
and you religiously prefer80
column width⌠didnât think that was possible too⌠- Deployment: When deploying a monorepo project, everything is included within one directory. All the information, dependencies and configuration. For those reasons the deployment process is clear, compared to how a multirepo project handles deploying a system.
- Easier to Refactor: Refactoring & making changes across multiple is as simple as it can get.
Conclusion
There is a fascinating article form Microsoft on Using monorepos during early in a project, It actually points out the benefits of monorepos is to accelerate a projects development which is very important during development phases of a project. I believe this where monorepos shine⌠they provide flexibility, freedom and speed for teams.
References
- What is monorepo?, semaphoreci.com
- Monorepo, wikipedia
- Advantages of monorepos, danluu.com
- Using monorepos to increase velocity during early stages of product development, devblogs.microsoft.com
- Benefits and challenges of monorepo development practices, circleci.com