Skip to content

Lesson 2 of 9 · 26m

Workspace Tools and Repository Layout

Choose package managers and task orchestrators based on graph correctness, reproducibility, and operational fit rather than ecosystem fashion.

Teams often ask whether they should use npm workspaces, pnpm, Yarn, Turborepo, Nx, Bazel, Pants, or Buck. That is backwards. First decide what correctness properties you need: deterministic installs, explicit dependency graphs, content-addressed caching, hermetic execution, remote execution, or language-neutral builds. Then choose the smallest toolset that actually provides them.

Separate package management from task orchestration

These concerns are frequently bundled but they are not the same job:

package manager     installs dependencies and links workspace packages
task orchestrator   runs build/test/lint in dependency order
build system        produces artifacts with declared inputs and outputs
CI system           schedules work, reports status, gates merges

pnpm workspaces can install and link packages. Turborepo and Nx can schedule tasks and cache results. Bazel goes further and models the build as a strict action graph. Overlapping features are real, but the conceptual separation helps you avoid buying a bulldozer to hang a picture.

A layout that communicates intent

A common TypeScript monorepo layout:

apps/
  web/
  api/
packages/
  ui/
  config/
  auth/
tools/
  scripts/
  eslint-rules/
package.json
pnpm-workspace.yaml
turbo.json

The important property is not the names. It is that location predicts ownership and dependency rules. apps are deployable leaves, packages are reusable internal products, and tools supports the repository itself. Do not let deployables import sideways into other deployables unless that is an explicit architectural decision.

Make workspace metadata explicit

For pnpm:

packages:
  - "apps/*"
  - "packages/*"
  - "tools/*"

For npm or pnpm workspace dependencies, prefer workspace-aware references where supported:

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

That declaration means the dependency comes from this repository, not whatever happens to exist on a registry. It prevents accidental resolution drift and makes graph construction more reliable.

Evaluate tools on scars, not demos

Ask the uncomfortable questions:

  • Can the tool explain why a task was invalidated?
  • Does the cache key include environment, inputs, dependencies, and toolchain versions?
  • What happens when two tasks write the same output?
  • Can a package opt out without breaking the graph?
  • How painful is a partial checkout or sparse workflow?
  • Can non-TypeScript code participate honestly?

A beautiful demo that hides inputs will become a production incident when stale artifacts ship. Boring introspection beats clever magic.

Avoid toolchain sprawl

One orchestrator should own the common verbs: build, test, lint, typecheck, and dev. Teams can add specialized verbs, but shared CI should not need to learn ten conventions. Standardization is not about control for its own sake; it is how caching, ownership, and affected detection become composable.

Field notes

  • Do not adopt a hermetic build system because it is theoretically pure; adopt it when reproducibility or scale pain justifies the migration cost.
  • Workspace globs that are too broad make every directory look like a package and slow graph discovery.
  • Keep generated code visible in the dependency graph. If generated clients are inputs, model them as inputs.
  • The best tool is often the one your team can debug at 2 a.m., not the one with the longest feature matrix.

Was this lesson helpful?

Sign in to rate