Strategic Design with Monorepos

What is a monorepo?

Monorepo

a single repository holding the code of multiple projects which may or may not be related in some way

In some cases the monorepo contains nearly all of the projects in a given organization

Colossal

  • All modules in one place
  • Versioned centrally
  • Dependencies managed

Project

  • Entire application stack
  • GraphQL + Web + Native + Shared
  • Test / Build / Deploy together

Micro Platform

Why Monorepos?

+1 buzzword 😏

So how to:

  • feel safe and confident putting new changes/features
  • help more people more easily collaborate on one project

How easy is it to:

  • get started
  • submit changes
  • test
  • deploy
  • identify faults
  • revert

Polyrepo

+ Flexibility

+ Encapsulating complexity

+ Easy to deploy

+ Clear ownership and politics

- Scattered developer env

- Complex lint / test / build / release

- Cross repo changes hard

- Cross repo rollbacks terrifying

- Difficulty enforcing conventions

- Context loss

Monorepo Advantages

Developer environment

+ Every service in one place

+ Backend, Frontend, DB

+ Top level yarn && yarn start

Common configuration

+ Top level ESLint / Prettier / Babel etc.

+ Reduce convention switching

+ No orphaned packages

Code reuse

+ Can split common code into modules

+ Use and dependencies versioned

+ Breaking changes visible

Cross project changes

+ 1 PR for multi module features

+ 1 PR to review with full context

+ 1 PR to revert if it goes wrong

Single release process

+ Everything needed to build available

+ Everything needed to test available

+ Release / Revert with confidence

Single culture

“Software is Easy, People are Hard”

Polyrepo

+ Flexibility

+ Encapsulating complexity

+ Easy to deploy

+ Clear ownership and politics

- Scattered developer env

- Complex lint / test / build / release

- Cross repo changes hard

- Cross repo rollbacks terrifying

- Difficulty enforcing conventions

- Context loss

Monorepo

+ Unified developer environment

+ Single lint / test / build / release

+ Cross module changes

+ Cross module rollbacks

+ Code reuse / sharing

+ Shared culture

Why NOT?

Monorepo Disadvantages

  • the repo will be bigger — more code to handle
  • CI / CD pipeline
  • less mature tooling
  • fewer stackoverflow posts
  • organizations

How do I get Monorepo?

How do we

  • manage dependencies
  • version, test, build a whole repo
  • continually integrate / deploy
  • manages dependencies
  • eliminates redundancy
  • exposes current co-packages
  • single yarn install and go
  • manages testing
  • manages versioning
  • manages building
  • manages releasing
  • used by plenty of projects

Structure of the project

"first" package

"app"

package.json

package.json

Adding lerna

lerna.json

Nx

First-class support

nx dep-graph

That's it 🙂

Made with Slides.com