|
2 | 2 |
|
3 | 3 | This file provides guidance to AI coding agents when working with code in this repository. |
4 | 4 |
|
| 5 | +## IMPORTANT: This is a Template Repository |
| 6 | + |
| 7 | +**You MUST read this section carefully before making any changes.** |
| 8 | + |
| 9 | +### Determining Context: Template vs Application |
| 10 | + |
| 11 | +Check the current working directory name: |
| 12 | + |
| 13 | +- **If directory is `fullstack-monorepo-template`**: You are working on the template itself. Keep all demo content and examples intact. |
| 14 | +- **If directory is anything else**: You are working on an application built from this template. You MUST clean up template artifacts before implementing features. |
| 15 | + |
| 16 | +### When Working on an Application (NOT the template) |
| 17 | + |
| 18 | +Before implementing any features, you MUST: |
| 19 | + |
| 20 | +1. **Delete demo/example content**: |
| 21 | + - `packages/web/src/routes/demo/` - All demo routes |
| 22 | + - `packages/web/src/data/` - Demo data files |
| 23 | + - `packages/web/src/routes/rpc/` - Example RPC route files (but keep the pattern in mind) |
| 24 | + - Any other placeholder or example code |
| 25 | + |
| 26 | +2. **Remove template styling**: |
| 27 | + - Do NOT use TanStack-specific theming, logos, or branding |
| 28 | + - Replace placeholder styles with application-specific styling |
| 29 | + - Remove TanStack logo files from `packages/web/public/` if not needed |
| 30 | + - **Keep TanStack Router DevTools** - The development debugging tools are useful and should remain |
| 31 | + |
| 32 | +3. **Update package names** in `package.json` files from `@fullstack-monorepo-template/*` to match the application name |
| 33 | + |
| 34 | +4. **Update service binding names** in `wrangler.jsonc` files to match the application name (replace `fullstack-monorepo-template-worker`) |
| 35 | + |
| 36 | +### When Working on the Template Itself |
| 37 | + |
| 38 | +Keep all demo content intact as it serves as reference examples for users of the template. |
| 39 | + |
5 | 40 | ## Monorepo Architecture |
6 | 41 |
|
7 | 42 | This is a pnpm workspace monorepo with two packages: |
@@ -42,17 +77,21 @@ import type { WorkerRpc } from '../worker/src/rpc'; |
42 | 77 |
|
43 | 78 | This creates a **direct TypeScript dependency** between packages. The monorepo structure enables this cross-package type sharing. |
44 | 79 |
|
45 | | -### TanStack Start Server Context |
| 80 | +### Calling Worker RPC Methods |
46 | 81 |
|
47 | | -In TanStack Start server functions/loaders, access the RPC binding via: |
| 82 | +**CORRECT way to access Worker RPC** in TanStack Start server functions: |
48 | 83 |
|
49 | 84 | ```typescript |
50 | | -import { getServerContext } from '@tanstack/react-start/server'; |
| 85 | +import { getWorkerRpc } from '@/lib/rpc'; |
51 | 86 |
|
52 | | -const { WORKER_RPC } = getServerContext().cloudflare.env; |
53 | | -const result = await WORKER_RPC.sayHello('World'); |
| 87 | +const workerRpc = getWorkerRpc(); |
| 88 | +const result = await workerRpc.sayHello('World'); |
54 | 89 | ``` |
55 | 90 |
|
| 91 | +**DO NOT use** `getServerContext().cloudflare.env` - this is incorrect. Always use the `getWorkerRpc()` helper from `@/lib/rpc.ts`. |
| 92 | + |
| 93 | +See `packages/web/src/routes/rpc/` for complete examples of proper RPC usage patterns. |
| 94 | + |
56 | 95 | ## Commands |
57 | 96 |
|
58 | 97 | ### Development |
@@ -134,8 +173,10 @@ export class WorkerRpc extends WorkerEntrypoint { |
134 | 173 | 3. **Call from web package** in any server function: |
135 | 174 |
|
136 | 175 | ```typescript |
137 | | -const { WORKER_RPC } = getServerContext().cloudflare.env; |
138 | | -const result = await WORKER_RPC.myNewMethod('value'); |
| 176 | +import { getWorkerRpc } from '@/lib/rpc'; |
| 177 | + |
| 178 | +const workerRpc = getWorkerRpc(); |
| 179 | +const result = await workerRpc.myNewMethod('value'); |
139 | 180 | ``` |
140 | 181 |
|
141 | 182 | 4. **Optional**: Add helper function in `packages/web/src/lib/worker-rpc.ts` for convenience |
|
0 commit comments