Define the Relationship with Monorepos

This ad is not shown to multipass and full ticket holders
React Summit US
React Summit US 2026
November 17 - 20, 2026
New York, US & Online
Upcoming event
React Summit US 2026
React Summit US 2026
November 17 - 20, 2026. New York, US & Online
Bookmark
Rate this content
Sentry
Promoted
Code breaks, fix it faster

Crashes, slowdowns, regressions in prod. Seer by Sentry unifies traces, replays, errors, profiles to find root causes fast.

Get started

A monorepo might sound like a big, intimidating thing, but we're going to break it down to just the bare essentials. A monorepo helps you better manage the relationships that already exist between your projects. Once we understand those relationships, we can use tools to very quickly define them and pull them together into a more cohesive whole.

This talk has been presented at React Summit US 2024, check out the latest edition of this React Conference.

FAQ

A monorepo is a single repository containing multiple distinct projects with well-defined relationships.

By reducing the distance of relationships between code components, monorepos allow for faster changes and immediate feedback, making iteration quicker.

A common misconception is that a monorepo is simply throwing all code into one repository without structure, which can lead to problems. It actually involves organizing multiple projects with well-defined relationships.

Reducing the distance between code components allows for faster understanding and testing of changes, as it minimizes the steps required to see the impact of a change.

Monorepos make dependencies between projects explicit and manageable, allowing developers to understand the impact of changes and trace affected areas effectively.

NX is recommended as a tool for managing monorepos, as it provides useful features to manage and understand the relationships between projects.

APIs increase the distance between code components, slowing down iteration speed due to the need for merging, packaging, and deployment before changes can be verified.

You can learn more about monorepos by visiting monorepo.tools and nx.dev for detailed information and resources.

Philip Fulcher
Philip Fulcher
6 min
19 Nov, 2024

Comments

Sign in or register to post your comment.
Video Summary and Transcription
Monorepos are single repositories containing multiple distinct projects with well-defined relationships. Relationships in code are based on distance, where code in different files is the closest relationship. By importing code from one file to another, dependencies are established, allowing for changes in one file to immediately impact the other. This enables fast iteration and development. When we separate code into packages or APIs, it increases the distance between code pieces, making it slower to understand the impact of changes. However, when multiple projects are combined in a monorepo, the relationships between them are reduced, enabling faster development. Monorepos make relationships explicit and provide tools to understand their impact. To learn more, visit monorepo.tools or nx.dev for information on managing monorepos with NX.
Available in Español: Definir la Relación con Monorepos

1. Introduction to Monorepos

Short description:

Monorepos are single repositories containing multiple distinct projects with well-defined relationships. Relationships in code are based on distance, where code in different files is the closest relationship. By importing code from one file to another, dependencies are established, allowing for changes in one file to immediately impact the other. This enables fast iteration and development.

My name is Philip Fulcher. I've got about five minutes to talk to you about monorepos. And so let's talk about it. But what do we talk about when we talk about monorepos? What even is a monorepo? And some people might say, oh, that's like when Google only has one repo for the entire company, right? And that's not what we're talking about. That is a scale of monorepo that is unfeasible for most people. You're probably not Google.

Maybe a monorepo is when you just throw all your code into one repo and then you figure it out later. And that's definitely not something that we want to do. That's going to run into all kinds of problems. So let's have a nice workable definition of a monorepo is a single repository containing multiple distinct projects with well-defined relationships. And what I really want to talk to you today is about this last element. What do we mean by well-defined relationships?

Let's think about relationships in code in terms of distance. So the closest that two pieces of your code can be related are just code that's in different files. You have a button component. It's got all your Tailwind classes that make you on-brand. And then you're going to import that button into your form to actually be able to use it. And so now there's a dependency between the form and the button. The form doesn't work without the button. And we do this all the time. And we kind of take for granted how great this relationship works for us. When you make a change in the button file, you can immediately see the change in the form. You have either a render in the browser, or you have a compilation error. Maybe you have a test suite running. That's going to tell you that there's a problem, or even lint errors. But you can understand the impact of your change immediately. And because of that, iteration is really fast. You make a change. You can see it. You can respond to it, fix it, move on to the next thing. But you're moving fast.

2. Benefits of Monorepos

Short description:

When we separate code into packages or APIs, it increases the distance between code pieces, making it slower to understand the impact of changes. However, when multiple projects are combined in a monorepo, the relationships between them are reduced, enabling faster development. Monorepos make relationships explicit and provide tools to understand their impact. To learn more, visit monorepo.tools or nx.dev for information on managing monorepos with NX.

Let's see what happens if we take that relationship sort of one step away. And think about code in packages. And if we import that button from a design system that's published by our organization, this feels really similar to what we just did. Unfortunately, we've increased the distance between these two pieces of code. And what that does is makes understanding the impact of the change slow. To make a change to the button, I make a change within the design system. I have to go through some sort of compilation or bundling process, and then publishing, and then I have to consume the latest version of the package to see the final change in my form. And that's really slow, even when you're working by yourself on a single machine.

When we talk about crossing team barriers there, your design system team has to make the change, merge, cut a release, publish. You have to consume the latest version. That is a really slow understanding of the impact of the change from the design system team. And therefore, iteration is so slow. Let's take an even further step away in terms of relationship between codes and think about APIs. Your front end has an implicit dependency on your back end. It won't function without the back end in most cases. And so if you have an API that's developed, it's hey, we all agreed at the beginning of the sprint this API endpoint was going to be called Contact Create, right? Well, it came out as Contact Init. I don't know if you've ever had changes to your back end API happen like that mid-sprint. But now this relationship is even slower than we've talked about before.

Monorepos, when you put those multiple projects all together in a single repository, are going to reduce the distance of your relationships. That change that you want to make in your button or your back end API is now co-located with the front end code that's going to consume it. And that just means that it's in the same repo, and that we can import it, and we can use all the really nice tools that help us understand the impact of that change. And with some helpful tooling from a monorepo tool, we can understand those relationships and actually trace them to determine what's been affected by our changes. So when we talk about putting all of your projects or many, many projects into a single monorepo, we feel like we're making a huge change. But we're not actually changing the relationships between the projects that we already have. What we're doing is making them explicit. We're making sure that we know that that relationship exists and how we understand the impact of changes through that relationship. And by that, those relationships are well-defined. And through that, monorepos are going to help you move faster. If you want to learn more about monorepos, please visit monorepo.tools. It's going to help you understand the monorepo concept as well as many of the tools that are available in the space. I happen to think that the best tool for you to manage your monorepo today is NX. If you're here in person, you can come talk to us at the booth. If you're online, please visit nx.dev for more information. Thank you very much.

Check out more articles and videos

We constantly think of articles and videos that might spark Git people interest / skill us up or help building a stellar career

Levelling up Monorepos with npm Workspaces
DevOps.js Conf 2022DevOps.js Conf 2022
33 min
Levelling up Monorepos with npm Workspaces
Top Content
NPM workspaces help manage multiple nested packages within a single top-level package, improving since the release of NPM CLI 7.0. You can easily add dependencies to workspaces and handle duplications. Running scripts and orchestration in a monorepo is made easier with NPM workspaces. The npm pkg command is useful for setting and retrieving keys and values from package.json files. NPM workspaces offer benefits compared to Lerna and future plans include better workspace linking and adding missing features.
End the Pain: Rethinking CI for Large Monorepos
DevOps.js Conf 2024DevOps.js Conf 2024
25 min
End the Pain: Rethinking CI for Large Monorepos
Today's Talk discusses rethinking CI in monorepos, with a focus on leveraging the implicit graph of project dependencies to optimize build times and manage complexity. The use of NX Replay and NX Agents is highlighted as a way to enhance CI efficiency by caching previous computations and distributing tasks across multiple machines. Fine-grained distribution and flakiness detection are discussed as methods to improve distribution efficiency and ensure a clean setup. Enabling distribution with NX Agents simplifies the setup process, and NX Cloud offers dynamic scaling and cost reduction. Overall, the Talk explores strategies to improve the scalability and efficiency of CI pipelines in monorepos.
Federated Microfrontends at Scale
React Summit 2023React Summit 2023
31 min
Federated Microfrontends at Scale
Top Content
This Talk discusses the transition from a PHP monolith to a federated micro-frontend setup at Personio. They implemented orchestration and federation using Next.js as a module host and router. The use of federated modules and the integration library allowed for a single runtime while building and deploying independently. The Talk also highlights the importance of early adopters and the challenges of building an internal open source system.
Scale Your React App without Micro-frontends
React Summit 2022React Summit 2022
21 min
Scale Your React App without Micro-frontends
This Talk discusses scaling a React app without micro-frontend and the challenges of a growing codebase. Annex is introduced as a tool for smart rebuilds and computation caching. The importance of libraries in organizing code and promoting clean architecture is emphasized. The use of caching, NxCloud, and incremental build for optimization is explored. Updating dependencies and utilizing profiling tools are suggested for further performance improvements. Splitting the app into libraries and the benefits of a build system like NX are highlighted.
Remixing Your Stack in a Monorepo Workspace
Remix Conf Europe 2022Remix Conf Europe 2022
22 min
Remixing Your Stack in a Monorepo Workspace
Let's talk about remixing our stack in a Monorepo workspace, which allows for incremental migration and is suitable for transitioning from a Next.js app to a remix stack. Refactoring may be required for feature-specific and Next.js-coupled components, but the process is simplified because the features have already been moved out. Configuring the Monorepo to reference packages locally and linking them to the Next.js application is necessary. Nx provides benefits like fast refreshing, pre-configured setups, and features like local and remote caching.
The Age of Monorepos
JSNation 2022JSNation 2022
25 min
The Age of Monorepos
Today's Talk is about the world of monorepos, their history, benefits, and features. Monorepos address challenges in web development, such as slow build processes and unstable connections on mobile devices. Collocation in monorepos enables easy sharing of functions and components among projects. Speed and efficiency in monorepos are achieved through collocation, dependency graphs, and task orchestration. Monorepo tools like Learnr offer features such as caching and distributed task execution. Monorepos provide code sharing, consistent tooling, and automated migration, resulting in a 10x developer experience.

Workshops on related topic

Node Monorepos with Nx
Node Congress 2023Node Congress 2023
160 min
Node Monorepos with Nx
Top Content
WorkshopFree
Isaac Mann
Isaac Mann
Multiple apis and multiple teams all in the same repository can cause a lot of headaches, but Nx has you covered. Learn to share code, maintain configuration files and coordinate changes in a monorepo that can scale as large as your organisation does. Nx allows you to bring structure to a repository with hundreds of contributors and eliminates the CI slowdowns that typically occur as the codebase grows.
Table of contents:- Lab 1 - Generate an empty workspace- Lab 2 - Generate a node api- Lab 3 - Executors- Lab 4 - Migrations- Lab 5 - Generate an auth library- Lab 6 - Generate a database library- Lab 7 - Add a node cli- Lab 8 - Module boundaries- Lab 9 - Plugins and Generators - Intro- Lab 10 - Plugins and Generators - Modifying files- Lab 11 - Setting up CI- Lab 12 - Distributed caching
React at Scale with Nx
React Summit 2023React Summit 2023
145 min
React at Scale with Nx
Top Content
WorkshopFree
Isaac Mann
Isaac Mann
We're going to be using Nx and some its plugins to accelerate the development of this app.
Some of the things you'll learn:- Generating a pristine Nx workspace- Generating frontend React apps and backend APIs inside your workspace, with pre-configured proxies- Creating shared libs for re-using code- Generating new routed components with all the routes pre-configured by Nx and ready to go- How to organize code in a monorepo- Easily move libs around your folder structure- Creating Storybook stories and e2e Cypress tests for your components
Table of contents: - Lab 1 - Generate an empty workspace- Lab 2 - Generate a React app- Lab 3 - Executors- Lab 3.1 - Migrations- Lab 4 - Generate a component lib- Lab 5 - Generate a utility lib- Lab 6 - Generate a route lib- Lab 7 - Add an Express API- Lab 8 - Displaying a full game in the routed game-detail component- Lab 9 - Generate a type lib that the API and frontend can share- Lab 10 - Generate Storybook stories for the shared ui component- Lab 11 - E2E test the shared component