Skip to content

project rulesDevOps and cloudtypescript

Turborepo Monorepo Rules

Project rules for Turborepo monorepos: clear package boundaries, cacheable task pipelines, shared configs and disciplined versioning.

npx workspacetemplates add turborepo-monorepo-rules --tool claude-code

Writes 1 file to your project root

CLAUDE.mdadd to your file21 lines · 1.4 KBFile
# Project rules: Turborepo monorepo

## Layout
- `apps/` holds deployable things, `packages/` holds libraries. Apps may depend on packages; packages never depend on apps, and packages avoid cycles.
- Every package has its own `package.json` with a scoped name such as `@acme/ui`, an explicit `exports` map and a `workspace:*` dependency on siblings.
- Import across packages by package name only. Never use relative paths that leave the package folder.

## Shared config
- Put TypeScript, ESLint and formatter settings in packages like `@acme/tsconfig` and `@acme/eslint-config`, and extend them. Do not copy config files.
- Declare a dependency in the package that imports it, not in the root, except for repo-wide tooling.

## Tasks
- Define tasks in `turbo.json`: `build` depends on `^build`, lists `outputs` (`dist/**`), and `test` and `lint` depend on what they need.
- List environment variables a task reads under `env` so the cache key is correct. Mark long-running tasks like `dev` as `persistent` and `cache: false`.
- Keep scripts named alike in every package (`build`, `test`, `lint`, `typecheck`) so `turbo run` works everywhere.

## Versioning
- Use one package manager and one lockfile. Use Changesets for versioned, published packages; private apps need no version bumps.

## Before finishing
- Run `turbo run lint typecheck test build --filter=...[origin/main]` to check only what changed, and fix cache misses you introduced.

What it does

This rules file explains how an agent should work inside a Turborepo workspace with several apps and packages. It keeps dependencies pointing one way and stops code from reaching into another package by relative path.

It also makes pipelines fast and trustworthy: every task declares its inputs and outputs so the cache hits when it should and misses when it must.

Example

you › Create a shared validation package and use it in the web app and the API

agent › The agent adds packages/validation with an exports map, a tsconfig extending the shared one, workspace dependencies in both apps, matching scripts and a turbo.json entry, then runs the filtered pipeline.

Questions

Does it work with pnpm, npm and Yarn?
Yes. Only the workspace protocol differs a little, so keep the one your repository already uses.
Why list outputs and env in turbo.json?
Turborepo caches by declared inputs and outputs. Missing entries give stale results or no cache hits at all.
  • AWS CDK Rules

    Project rulesaws

    Free
  • Docker Rules

    Project rulesdocker

    Free
  • GitHub Actions Rules

    Project rulesgithub-actions

    Free
  • Kubernetes Rules

    Project ruleskubernetes

    Free