You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 -->
Copy file name to clipboardExpand all lines: apps/content/docs/best-practices/monorepo-setup.md
+25-10Lines changed: 25 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,6 +9,10 @@ A monorepo stores multiple related projects in a single repository, a common pra
9
9
10
10
This guide shows you how to efficiently set up a monorepo with oRPC while maintaining end-to-end type safety across all projects.
11
11
12
+
::: info Playground
13
+
Explore a sample monorepo setup in our [Multiservice Monorepo Playground](https://github.com/unnoq/orpc-multiservice-monorepo-playground).
14
+
:::
15
+
12
16
## TypeScript Project References
13
17
14
18
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
37
41
38
42
:::
39
43
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
48
45
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.`
49
46
50
47
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'
55
52
56
53
:::
57
54
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
+
58
62
::: tip
59
63
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)).
60
64
:::
61
65
62
66
::: code-group
63
67
64
-
```txt [contract-first]
68
+
```txt [Contract First]
65
69
apps/
66
70
ββ api/ // Import `core-contract` and implement it
67
71
ββ web/ // Import `core-contract` and set up @orpc/client here
@@ -71,7 +75,7 @@ packages/
71
75
ββ .../
72
76
```
73
77
74
-
```txt [normal]
78
+
```txt [Service First]
75
79
apps/
76
80
ββ api/ // Import `core-service` and run it in your environment
77
81
ββ web/ // Import `core-service` and set up @orpc/client here
@@ -81,6 +85,17 @@ packages/
81
85
ββ .../
82
86
```
83
87
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
0 commit comments