No. 22Architecture8 min read2,003 words
Monorepo vs polyrepo: a pragmatic guide for small teams
Monorepo or separate repos? A decision guide for product teams: when each fits, a pnpm and Turborepo setup that stays fast, and the real costs nobody mentions.
- Written by
- Lazy Devs
- Published
- Updated
- Sources
- Cited inline

Key takeaways ยท 05
The short version
- 01Choose a monorepo when one team owns several apps that share code and ship together; choose separate repos when teams, toolchains or access rules genuinely diverge.
- 02A monorepo is not a monolith: one repository can hold many independently deployed apps, and one deployable app can live in its own repo.
- 03The biggest practical win of a monorepo is atomic change: rename a shared type and both the API and the frontend fail in the same CI run, before anything ships.
- 04Set up workspaces and a caching task runner such as Turborepo or Nx on day one, so CI time tracks the size of the change rather than the size of the repo.
- 05The structure is cheap to choose; the tooling around it is the real commitment. A monorepo without caching and a multi-repo without a versioning plan fail in the same way.
On this page ยท 11
Use a monorepo when one team owns several apps that share code and ship together. Use separate repositories when different teams own different services, the projects use unrelated toolchains, or some people must not see some of the code. For most small product teams, a monorepo with workspaces and a caching task runner is the better default, but only if you spend the half day setting up that tooling properly.
Every few months someone asks whether they should move everything into a monorepo, and they want a yes or a no. The honest answer depends on team shape, release cadence and how much code you actually share. So instead of vibes, here is the decision process we use, and the setup we reach for when the answer is yes.
What a monorepo is, and what it is not
A monorepo is one version control repository holding multiple projects: your web app, your API, a shared UI library, maybe a CLI. It is not a monolith. A monolith is a single deployable unit. You can have a monorepo that ships five independently deployed services, and you can have a monolith living alone in a tiny repo. People conflate the two constantly and then argue past each other.
What makes a monorepo worth the trouble is shared code with a shared lifecycle. If your frontend and backend share TypeScript types for API payloads, a monorepo lets you change the type in one commit and see both sides break in CI at the same time. That single property removes a whole category of "the API changed and nobody told the frontend" bugs.
Monorepo vs separate repos: how to decide
| Factor | Points to a monorepo | Points to separate repos |
|---|---|---|
| Shared code | Types, schemas, UI components used by several apps | Little or nothing shared |
| Ownership | One team owns most of it | Different teams with separate roadmaps |
| Change pattern | Features routinely touch API and UI together | Projects change independently |
| Toolchains | Same language and build tools | Different languages and ecosystems |
| Access control | Everyone on the team may see everything | Contractors or partners must see only part |
| Release cadence | Shipped together or close to it | Released on unrelated schedules |
Most small product teams sit squarely in the left column, which is why monorepos got popular. But the failure mode is real: a monorepo with bad tooling is slower and more painful than two clean repos.
Three questions that settle it
- Do these projects share code that changes together?
- Does one team mostly own them?
- Do you want a single pull request to change the API and the UI for a feature at once?
Two or three yeses: go monorepo, and invest in the tooling before you have ten packages, not after. Mostly noes: keep separate repos and use a private package registry for the rare shared piece.
For a first product, keep it simple: one repository, one app, until a second app actually exists. That is how we approach shipping a SaaS MVP in weeks.
Set up workspaces first
A monorepo without a package manager that understands workspaces is just a folder with extra steps. With pnpm workspaces (or npm workspaces, or Yarn), internal packages resolve by name from the local folder instead of by a published version. Here is a minimal pnpm layout:
apps/
web/ Next.js app
api/ Node API
packages/
types/ shared Zod schemas and types
ui/ shared React components
package.json
pnpm-workspace.yaml
turbo.json// package.json (repo root)
{
"name": "studio",
"private": true,
"packageManager": "pnpm@12.16.1",
"scripts": {
"build": "turbo run build",
"dev": "turbo run dev",
"lint": "turbo run lint",
"typecheck": "turbo run typecheck",
"test": "turbo run test"
},
"devDependencies": {
"turbo": "^2.11.0"
}
}# pnpm-workspace.yaml
packages:
- "apps/*"
- "packages/*"Pin packageManager to the exact version your team uses, so every laptop and CI runner installs with the same tool. Now apps/web can depend on a shared package without publishing anything:
// apps/web/package.json
{
"name": "@studio/web",
"private": true,
"dependencies": {
"@studio/types": "workspace:*",
"next": "^16.0.0",
"react": "^19.0.0",
"react-dom": "^19.0.0"
}
}The workspace:* protocol tells pnpm to link the local packages/types folder. Change a type there and apps/web sees it immediately. No build, publish, install dance.
Share types and schemas, not just folders
The shared package itself should stay small and honest:
// packages/types/src/invoice.ts
import { z } from "zod";
export const InvoiceStatus = z.enum(["draft", "sent", "paid", "void"]);
export const Invoice = z.object({
id: z.uuid(),
amountCents: z.number().int().nonnegative(),
currency: z.string().length(3),
status: InvoiceStatus,
dueAt: z.coerce.date(),
});
export type Invoice = z.infer<typeof Invoice>;Both the Next.js app and the Node API import Invoice from @studio/types. The API validates incoming requests with Invoice.parse() using Zod, and the frontend gets the inferred type for free. Rename a field and TypeScript fails in both apps in the same CI run. That is the whole pitch, and it works best with strict TypeScript turned on everywhere.
If a shared package exports TypeScript source rather than compiled JavaScript, tell Next.js to compile it with transpilePackages:
// apps/web/next.config.ts
import type { NextConfig } from "next";
const nextConfig: NextConfig = {
transpilePackages: ["@studio/types", "@studio/ui"],
};
export default nextConfig;These "just in time" internal packages are the simplest setup: no build step for the shared code, and edits show up instantly in development. Add a build step for a package only when something outside the monorepo needs to consume it.
Use a task runner with caching, or CI will crawl
The second biggest reason monorepos get a bad name is build time. If running checks means rebuilding every package on every change, people will quietly move things back out. The fix is a task runner that understands the dependency graph and caches results. Turborepo's configuration for the setup above is short:
// turbo.json
{
"$schema": "https://turborepo.dev/schema.json",
"tasks": {
"build": {
"dependsOn": ["^build"],
"outputs": ["dist/**", ".next/**", "!.next/cache/**"]
},
"typecheck": {
"dependsOn": ["^build"]
},
"lint": {},
"test": {
"dependsOn": ["^build"]
},
"dev": {
"cache": false,
"persistent": true
}
}
}The ^build syntax means "build my dependencies first." The outputs list tells Turborepo what to cache, and excludes the Next.js build cache, which should not be stored as a task output. Touch only apps/web and the cached results for packages/types are reused. Point the cache at remote storage and an unchanged package in CI is restored in seconds instead of rebuilt.
Nx offers a similar graph-aware model with more built-in generators and plugins. The principle is identical: without caching, a monorepo punishes you for growing. With it, CI time tracks the size of your change, not the size of your repo.
Run only what changed in CI
Use the task runner's filtering so a pull request that touches only the marketing site does not run the API's integration tests. With Turborepo that is a --filter on changed packages and their dependents. That logic belongs in the single, small CI workflow we describe in CI/CD that small teams actually maintain, not in a sprawl of per-app workflow files.
Deploying apps out of a monorepo
Each app in a monorepo still deploys on its own. A few practical details:
- On managed platforms, set each project's root directory to its app folder (
apps/web) and enable skipping builds when nothing relevant changed. - With Next.js standalone output, file tracing uses the app folder as its root by default, so files from shared packages outside it can be missed. The Next.js
outputdocs cover settingoutputFileTracingRootto the repo root for this case. - For container images,
turbo prune --dockerproduces a trimmed copy of the repo with only the target app and the packages it depends on, which keeps the Docker build context and cache small. Our guide to Docker for web apps shows the multi-stage image to put it in.
The honest costs of a monorepo
Here are the parts that hurt.
CI gets more clever, which means more fragile. Affected-package detection and remote caching are worth it, but they are logic you now own and need to debug when they misbehave.
Tooling has to agree. One TypeScript version, one ESLint setup, one Node version across the repo. That consistency is a feature until one app genuinely needs a different version and you are fighting the shared config. pnpm catalogs can help keep shared dependency versions in one place.
Git history gets noisy. git log shows commits across every project. Path-scoped commands (git log -- apps/web) help, but newcomers feel the firehose.
Access control is coarse. Most Git hosts grant permissions per repository. CODEOWNERS can require the right reviewers for each folder, but it controls approvals, not who can read the code. If someone truly must not see part of the codebase, a monorepo works against you.
Separate repos have costs too. Shared code needs publishing, versioning and coordinated upgrades. A breaking change in a shared package becomes a multi-repo migration. "The API changed and nobody told the frontend" is a polyrepo problem first.
None of these are dealbreakers for a single product team. All of them grow with headcount and project count, which is why larger organisations either invest heavily in custom tooling or split things apart.
Common monorepo mistakes we see
When we take over a monorepo that the team has started to resent, the cause is rarely the idea itself. It is usually one of these:
- A "shared" package that is really a junk drawer. A
utilspackage that every app imports and nobody owns becomes the place where coupling hides. Keep shared packages narrow and named for what they do:types,ui,email-templates. - Apps importing each other.
apps/webreaching intoapps/api/srcbreaks the dependency graph and makes caching unreliable. If two apps need the same code, move it into a package. - No caching, or caching the wrong outputs. Forgetting to declare
outputsmeans the task runner restores nothing; declaring too much means stale artifacts. Check a cache hit actually produces a working build. - Hidden inputs. Tasks that read environment variables or files the runner does not know about get cached when they should not be. Declare environment variables that affect builds in the task config.
- One giant CI job. Running every check for every package on every pull request throws away the main benefit. Filter by what changed.
- Moving everything at once. A big-bang migration of five repos stalls feature work for weeks. Move one app at a time.
Each of these is fixable in a day or two, and fixing them usually turns "the monorepo is slow" back into "the monorepo is fine."
Moving an existing project into a monorepo
If you have two or three repos today and the decision above says monorepo, the move is less dramatic than it sounds:
- Create the new repo with workspaces and the task runner configured, and no apps yet.
- Move one app in, preserving history if you care about it, and get its build and tests green.
- Extract the most duplicated code (usually API types and validation schemas) into a shared package.
- Move the second app in and switch it to the shared package.
- Update CI to build and test only affected packages, and repoint deployments to the new root directories.
- Archive the old repositories once nothing depends on them.
Do it between big features, not in the middle of one, and keep the first shared package deliberately small.
Choose the tooling on purpose
Default to a monorepo when a small team shares code and ships together, and set up workspaces plus a caching task runner on day one. Default to separate repos when teams, toolchains or access needs diverge. Either way, the structure is cheap. The tooling around it is what you are really choosing, so choose it deliberately. It is one of the defaults we explain in the stack we reach for, and why.
If you want a second pair of eyes on your repo layout before it calcifies, or help moving to a monorepo without a lost month, our technical consulting is built for exactly that. Get in touch.
FAQ ยท 05 questions
Frequently asked questions
What is the difference between a monorepo and a monolith?
A monorepo is a single version control repository that holds several projects. A monolith is a single deployable application. You can have a monorepo containing five independently deployed services, or a monolith living alone in its own repository. The two decisions are separate.
Is a monorepo good for a small team?
Usually yes, when the same small team owns several apps that share code such as types, validation schemas or UI components. It removes the publish-and-bump cycle for internal packages and lets one pull request change everything a feature touches. It is a poor fit when the projects share nothing or need strict access separation.
Do I need Turborepo or Nx for a monorepo?
For two small packages, workspaces alone are enough. Once you have several apps and shared packages, a task runner that understands the dependency graph and caches results pays for itself, because it stops CI from rebuilding and retesting packages that did not change.
How do you deploy one app from a monorepo?
Most platforms let you set the root directory of each app and skip builds when nothing relevant changed. In your own CI, use the task runner's affected or filter commands to build and deploy only the apps touched by a change. For containers, prune the repo to just the target app and its dependencies before building the image.
Can you give different people access to different parts of a monorepo?
Only partly. Most Git hosts grant permissions per repository, so anyone with read access can see everything. CODEOWNERS files can require specific reviewers for specific folders, but they control approvals, not visibility. If someone must not see part of the code, keep that code in a separate repository.