Code structure for a large monorepo using nx + tRPC

We have a large monorepo with a single tRPC API that will be used by several web clients and other consumers. We use nx for our build system.

We want a way to share the API contract between client and api, but we don’t want implementation changes that do not change the API contract to trigger a rebuild of all the clients and consumers.

Ideally we’d also want to have our api split into several routers and have some applications only rely on a subset of the routers.

We don’t want to use codegen to generate shared types. We’re after a structure that will let us separate the contract from the implementation, similar to ts-rest (

Does anyone else have a similar use case, and can share how they structured their code/ app/ libs ?