# Monorepo

> The Monorepo is an approach where multiple projects or packages are stored in a single repository.

## What is a monorepo and when should I use one?

The approach of keeping several apps and packages in one repository with shared tooling and dependencies. Simplifies code sharing and atomic changes across projects. Usually managed with workspaces and build tools that cache tasks.

- Topic: Practices
- Type: approach

## Example

Wrong:

```json
{
  "dependencies": {
    "@acme/ui": "^1.2.0"
  }
}
```

Right:

```json
{
  "dependencies": {
    "@acme/ui": "workspace:*"
  }
}
```

The `workspace:` protocol links the local package, so changes are used at once instead of a published copy.

## Common mistakes

- Importing another package's source by relative path instead of through its package name.

## Key points

- Internal packages are linked through workspaces, not published and installed from the registry.
- There is one lock file at the repository root.
- CI builds and tests only the packages affected by a change, with a shared cache.

## Interview questions

### Monorepo vs polyrepo: which is better?

A monorepo makes shared code and atomic changes across packages easy. Separate repos give stronger isolation and simpler permissions per project.

### Do I need a special tool for a monorepo?

Package manager workspaces are enough to start. Build tools with task caching help when there are many packages.

### Can each package in a monorepo have its own version?

Yes. Packages can be versioned and published independently, or all released together with one version.

## Related cards

- [Workspaces](https://wonderium.dev/processes/workspaces.md)
- [pnpm](https://wonderium.dev/processes/pnpm.md)
- [package.json](https://wonderium.dev/processes/package-json.md)
- [CODEOWNERS](https://wonderium.dev/processes/codeowners.md)
- [Micro Frontends](https://wonderium.dev/engineering/micro-frontends.md)

---

- Level: [Processes](https://wonderium.dev/processes.md)
- HTML version: https://wonderium.dev/processes/monorepo
- Last updated: 2026-11-25
