How to understand a Turborepo monorepo codebase
A Turborepo monorepo holds several apps and shared packages in one repository, linked by the package manager's workspaces. `turbo.json` describes how tasks such as `build` and `test` depend on each other across packages, and Turborepo caches their outputs.
How to tell it's Turborepo monorepo
turbo.jsonat the root andturboindevDependenciesapps/andpackages/folders- Workspace dependencies such as
"@acme/ui": "workspace:*"
Where things usually live
- turbo.json
- Task definitions (
tasks, calledpipelinebefore v2),dependsOn, outputs and inputs. - apps/*
- Deployable applications, such as
web,docsandapi. - packages/*
- Shared code: UI kit, config, database client, TypeScript and ESLint presets.
- package.json (root)
- Workspace globs and root scripts that call
turbo run. - pnpm-workspace.yaml
- Workspace list when using pnpm.
Conventions, not rules. Real projects rename and move things, so confirm against the repository.
Where to start reading
- The root
package.jsonand workspace config, to list every package turbo.json, for how builds depend on each other- The
package.jsonof the app you care about, for its internal dependencies
How a request moves through the code
turbo run buildreads the workspace graph from eachpackage.json.dependsOn: ["^build"]makes each package's dependencies build first.- Turbo hashes each task's inputs and restores cached outputs when nothing changed.
- Apps import internal packages by name, resolved to local folders through workspaces.
Questions to ask about the repository
- Draw the dependency graph between apps and packages.
- Which packages are compiled and which are consumed as source?
- Which apps would be affected by a change to
packages/ui?
What trips people up
- Internal packages may point
mainat TypeScript source or at built output; mixing the two causes confusing errors. - Missing
outputsorinputsinturbo.jsonleads to stale cache hits or no caching at all. - For RepoGrasp's size limit, paste a link to one app or package folder rather than the whole monorepo.