Monorepo in real life
Monolithic application
A single unified software application which is self-contained and independent from other applications
Monolithic
Simple
Modular application
An application composed of loosely coupled, functional units called modules
Components or Bundles
MonoRepo
A monorepo is a single repository containing multiple distinct projects, with well-defined relationships
MonoRepo
Simple
Code colocation
Maybe monorepo
Code colocation
Maybe maybe monorepo
MonoRepo library
with subtree split
Monorepo or monolithic or "code colocation" ?
Maybe all at once!
If we have multiple distinct projects, what is the monorepo alternative ?
Polyrepo
Why MonoRepo?
Backward resilient
Better decommissioning
Lesser PullRequest
Better Code Review
Implicit CI
Better productivity
Avoid switching repo
Better collaboration between Teams
We can fix bugs in all projects
Less Managment
Everything is centralized
Dependency managment
Code more reusable
Access Control
Better Continus Integration
Visibility
Cross Team Contribution
Single source of truth
Consistency
Shared Timeline
Atomic commits
Unified CI/CD
Unified build process
Unified deploy process
Refactoring easier
Sharing coding standard
Synchronized release
Sharing dependencies
To list a pro and cons of monorepo strategy i recommand:
My top 5 reasons
- Better Code Review
- Lesser PullRequest
- Single source of truth
- Less Managment
- Code more reusable
If I update project A, do i need to wait the whole CI for all projects ?
It depends - sometime you want it, sometime not. But know you have the opportunity to choose.
# .gitlab-ci.yml
backend_test:
stage: test
script:
- make functional-test-backend
- make functional-test-front
rules:
changes:
- backend/*
front_test:
stage: test
script:
- make functional-test-front
rules:
changes:
- front-react/*
Feedback MicroService
- We have a 15 old years ecommerce project
- We have to modernize it
- We have to keep business going
- We want to use Service Oriented Architecture
Context
From SymfonyCon 2022
Ecommerce
Ecommerce
Stock
Order
Before
After
From SymfonyCon 2022
Text
Tooling
#1 CODEOWNERS
#1 CODEOWNERS
#2 Deptrac
paths:
- ./ecommerce/src
- ./stock/src
- ./order/src
layers:
- name: Ecommerce
collectors:
- type: className
regex: .*App\\Ecommerce\\.*
- name: Stock
collectors:
- type: className
regex: .*App\\Stock\\.*
- name: Order
collectors:
- type: className
regex: .*App\\Order\\.*
#2 Deptrac
layers:
- name: Ecommerce
collectors:
- type: className
regex: .*App\\Ecommerce\\.*
- name: Stock
collectors:
- type: className
regex: .*App\\Stock\\.*
- name: PaymentBundle
collectors:
- type: className
regex: .*App\\PaymentBundle\\.*
ruleset:
Ecommerce:
- PaymentBundle
Stock:
- PaymentBundle
Conclusion for PHP context
- 🤹 Setting up monorepo require skills (CI/CD/Tools)
- ⏳ Setting up monorepo doesn't take long (CI/CD) and don't require a lot of tooling
- 🕵️♂️ The real only downside is boundary issue
- 🧩 Can be temporary and progressively switch to polyrepo
- 🚀 Will skyrocket development speed in almost any multi-project context
“With the right tools, anyone can unlock the power of monorepos”
Bonus Git Clone
🌍 shallow clone a lightweight "git clone" without the whole git history
🚧 partial clone a feature to avoid to download everything
git clone --depth=1 https://github.com/Symfony/symfony
git clone --filter=blob:none https://github.com/org/proj
# Git command
git subtree split --prefix=lib
# Fabpot tools
splitsh-lite --prefix=lib/
Bonus Git split
Code
By skigun
Code
- 152