Developer Tools6 min read

Monorepo Engineer

Structures and optimises monorepos - Turborepo pipelines, pnpm workspaces, shared packages, build caching, and affected-only CI runs.

monorepoTurborepoNxpnpm workspacesbuild cachingshared packages

The Monorepo Engineer structures multi-package repositories for fast builds, shared code, and independent deployments. A well-configured monorepo cuts CI time by 60–80% through build caching and affected-package detection. A poorly configured one creates an interconnected mess that deploys everything on every change.

Turborepo + pnpm Setup

# pnpm-workspace.yaml
packages:
  - 'apps/*'
  - 'packages/*'

# turbo.json - define task pipeline
{
  "$schema": "https://turbo.build/schema.json",
  "pipeline": {
    "build": {
      "dependsOn": ["^build"],  // Build dependencies first (topological)
      "outputs": [".next/**", "dist/**", "build/**"]
    },
    "test": {
      "dependsOn": ["build"],
      "outputs": ["coverage/**"]
    },
    "lint": { "outputs": [] },
    "dev": {
      "cache": false,       // Never cache dev servers
      "persistent": true
    }
  }
}

Repository Structure

monorepo/
  apps/
    web/           # Next.js app
    api/           # Node.js API
    admin/         # Admin dashboard
  packages/
    ui/            # Shared React components (published or internal)
    config/        # Shared tsconfig, eslint, tailwind configs
    utils/         # Shared utility functions
    types/         # Shared TypeScript types

# packages/ui/package.json
{
  "name": "@acme/ui",
  "main": "./src/index.ts",
  "exports": {
    ".": "./src/index.ts"   // Internal packages: point to source, not build
  }
}

# apps/web/package.json
{
  "dependencies": {
    "@acme/ui": "workspace:*"   // pnpm workspace protocol
  }
}

CI Optimisation

# .github/workflows/ci.yml
jobs:
  build:
    steps:
      - uses: actions/checkout@v4
        with:
          fetch-depth: 2  # Turborepo needs at least 2 commits for diffing

      - uses: pnpm/action-setup@v4
      - uses: actions/cache@v4
        with:
          path: .turbo   # Cache Turborepo's local cache
          key: turbo-${{ hashFiles('pnpm-lock.yaml') }}-${{ github.sha }}
          restore-keys: turbo-${{ hashFiles('pnpm-lock.yaml') }}-

      - run: pnpm install --frozen-lockfile
      # Only build/test packages affected by changes since last commit
      - run: pnpm turbo run build test lint --filter="...[HEAD^1]"

Explore all agents

Browse the full library of specialized AI agents.