How to install dependencies when mono repo is too big

As I have explained in another post: Looking for feedback on structuring a big project with turbo repo

The way we decided to implement the repository, using nested packages with pnpm workspaces, doesn’t seem to be working as I expected.

We are in the process of migrating from react-router v6 to v7, and scaling this app to the setup we have, it’s getting chaotic.

Short summary of our setup

/ ← repo root
├── package.json              # “my-monorepo” 
├── pnpm-workspace.yaml       # includes apps/**/* , shared/**/*
├── turbo.json                # defines pipeline (build, dev, test, etc.)
├── apps
│   └── web-app 1
│       ├── package.json      # “@web-1/root”
│       ├── src/
│       └── packages/         # nested workspaces
│           ├── ui-kit
│           │   └── package.json  # “@web-1/ui-kit”
│           └── utils
│               └── package.json  # “@web-1/utils”
│   └── web-app 2
│       ├── package.json      # “@web-2/root”
│       ├── src/
│       └── packages/         # nested workspaces
│           ├── ui-kit
│           │   └── package.json  # “@web-2/ui-kit”
│           └── utils
│               └── package.json  # “@web-2/utils”
│
├── shared (across all apps)
│   ├── config
│   │   └── package.json      # “@shared/config”
│   └── hooks
│       └── package.json      # “@shared/hook”

All the dedicated web-1 and web-2 packages are JIT, sort of packages, meaning that they are all dependent on the corresponding app.

Questions, where I would like to get feedback:

  • Because we use JIT, does this mean we have to define the exports explicitly?
  • If I use react-router in web-1, do I need to install that dependency on every nested package if I want to use anything from it? Or is it better to use peer dependencies in this case?
  • Are the names we pick for the packages ok, or do we have to follow a particular pattern for them to work?
  • What would be the best approach for installing a new dependency? I have tried the following, but it doesn’t seem to follow the dependency tree: pnpm add react-router@latest --save-dev --recursive --filter=@web-1/root.
  • If there are other packages under “shared” using react-router as well, should that be different?
  • When I try to make a dependency chart, it seems like we have circular dependencies, but in practice, we don’t. What could I be missing?
  • Offtopic, but still related, is there any specific AI model recommended to work with turborepo? No matter how much I try to specify rules or instructions, it never generates decent outputs.

To be honest, even though it’s not discouraged, having nested packages it’s the root of our issues.

Sorry for the long post!
Thanks again!