StarterApp Docs
CodebaseFoundations

Turborepo

High-performance build system for JavaScript and TypeScript monorepos

Turborepo transforms monorepo development through caching and parallel execution. Built by Vercel, it accelerates builds, tests, and development workflows while maintaining the advantages of keeping related projects in a single repository.

Pro Tip

Turborepo optimizes monorepo workflows with remote caching, parallel task execution, and incremental builds to speed up development and CI/CD pipelines.

Monorepo Architecture

A monorepo consolidates multiple projects into one Git repository. This architecture provides:

Atomic Changes - Updates to APIs and their consumers happen in single commits. Breaking changes become coordinated migrations rather than versioning nightmares.

Code Sharing - Shared libraries live alongside applications. Import common code directly without publishing to npm registries.

Consistent Tooling - Configuration for TypeScript, Ultracite, and testing applies across all projects. Standards propagate automatically.

Unified Types - TypeScript definitions flow between packages. Change an interface and see impacts immediately across the entire codebase.

Turborepo's Build Intelligence

Turborepo understands task relationships and optimizes execution:

turbo.json
{
  "pipeline": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": ["dist/**", ".next/**"]
    },
    "test": {
      "dependsOn": ["build"]
    },
    "dev": {
      "cache": false
    }
  }
}

This configuration tells Turborepo:

  • Build dependencies before dependents
  • Cache build outputs for reuse
  • Run development servers without caching
  • Execute tasks in optimal order

Remote Caching

Turborepo's remote caching shares build artifacts across machines and team members:

Remote caching in action
# Developer A builds the project
turbo build
# ✓ Builds everything, caches results

# Developer B pulls latest code
turbo build
# ✓ Downloads cached artifacts, skips rebuild

CI/CD systems benefit similarly. Unchanged packages skip rebuilding entirely. What took minutes now takes seconds.

Parallel Execution

Tasks run concurrently when possible:

Parallel task execution
turbo test
# Running 4 tasks in parallel:
# - packages/ui test
# - packages/auth test
# - packages/utils test
# - apps/web test

CPU cores stay busy. Feedback arrives faster. The development loop tightens.

Incremental Builds

Turborepo tracks file changes and rebuilds only affected packages:

Incremental build example
# Edit packages/ui/Button.tsx
turbo build
# ✓ Rebuilds packages/ui
# ✓ Rebuilds apps using packages/ui
# ✗ Skips unaffected packages

This granular understanding prevents unnecessary work. Large codebases remain responsive.

Pipeline Configuration

Task pipelines define dependencies and caching strategies:

Pipeline configuration
{
  "pipeline": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": ["dist/**"]
    },
    "test": {
      "dependsOn": ["build"],
      "inputs": ["src/**", "tests/**"]
    },
    "lint": {
      "outputs": []
    }
  }
}

Each task declares:

  • dependsOn - Tasks that must complete first
  • outputs - Directories to cache
  • inputs - Files that trigger re-execution

Workspace Integration

Turborepo works with npm, yarn, and pnpm workspaces:

package.json
{
  "workspaces": [
    "apps/*",
    "packages/*"
  ],
  "scripts": {
    "build": "turbo build",
    "dev": "turbo dev",
    "test": "turbo test"
  }
}

Existing monorepo setups adopt Turborepo without restructuring.

Development Workflow

A typical Turborepo development session:

Typical Turborepo workflow
# Clone repository
git clone repo && cd repo

# Install dependencies
pnpm install

# Start development
turbo dev
# ✓ Starts all dev servers in parallel
# ✓ Watches for changes
# ✓ Hot reloads on save

# Run tests
turbo test
# ✓ Runs only affected tests
# ✓ Uses cached results when possible

# Build for production
turbo build
# ✓ Builds in dependency order
# ✓ Caches results for next time

AI-Assisted Development

Turborepo's structured approach benefits AI code generation:

Clear Boundaries - Package organization guides where code belongs. AI understands the separation between apps and libraries.

Consistent Patterns - Task definitions repeat across packages. AI learns the pipeline once and applies it everywhere.

Fast Feedback - Quick builds mean AI can iterate rapidly. Generate, test, refine without waiting.

Cache Awareness - AI-generated code that doesn't affect builds uses cached results. Experimentation stays fast.

Advanced Features

Pruned Lockfiles - Deploy only necessary dependencies:

Prune for deployment
turbo prune --scope=@app/web
# Creates minimal lockfile for deployment

Dry Runs - Preview what would execute:

Dry run preview
turbo build --dry-run
# Shows planned execution without running

Graph Visualization - Understand task relationships:

Generate dependency graph
turbo build --graph
# Generates visual dependency graph

Additional Resources