$npx -y skills add avibebuilder/claude-prime --skill monorepoMUST use for ANY query mentioning packages, monorepo, workspace, catalog, turbo, turborepo, or pnpm in a multi-package context. MUST use when sharing config (ESLint, tsconfig, prettier) across packages, fixing build order between packages, adding new packages, scoping CI installs
| 1 | # Monorepo |
| 2 | |
| 3 | Project-specific patterns for pnpm workspaces + Turborepo. |
| 4 | |
| 5 | ## Architecture Decisions |
| 6 | |
| 7 | ### Workspace Organization |
| 8 | 1. **Split apps from packages** — `apps/` for deployables, `packages/` for shared libraries. |
| 9 | 2. **Namespace packages** — Prefix with `@org/` to avoid npm conflicts. |
| 10 | 3. **Single lockfile** — `pnpm-lock.yaml` at root only. Never commit multiple lockfiles. |
| 11 | 4. **No cross-package file access** — Never use `../` to reach into other packages; import via dependencies. |
| 12 | |
| 13 | ### Dependency Management |
| 14 | 5. **Use `workspace:*` protocol** — Always for internal package dependencies. |
| 15 | 6. **Hoist common devDependencies** — Shared tooling (TypeScript, ESLint) in root. |
| 16 | 7. **Peer dependencies for frameworks** — React, Vue, etc. as peers to avoid version conflicts. |
| 17 | 8. **Consider Catalogs (pnpm 9.5+)** — Centralize versions in `pnpm-workspace.yaml` for large repos. |
| 18 | |
| 19 | ### Turborepo Tasks |
| 20 | 9. **Use `^` for build dependencies** — `"dependsOn": ["^build"]` for topological order. |
| 21 | 10. **Always define `outputs`** — Without outputs, nothing gets cached. |
| 22 | 11. **Mark dev servers as persistent** — `"persistent": true, "cache": false`. |
| 23 | 12. **Be explicit about environment** — List all build-affecting vars in `env` or `globalEnv`. |
| 24 | |
| 25 | ## Gotchas |
| 26 | |
| 27 | - Missing `outputs` in turbo.json silently disables caching for that task. The task runs every time and you won't get an error — just slow builds. Always verify outputs are configured. |
| 28 | - `pnpm install` does NOT respect `--filter` for installation — it always installs the entire workspace. Filtering only works for `pnpm run` and `pnpm exec`. |
| 29 | - `workspace:*` resolves to the CURRENT version of the local package, not "latest from npm". If the package has `"version": "0.0.0"`, published packages will have `"dependency": "0.0.0"` — set meaningful versions before publishing. |
| 30 | - Turborepo's `env` field in turbo.json uses GLOB patterns, not exact matches. `"env": ["API_*"]` captures `API_KEY`, `API_URL`, etc. Forgetting this causes over-invalidation. |
| 31 | - `turbo run build --filter=app-a` builds app-a AND all its workspace dependencies. If a dependency fails, app-a won't build. Check transitive deps. |
| 32 | - Adding a package to `packages/` requires running `pnpm install` before the workspace recognizes it. The new package also needs a valid `package.json` with `name` matching the workspace pattern. |
| 33 | - TypeScript project references (`references` in tsconfig.json) must match the workspace dependency graph. Mismatches cause type errors that only appear during `tsc --build`, not in IDE. |
| 34 | - `turbo.json`'s `globalDependencies` invalidates ALL tasks when listed files change. Don't put frequently-changed files here — use task-level `inputs` instead. |
| 35 | - Shared Tailwind configs need `@source` directives pointing to consuming packages' source directories, otherwise classes used in shared packages are purged. |
| 36 | - `pnpm deploy` (for production) copies a single package and its dependencies to a target directory. It does NOT run build scripts — build first, then deploy. |
| 37 | - Remote cache (Vercel or self-hosted) requires `outputs` to be correct. If outputs are wrong, cached artifacts will be incomplete and downstream tasks break silently. |
| 38 | - `persistent: true` tasks prevent `turbo run` from exiting. Don't include persistent tasks in CI pipelines unless they have a timeout. |
| 39 | |
| 40 | ## References |
| 41 | |
| 42 | | When you need... | Read | |
| 43 | |------------------|------| |
| 44 | | workspace.yaml, workspace: protocol, filtering | [pnpm-workspace.md](./references/pnpm-workspace.md) | |
| 45 | | turbo.json schema, tasks, dependsOn | [turborepo.md](./references/turborepo.md) | |
| 46 | | Cache outputs/inputs, remote cache setup | [caching.md](./references/caching.md) | |
| 47 | | Directory layout, package naming, tsconfig | [structure.md](./references/structure.md) | |
| 48 | | Tailwind v4 shared theme package | [tailwind-v4.md](./references/tailwind-v4.md) | |
| 49 | |
| 50 | ## External Resources |
| 51 | |
| 52 | - [pnpm Workspaces](https://pnpm.io/workspaces) |
| 53 | - [Turborepo Docs](https://turborepo.com/docs) |
| 54 | - [Configuring turbo.json](https://turborepo.com/docs/reference/configuration) |