Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 6515bc5

Browse files
committed
chore: update examples to use turbo (#1017)
1 parent ed1182a commit 6515bc5

File tree

23 files changed

+262
-30
lines changed

23 files changed

+262
-30
lines changed

CLAUDE.md

Lines changed: 182 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,185 @@ Always include a README.md for new packages. The `README.md` should always follo
2828
Apache 2.0
2929
```
3030

31-
[... rest of the existing content remains unchanged ...]
31+
## Common Terminology
32+
33+
- **Actor**: A stateful, long-lived entity that processes messages and maintains state
34+
- **Manager**: Component responsible for creating, routing, and managing actor instances
35+
- **Remote Procedure Call (RPC)**: Method for an actor to expose callable functions to clients
36+
- **Event**: Asynchronous message sent from an actor to connected clients
37+
- **Alarm**: Scheduled callback that triggers at a specific time
38+
39+
### Coordinated Topology Terminology
40+
41+
- **Peer**: Individual actor instance in a coordinated network
42+
- **Node**: Physical or logical host running one or more actor peers
43+
44+
## Build Commands
45+
46+
Run these commands from the root of the project. They depend on Turborepo, so you cannot run the commands within the package itself. Running these commands are important in order to ensure that all dependencies are automatically built.
47+
48+
- **Type Check:** `pnpm check-types` - Verify TypeScript types
49+
- **Check specific package:** `pnpm check-types -F rivetkit` - Check only specified package
50+
- **Build:** `pnpm build` - Production build using Turbopack
51+
- **Build specific package:** `pnpm build -F rivetkit` - Build only specified package
52+
- **Format:** `pnpm fmt` - Format code with Biome
53+
- Do not run the format command automatically.
54+
55+
## Core Concepts
56+
57+
### Topologies
58+
59+
rivetkit supports three topologies that define how actors communicate and scale:
60+
61+
- **Singleton:** A single instance of an actor running in one location
62+
- **Partition:** Multiple instances of an actor type partitioned by ID, useful for horizontal scaling
63+
- **Coordinate:** Actors connected in a peer-to-peer network, sharing state between instances
64+
65+
### Driver Interfaces
66+
67+
Driver interfaces define the contract between rivetkit and various backends:
68+
69+
- **ActorDriver:** Manages actor state, lifecycle, and persistence
70+
- **ManagerDriver:** Manages actor discovery, routing, and scaling
71+
- **CoordinateDriver:** Handles peer-to-peer communication between actor instances
72+
- Only applicable in coordinate topologies
73+
74+
### Driver Implementations
75+
76+
Located in `packages/drivers/`, these implement the driver interfaces:
77+
78+
- **Memory:** In-memory implementation for development and testing
79+
- **Redis:** Production-ready implementation using Redis for persistence and pub/sub
80+
81+
### Platforms
82+
83+
Located in `packages/platforms/`, these adapt rivetkit to specific runtime environments:
84+
85+
- **NodeJS:** Standard Node.js server environment
86+
- **Cloudflare Workers:** Edge computing environment
87+
- **Bun:** Fast JavaScript runtime alternative to Node.js
88+
- **Rivet:** Cloud platform with built-in scaling and management
89+
90+
## Package Import Resolution
91+
92+
When importing from workspace packages, always check the package's `package.json` file under the `exports` field to determine the correct import paths:
93+
94+
1. Locate the package's `package.json` file
95+
2. Find the `exports` object which maps subpath patterns to their file locations
96+
3. Use these defined subpaths in your imports rather than direct file paths
97+
4. For example, if you need to import from a package, check its exports to find if it exposes specific subpaths for different modules
98+
99+
This ensures imports resolve correctly across different build environments and prevents errors from direct file path imports that might change.
100+
101+
## Code Style Guidelines
102+
103+
- **Formatting:** Uses Biome for consistent formatting
104+
- See biome.json for reference on formatting rules
105+
- **Imports:** Organized imports enforced, unused imports warned
106+
- **TypeScript:** Strict mode enabled, target ESNext
107+
- **Naming:**
108+
- camelCase for variables, functions
109+
- PascalCase for classes, interfaces, types
110+
- UPPER_CASE for constants
111+
- Use `#` prefix for private class members (not `private` keyword)
112+
- **Error Handling:**
113+
- Extend from `ActorError` base class (packages/core/src/actor/errors.ts)
114+
- Use `UserError` for client-safe errors
115+
- Use `InternalError` for internal errors
116+
- Don't try to fix type issues by casting to unknown or any. If you need to do this, then stop and ask me to manually intervene.
117+
- Write log messages in lowercase
118+
- Use `logger()` to log messages
119+
- Do not store `logger()` as a variable, always call it using `logger().info("...")`
120+
- Use structured logging where it makes sense, for example: `logger().info("foo", { bar: 5, baz: 10 })`
121+
- Supported logging methods are: trace, debug, info, warn, error, critical
122+
- Instead of returning errors as raw HTTP responses with c.json, use or write an error in packages/rivetkit/src/actor/errors.ts and throw that instead. The middleware will automatically serialize the response for you.
123+
124+
## Project Structure
125+
126+
- Monorepo with pnpm workspaces and Turborepo
127+
- Core code in `packages/core/`
128+
- Platform implementations in `packages/platforms/`
129+
- Driver implementations in `packages/drivers/`
130+
131+
## Development Notes
132+
133+
- Use zod for runtime type validation
134+
- Use `assertUnreachable(x: never)` for exhaustive type checking in switch statements
135+
- Add proper JSDoc comments for public APIs
136+
- Ensure proper error handling with descriptive messages
137+
- Run `pnpm check-types` regularly during development to catch type errors early. Prefer `pnpm check-types` instead of `pnpm build`.
138+
- Use `tsx` CLI to execute TypeScript scripts directly (e.g., `tsx script.ts` instead of `node script.js`).
139+
- Do not auto-commit changes
140+
141+
## Test Guidelines
142+
143+
- Do not check if errors are an instanceOf ActorError in tests. Many error types do not have the same prototype chain when sent over the network, but still have the same properties so you can safely cast with `as`.
144+
145+
## Examples
146+
147+
Examples live in the `examples/` folder.
148+
149+
### Example Configuration
150+
151+
- All examples should have the turbo.json:
152+
153+
```json
154+
{
155+
"$schema": "https://turbo.build/schema.json",
156+
"extends": ["//"]
157+
}
158+
```
159+
160+
### `examples/*/package.json`
161+
162+
- Always name the example `example-{name}`
163+
- Always use `workspace:*` for dependencies
164+
- Use `tsx` unless otherwise instructed
165+
- Always have a `dev` and `check-types` scripts
166+
- `dev` should use `tsx --watch` unless otherwise instructed
167+
- `check-types` should use `tsc --noEmit`
168+
169+
### `examples/*/README.md`
170+
171+
Always include a README.md. The `README.md` should always follow this structure:
172+
173+
```md
174+
# {human readable title} for RivetKit
175+
176+
Example project demonstrating {specific feature} with [RivetKit](https://rivetkit.org).
177+
178+
[Learn More →](https://github.com/rivet-gg/rivetkit)
179+
180+
[Discord](https://rivet.gg/discord) — [Documentation](https://rivetkit.org) — [Issues](https://github.com/rivet-gg/rivetkit/issues)
181+
182+
## Getting Started
183+
184+
### Prerequisites
185+
186+
- {node or bun based on demo}
187+
- {any other related services if this integrates with external SaaS}
188+
189+
### Installation
190+
191+
```sh
192+
git clone https://github.com/rivet-gg/rivetkit
193+
cd rivetkit/examples/{name}
194+
npm install
195+
```
196+
197+
### Development
198+
199+
```sh
200+
npm run dev
201+
```
202+
203+
{instructions to either open browser or run script to test it}
204+
205+
## License
206+
207+
Apache 2.0
208+
```
209+
210+
## Test Notes
211+
212+
- Using setTimeout in tests & test actors will not work unless you call `await waitFor(driverTestConfig, <ts>)`

examples/better-auth/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
"vitest": "^3.1.1"
2525
},
2626
"dependencies": {
27-
"@hono/node-server": "^1.14.4",
28-
"@rivetkit/react": "workspace:0.9.0-rc.1",
27+
"@rivetkit/react": "workspace:*",
2928
"better-auth": "^1.0.1",
3029
"hono": "^4.7.0",
3130
"react": "^18.2.0",

examples/better-auth/turbo.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://turbo.build/schema.json",
3+
"extends": ["//"]
4+
}

examples/chat-room/turbo.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://turbo.build/schema.json",
3+
"extends": ["//"]
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://turbo.build/schema.json",
3+
"extends": ["//"]
4+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://turbo.build/schema.json",
3+
"extends": ["//"]
4+
}

examples/counter/turbo.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://turbo.build/schema.json",
3+
"extends": ["//"]
4+
}

examples/drizzle/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"typescript": "^5.5.2"
1515
},
1616
"dependencies": {
17-
"@rivetkit/db": "workspace:0.9.0-rc.1",
17+
"@rivetkit/db": "workspace:*",
1818
"drizzle-kit": "^0.31.2",
1919
"drizzle-orm": "^0.44.2"
2020
},

examples/drizzle/turbo.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"$schema": "https://turbo.build/schema.json",
3+
"extends": ["//"]
4+
}

examples/elysia/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"typescript": "^5.5.2"
1414
},
1515
"dependencies": {
16-
"@rivetkit/react": "workspace:0.9.0-rc.1",
16+
"@rivetkit/react": "workspace:*",
1717
"elysia": "^1.3.5",
1818
"react": "^18.2.0",
1919
"react-dom": "^18.2.0"

0 commit comments

Comments
 (0)