Cursor rules for Monorepo
Several apps and shared packages in one repository.
.cursor/rules/monorepo.mdc
--- description: Guardrails for working across apps and packages in the monorepo globs: apps/**/*.ts,apps/**/*.tsx,packages/**/*.ts,packages/**/*.tsx alwaysApply: false --- # Monorepo ```bash pnpm install # install every workspace's dependencies pnpm --filter <package> test # run one package's tests pnpm -r lint # lint every package pnpm -r test # run the tests in every package ``` Run the tests after every code change. - A change to a shared package can break every app that uses it. Check who imports it before changing a public export. - Keep dependencies declared in the package that uses them. Do not add root-level dependencies for a single package. - Match the style of the file you are editing. Do not reformat files you did not change. Rules for every edit: - Never read, print, edit or commit .env files, credentials, API keys or private keys. - Database schema and migrations belong to one package. Change them only there, with a new migration file. - Never deploy any app to production. I run production deploys myself. - Never run git push --force, git reset --hard, git clean, git checkout -- <file>, git stash or git rebase, and never use --no-verify. Ask first. - The root lockfile and workspace config (pnpm-workspace.yaml, turbo.json, nx.json): do not edit without asking.
Why it says what it says
Scope to one package
In a monorepo the agent's biggest risk is wandering into unrelated packages. Naming the scope keeps diffs reviewable.
Filtered commands
Running every package's tests after each small edit is slow. Filtered commands first, full run at the end.
Shared packages
A change to a shared export breaks other apps quietly. The rule asks the agent to look at importers first.
Single owner for the schema
When several apps touch the database, migrations drift. One owning package keeps a single history.
Workspace config is off limits
Root config and the lockfile affect every package at once, so changes there deserve a human decision.