Full answer
In a polyrepo setup each app and library has its own repository and version. Sharing a component library means publishing a package, bumping versions and updating every consumer. In a monorepo they live together, which changes the workflow.
Structure. A common layout is apps/web, apps/admin, packages/ui (design system), packages/config (ESLint, TypeScript and Prettier presets) and packages/utils. The root declares workspaces, for example in pnpm-workspace.yaml. Packages depend on each other using the workspace protocol ("@acme/ui": "workspace:*"), so the package manager links the local folder instead of downloading it.
Task running and caching. Running build in the right order matters: ui before web. Turborepo and Nx read the dependency graph, run tasks in parallel where possible, and cache outputs keyed by the inputs (source files, dependencies, environment). If nothing changed, the result is restored in seconds. Remote caching shares results between CI and developers. Affected-only commands run tests for packages touched by a change.
Benefits: share and refactor code across apps in one pull request, one set of tool versions, easier code reuse and discoverability, and a single source of truth for dependency versions (pnpm catalogs help).
Costs and pitfalls: tooling and onboarding complexity, CI that runs everything unless it uses caching and filtering, accidental coupling between packages (enforce boundaries with lint rules), permissions and ownership (CODEOWNERS), and phantom dependencies (pnpm's strict node_modules helps catch packages that are imported but not declared). Internal packages may be consumed as source (transpiled by the app's bundler) for speed, or built to dist for publishing, which is a design choice.
Not every project needs one. A single app with a single team rarely benefits.
The example is a pnpm workspace file with a shared version catalog. It is configuration and was not executed.
# pnpm-workspace.yaml at the repository root
packages:
- "apps/*"
- "packages/*"
# Shared versions: packages write "react": "catalog:" in their package.json
catalog:
react: ^19.2.0
react-dom: ^19.2.0
typescript: ^5.9.0This is a configuration file and was not executed. Its YAML syntax was parsed with a YAML library to confirm it is valid. The catalog feature needs a recent pnpm version, and the versions shown are examples to adapt.
Key points
- A monorepo holds several apps and packages in one repository with shared tooling.
- Workspaces link local packages. The workspace protocol resolves them from the repo.
- Turborepo and Nx run tasks in dependency order and cache results, including remote caches.
- Benefits: shared code, atomic changes, consistent versions. Costs: tooling complexity and CI time without caching.
- Enforce package boundaries and declare every dependency.
Common mistakes
- Creating a monorepo for one small app and paying the tooling cost.
- Running every package's tests on every change because caching is not set up.
- Importing from another package's internal files instead of its public entry.
- Importing packages that are not declared in package.json.
- Having no owners or boundaries, so any team changes any package.
Follow-ups
- How do you decide whether internal packages are built or consumed as source?
- How would you run only the tests affected by a pull request?
- How do you version and publish packages from a monorepo?
Tips
- Describe the layout and the workspace protocol.
- Explain task caching, since it is what makes monorepos fast.
- Say a single small app does not need one.