Skip to content

Monorepo Workflows with AI

You renamed a shared type in your monorepo’s core package. Seven downstream packages now have broken builds, two of them have integration tests that pass locally but fail in CI because they depend on a package that has not been rebuilt yet. The AI tool you used only looked at the file you were editing — it had no idea about the ripple effect across your workspace.

  • Monorepo-aware prompting strategies that account for cross-package dependencies
  • Workflows for coordinated multi-package changes with AI assistance
  • Techniques for AI-driven dependency graph analysis and impact assessment
  • Automated release coordination patterns using AI tools
  • Strategies for shared configuration and convention enforcement

Monorepos amplify the context problem. A change to a shared utility might affect 15 packages. The AI needs to understand not just the file you are editing, but the entire dependency chain.

Structure your .cursor/rules to encode the monorepo graph:

# .cursor/rules (root)
This is a Turborepo monorepo managed with pnpm workspaces.
Package structure:
- /packages/core - Shared types, utilities, base classes (NO external deps)
- /packages/ui - React component library (depends on: core)
- /packages/api-client - API SDK (depends on: core)
- /apps/web - Next.js frontend (depends on: core, ui, api-client)
- /apps/api - Express backend (depends on: core)
- /apps/admin - Admin dashboard (depends on: core, ui, api-client)
Build order: core → ui, api-client → web, api, admin
CRITICAL RULES:
- Changes to /packages/core affect ALL other packages. Always check downstream.
- Never import from /apps/* into /packages/*
- Shared types go in /packages/core/src/types/
- Each package has its own tsconfig.json that extends /tsconfig.base.json

When working on cross-package changes, explicitly reference the dependency chain: @packages/core/src/types @packages/ui/src/components @apps/web/src/pages

When modifying shared code, work from the bottom of the dependency tree upward.

  1. Analyze the impact

    Before touching any code, understand what will break.

  2. Modify the source package

    Change the shared type, utility, or component in the foundational package.

  3. Build the source package

    Verify the source package compiles correctly in isolation.

  4. Update direct dependents

    Move one level up the dependency tree. Update each direct dependent.

  5. Build and test each dependent

    Verify each dependent compiles and its tests pass before moving further up.

  6. Continue up the tree

    Repeat until you reach the leaf applications.

  7. Run the full pipeline

    Execute the complete build and test suite to catch any issues.

AI tools can help maintain consistency across monorepo packages.

Understanding your dependency graph is critical for safe changes. AI tools can generate and analyze these graphs.

Analyze the import statements across our entire monorepo and build a dependency graph.
Flag any:
- Circular dependencies between packages
- Apps importing from other apps (forbidden)
- Packages importing from apps (forbidden)
- Unused packages (no dependents)
- Packages with suspiciously deep dependency chains (> 3 levels)
Visualize the graph as a text-based tree structure.

When a change spans multiple packages, version bumping needs to follow the dependency order.

“The AI modified a shared package without updating dependents.” Your rules file does not encode the dependency graph. Add explicit dependency chains and build-order requirements to your .cursor/rules or CLAUDE.md.

“Build passes locally but fails in CI for downstream packages.” You likely tested with stale builds of dependencies. Always run turbo build --filter=...affected (or equivalent) to rebuild the entire affected chain.

“The AI created circular dependencies between packages.” Add explicit layering rules to your AI configuration: “packages/core MUST NOT import from packages/ui or any app.” AI tools follow constraints well when they are stated clearly.

“Version bumps are inconsistent across packages.” Use changesets or a similar tool for version management. Teach the AI your versioning workflow through rules files rather than relying on ad-hoc prompting.