Turborepo Monorepo Setup

fullstack
TypeScript
architecture
corporate_pm
Remix

Organize multiple apps and packages in a monorepo using Turborepo with shared configs.

12/8/2025

Prompt

Turborepo Monorepo Setup

Create a monorepo structure for [Organization/Project] using Turborepo to manage multiple apps and shared packages.

Requirements

1. Repository Structure

Organize monorepo with:

  • Apps folder containing [Number] applications:

    • [App 1] - [Type] (e.g., Next.js web app)
    • [App 2] - [Type] (e.g., Express API)
    • [App 3] - [Type] (e.g., Mobile app)
  • Packages folder with shared code:

    • [Package 1] - [Purpose] (e.g., UI components)
    • [Package 2] - [Purpose] (e.g., shared utilities)
    • [Package 3] - [Purpose] (e.g., TypeScript configs)

2. Turborepo Configuration

Set up turbo.json with:

  • Build pipeline with dependency management
  • Test pipeline
  • Lint pipeline
  • Dev mode configuration
  • Caching strategy for faster builds
  • Output glob patterns

3. Shared Packages

Create internal packages for:

  • Shared UI components (@repo/ui)
  • Common utilities (@repo/utils)
  • TypeScript configurations (@repo/tsconfig)
  • ESLint configurations (@repo/eslint-config)
  • Shared types/interfaces

4. Dependency Management

Configure:

  • Workspace protocol for internal packages
  • Version synchronization
  • Dependency hoisting
  • Lock file management

5. Build Optimization

Implement:

  • Remote caching (optional)
  • Parallel task execution
  • Incremental builds
  • Dependency-aware task scheduling

Implementation Pattern

[project-name]/
├── apps/
│   ├── [app-name]/
│   │   ├── package.json
│   │   └── src/
│   └── [app-name-2]/
│       ├── package.json
│       └── src/
├── packages/
│   ├── ui/
│   │   ├── package.json
│   │   └── src/
│   ├── config/
│   │   ├── package.json
│   │   └── index.ts
│   └── tsconfig/
│       ├── package.json
│       └── base.json
├── turbo.json
├── package.json
└── pnpm-workspace.yaml

turbo.json Configuration

{
  "$schema": "https://turbo.build/schema.json",
  "pipeline": {
    "build": {
      "dependsOn": ["^build"],
      "outputs": [".next/**", "dist/**", "build/**"]
    },
    "test": {
      "dependsOn": ["build"],
      "outputs": ["coverage/**"],
      "inputs": ["src/**", "test/**"]
    },
    "lint": {
      "outputs": []
    },
    "dev": {
      "cache": false,
      "persistent": true
    },
    "type-check": {
      "dependsOn": ["^build"],
      "outputs": []
    }
  }
}

Root package.json

{
  "name": "[monorepo-name]",
  "private": true,
  "workspaces": ["apps/*", "packages/*"],
  "scripts": {
    "dev": "turbo dev",
    "build": "turbo build",
    "test": "turbo test",
    "lint": "turbo lint",
    "type-check": "turbo type-check"
  },
  "devDependencies": {
    "turbo": "latest"
  }
}

App package.json

{
  "name": "[app-name]",
  "dependencies": {
    "@repo/ui": "*",
    "@repo/utils": "*"
  },
  "devDependencies": {
    "@repo/tsconfig": "*",
    "@repo/eslint-config": "*"
  }
}

Common Commands

# Run dev for all apps
turbo dev

# Build everything
turbo build

# Build specific app
turbo build --filter=[app-name]

# Run multiple tasks
turbo lint test build

# Clear cache
turbo build --force

# Dry run to see what would execute
turbo build --dry-run

Best Practices

  • Use workspace protocol (*) for internal dependencies
  • Configure proper caching for CI/CD
  • Keep shared packages focused
  • Use changesets for versioning
  • Document internal package APIs
  • Set up remote caching for team collaboration

Tags

turborepo
monorepo
build-tools
nx

Tested Models

gpt-4
claude-3-5-sonnet

Comments (0)

Sign in to leave a comment

Sign In