docs/current_docs/reference/best-practices/monorepos.mdx
When using Dagger to build a monorepo, you can choose between two common patterns for organizing your Dagger modules. The choice depends on the complexity of the monorepo and the relationships between the projects in it.
One common approach is to create a top-level Dagger module for the monorepo, attach sub-modules for each component of the monorepo, and model the Dagger module dependencies on the logical dependencies between components. This pattern is suitable when there are dependencies but differences between the projects in the monorepo (e.g. a monorepo with SDKs, CLIs, web applications, docs, all of which have different requirements).
graph TD
A[Top-level orchestrator module] --> B[Webapp frontend module]
A[Top-level orchestrator module] --> C[Webapp backend module]
A[Top-level orchestrator module] --> D[Utilities module]
A[Top-level orchestrator module] --> E[Docs module]
The key benefits of this pattern include:
An alternative approach is to create a single, shared automation module which all projects use and contribute to. This pattern is suitable when there are significant commonalities between the projects in the monorepo (e.g. a monorepo with only micro-services or only front-end applications).
graph TD
A[Shared module] --> B[Microservice 1]
A[Shared module] --> C[Microservice 2]
A[Shared module] --> D[Microservice 3]
The key benefits of this pattern include:
:::note When considering how to optimize monorepo builds, there are two layers to keep in mind: