Skip to content

Commit 22999a0

Browse files
authored
docs: Multiservice Monorepo Playground (#1209)
Fixes #1018 <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **Documentation** * Updated monorepo setup best practices guide with improved organization and clarity. * Added new Multiservice Monorepo Playground with local development setup instructions and examples. * Enhanced documentation sections with clearer recommendations, tip blocks, and illustrative code examples demonstrating hybrid architectures. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
1 parent 48d6b8b commit 22999a0

File tree

2 files changed

+27
-10
lines changed

2 files changed

+27
-10
lines changed

β€Žapps/content/docs/best-practices/monorepo-setup.mdβ€Ž

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ A monorepo stores multiple related projects in a single repository, a common pra
99

1010
This guide shows you how to efficiently set up a monorepo with oRPC while maintaining end-to-end type safety across all projects.
1111

12+
::: info Playground
13+
Explore a sample monorepo setup in our [Multiservice Monorepo Playground](https://github.com/unnoq/orpc-multiservice-monorepo-playground).
14+
:::
15+
1216
## TypeScript Project References
1317

1418
When consuming, some parts of the client may end up being typed as `any` because the client environment doesn't have access to all types that oRPC procedures depend on. The most effective solution is to use [TypeScript Project References](https://www.typescriptlang.org/docs/handbook/project-references.html). This ensures the client can resolve all types used by oRPC procedures while also improving TypeScript performance.
@@ -37,14 +41,7 @@ When consuming, some parts of the client may end up being typed as `any` because
3741

3842
:::
3943

40-
## Recommended Structure
41-
42-
- `/apps`: `references` dependencies in `tsconfig.json`
43-
- `/packages`: Enable `composite` in `tsconfig.json`
44-
45-
The key principle is separating the server component (with `composite` enabled) into a dedicated package containing only necessary files. This approach simplifies dealing with the `composite` option's constraints.
46-
47-
::: details Common `composite` option's constraint
44+
::: tip Common `composite` option's constraint
4845
The most common issue with `composite` is missing type definitions, resulting in: `The inferred type of "X" cannot be named without a reference to "Y". This is likely not portable. A type annotation is necessary.`
4946

5047
If you encounter this, try installing package `Y` if not already installed and adding this to your codebase where the error occurs:
@@ -55,13 +52,20 @@ import type * as _A from '../../node_modules/detail_Y_path_here'
5552

5653
:::
5754

55+
## Recommended Structure
56+
57+
- `/apps`: `references` dependencies in `tsconfig.json`
58+
- `/packages`: Enable `composite` in `tsconfig.json`
59+
60+
The key principle is separating the server component (with `composite` enabled) into a dedicated package containing only necessary files. This approach simplifies dealing with the `composite` option's constraints.
61+
5862
::: tip
5963
Avoid **alias imports** inside server components when possible. Instead, use **linked workspace packages** (e.g., [PNPM Workspace protocol](https://pnpm.io/workspaces#workspace-protocol-workspace)).
6064
:::
6165

6266
::: code-group
6367

64-
```txt [contract-first]
68+
```txt [Contract First]
6569
apps/
6670
β”œβ”€ api/ // Import `core-contract` and implement it
6771
β”œβ”€ web/ // Import `core-contract` and set up @orpc/client here
@@ -71,7 +75,7 @@ packages/
7175
β”œβ”€ .../
7276
```
7377

74-
```txt [normal]
78+
```txt [Service First]
7579
apps/
7680
β”œβ”€ api/ // Import `core-service` and run it in your environment
7781
β”œβ”€ web/ // Import `core-service` and set up @orpc/client here
@@ -81,6 +85,17 @@ packages/
8185
β”œβ”€ .../
8286
```
8387

88+
```txt [Hybrid]
89+
apps/
90+
β”œβ”€ api/ // Import `core-service` and set up @orpc/server here
91+
β”œβ”€ web/ // Import `core-contract` and set up @orpc/client here
92+
β”œβ”€ app/
93+
packages/
94+
β”œβ”€ core-contract/ // Define contract with @orpc/contract
95+
β”œβ”€ core-service/ // Import `core-contract` and implement it
96+
β”œβ”€ .../
97+
```
98+
8499
:::
85100

86101
::: info

β€Žapps/content/docs/playgrounds.mdβ€Ž

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ featuring pre-configured examples accessible instantly via StackBlitz or local s
2424
| Bun WebSocket + OpenTelemetry | | [View Source](https://github.com/unnoq/orpc/tree/main/playgrounds/bun-websocket-otel) |
2525
| Electron Playground | | [View Source](https://github.com/unnoq/orpc/tree/main/playgrounds/electron) |
2626
| Browser Extension Playground | | [View Source](https://github.com/unnoq/orpc/tree/main/playgrounds/browser-extension) |
27+
| Multiservice Monorepo Playground | | [View Source](https://github.com/unnoq/orpc-multiservice-monorepo-playground) |
2728
| Vue + Bun + Monorepo (Community) | | [View Source](https://github.com/hunterwilhelm/orpc-community-playgrounds/tree/main/vue-bun) |
2829

2930
:::warning
@@ -47,6 +48,7 @@ npx degit unnoq/orpc/playgrounds/cloudflare-worker orpc-cloudflare-worker-playgr
4748
npx degit unnoq/orpc/playgrounds/bun-websocket-otel orpc-bun-websocket-otel-playground
4849
npx degit unnoq/orpc/playgrounds/electron orpc-electron-playground
4950
npx degit unnoq/orpc/playgrounds/browser-extension orpc-browser-extension-playground
51+
npx degit unnoq/orpc-multiservice-monorepo-playground orpc-multiservice-monorepo-playground
5052

5153
# Community (clone at your own risk)
5254
npx degit hunterwilhelm/orpc-community-playgrounds/vue-bun orpc-vue-bun-monorepo-playground

0 commit comments

Comments
Β (0)