Turborepo Foundation
Purpose
Configure Turborepo so its caching and orchestration are correct and fast: a task pipeline with accurate dependencies, precise input/output declarations, and affected-only execution wired into CI. Chosen upstream by monorepo-selection.
When to Use
- After
monorepo-selection chose Turborepo (over a relational package manager on top of pnpm/npm workspaces).
- Not for workspaces-only monorepos or single repos.
Inputs
- The workspace setup (
pnpm-workspaces/npm-workspaces) and package task graph.
- Build/test/lint task definitions per package.
Discovery Questions
- What tasks exist per package (build, test, lint, typecheck) and how do they depend across packages?
- What are each task's real inputs (source globs, config, env) and outputs (dist dirs) — the basis for correct caching?
- Does CI want remote caching, and is it shared across the team/CI safely?
Responsibilities
- Define the task pipeline:
dependsOn relationships (^build for upstream builds), so tasks run in dependency order.
- Declare inputs and outputs precisely per task — this is where caching correctness lives: missing inputs → stale cache serving wrong results; missing outputs → cache misses. Include config files and relevant env in inputs.
- Enable affected-only execution so CI runs only what changed and its dependents (
ci-cd), and local runs reuse cache.
- Configure caching: local by default; remote cache only with a deliberate, secured setup (tokens as secrets —
secrets-management) and awareness that a poisoned/misconfigured cache is a correctness and supply-chain risk.
- Keep task scripts in the packages; Turborepo orchestrates, it doesn't own the logic.
Required Workflow
- Enumerate tasks + cross-package dependencies.
- Define the pipeline with
dependsOn.
- Declare accurate inputs/outputs per task (verify cache correctness).
- Wire affected-only execution into CI.
- Configure caching (local; remote only if secured); validate no stale-cache correctness bugs.
Decision Rules
- Caching correctness depends on complete input/output declarations — under-declaring inputs is a silent-wrong-result bug, over-declaring just misses cache.
- Remote caching is opt-in and secured; treat cache artifacts as trusted-build inputs (supply-chain surface —
../../security/dependency-security).
- Orchestrate; don't relocate build logic into the pipeline config.
- Validate cache hits produce identical results to clean builds before trusting them in CI.
Rules
- Cache tokens/secrets via the secret store, never committed (
secrets-management).
- Pipeline changes reviewed — cache correctness is easy to break subtly.
- Turborepo config stays proportional; no orchestration of tasks that don't exist.
Anti-Patterns
- Under-declared inputs serving stale cache as fresh results.
- Committed remote-cache tokens.
- Build logic migrated into
turbo.json instead of package scripts.
- Trusting remote cache without validating correctness.
- Configuring pipelines for tasks/packages that aren't there.
Validation Checklist
Definition of Done
A Turborepo pipeline with correct task dependencies and precise, validated input/output declarations, affected-only CI execution, and secured caching — orchestrating existing package tasks without owning their logic.
Related Skills
monorepo-selection, pnpm-workspaces, npm-workspaces, ci-cd, github-actions, secrets-management, ../../security/dependency-security.
Related Knowledge
../../../knowledge/ (task graph, CI needs).
Related References
../../../references/devops/ (pipeline patterns, when populated).
Context Loading Guidance
- Requires: workspace setup, per-package task graph with inputs/outputs.
- Does not require: app feature code, unrelated infra.
- May load:
ci-cd, secrets-management (remote cache).
- Stop when: the pipeline + caching + affected-only CI are configured and validated.
Token Efficiency Guidance
The task × (dependsOn, inputs, outputs) table is the artifact; get those right and the config follows.
1---2name: turborepo-foundation3description: Use to plan a Turborepo setup after it's chosen — task pipeline definition (dependsOn), input/output declarations for correct caching, affected-only execution, and CI integration. Plans configuration; does not scaffold apps.4---56# Turborepo Foundation78## Purpose910Configure Turborepo so its caching and orchestration are **correct and fast**: a task pipeline with accurate dependencies, precise input/output declarations, and affected-only execution wired into CI. Chosen upstream by `monorepo-selection`.1112## When to Use1314- After `monorepo-selection` chose Turborepo (over a relational package manager on top of pnpm/npm workspaces).15- **Not** for workspaces-only monorepos or single repos.1617## Inputs1819- The workspace setup (`pnpm-workspaces`/`npm-workspaces`) and package task graph.20- Build/test/lint task definitions per package.2122## Discovery Questions2324- What tasks exist per package (build, test, lint, typecheck) and how do they depend across packages?25- What are each task's real **inputs** (source globs, config, env) and **outputs** (dist dirs) — the basis for correct caching?26- Does CI want remote caching, and is it shared across the team/CI safely?2728## Responsibilities2930- Define the **task pipeline**: `dependsOn` relationships (`^build` for upstream builds), so tasks run in dependency order.31- Declare **inputs and outputs precisely per task** — this is where caching correctness lives: missing inputs → stale cache serving wrong results; missing outputs → cache misses. Include config files and relevant env in inputs.32- Enable **affected-only execution** so CI runs only what changed and its dependents (`ci-cd`), and local runs reuse cache.33- Configure **caching**: local by default; **remote cache** only with a deliberate, secured setup (tokens as secrets — `secrets-management`) and awareness that a poisoned/misconfigured cache is a correctness and supply-chain risk.34- Keep task scripts in the packages; Turborepo orchestrates, it doesn't own the logic.3536## Required Workflow37381. Enumerate tasks + cross-package dependencies.392. Define the pipeline with `dependsOn`.403. Declare accurate inputs/outputs per task (verify cache correctness).414. Wire affected-only execution into CI.425. Configure caching (local; remote only if secured); validate no stale-cache correctness bugs.4344## Decision Rules4546- Caching correctness depends on complete input/output declarations — under-declaring inputs is a silent-wrong-result bug, over-declaring just misses cache.47- Remote caching is opt-in and secured; treat cache artifacts as trusted-build inputs (supply-chain surface — `../../security/dependency-security`).48- Orchestrate; don't relocate build logic into the pipeline config.49- Validate cache hits produce identical results to clean builds before trusting them in CI.5051## Rules5253- Cache tokens/secrets via the secret store, never committed (`secrets-management`).54- Pipeline changes reviewed — cache correctness is easy to break subtly.55- Turborepo config stays proportional; no orchestration of tasks that don't exist.5657## Anti-Patterns5859- Under-declared inputs serving stale cache as fresh results.60- Committed remote-cache tokens.61- Build logic migrated into `turbo.json` instead of package scripts.62- Trusting remote cache without validating correctness.63- Configuring pipelines for tasks/packages that aren't there.6465## Validation Checklist6667- [ ] Task pipeline with correct `dependsOn`.68- [ ] Accurate inputs/outputs per task (cache-correct).69- [ ] Affected-only execution wired to CI.70- [ ] Caching configured; remote (if any) secured; correctness validated.71- [ ] Secrets handled via the store.7273## Definition of Done7475A Turborepo pipeline with correct task dependencies and precise, validated input/output declarations, affected-only CI execution, and secured caching — orchestrating existing package tasks without owning their logic.7677## Related Skills7879`monorepo-selection`, `pnpm-workspaces`, `npm-workspaces`, `ci-cd`, `github-actions`, `secrets-management`, `../../security/dependency-security`.8081## Related Knowledge8283`../../../knowledge/` (task graph, CI needs).8485## Related References8687`../../../references/devops/` (pipeline patterns, when populated).8889## Context Loading Guidance9091- **Requires:** workspace setup, per-package task graph with inputs/outputs.92- **Does not require:** app feature code, unrelated infra.93- **May load:** `ci-cd`, `secrets-management` (remote cache).94- **Stop when:** the pipeline + caching + affected-only CI are configured and validated.9596## Token Efficiency Guidance9798The task × (dependsOn, inputs, outputs) table is the artifact; get those right and the config follows.