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
{{ message }}
This repository was archived by the owner on Oct 22, 2025. It is now read-only.
-**Worker**: A stateful, long-lived entity that processes messages and maintains state
@@ -20,12 +43,14 @@
20
43
21
44
## Build Commands
22
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.
@@ -83,26 +110,28 @@ This ensures imports resolve correctly across different build environments and p
83
110
- UPPER_CASE for constants
84
111
- Use `#` prefix for private class members (not `private` keyword)
85
112
-**Error Handling:**
86
-
- Extend from `WorkerError` base class
113
+
- Extend from `WorkerError` base class (packages/core/src/worker/errors.ts)
87
114
- Use `UserError` for client-safe errors
88
115
- Use `InternalError` for internal errors
89
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.
90
117
- Write log messages in lowercase
91
-
- Instead of returning raw HTTP responses with c.json, use or write an error in packages/rivetkit/src/worker/errors.ts and throw that instead. The middleware will automatically serialize the response for you.
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 })`
- Instead of returning errors as raw HTTP responses with c.json, use or write an error in packages/rivetkit/src/worker/errors.ts and throw that instead. The middleware will automatically serialize the response for you.
92
123
93
124
## Project Structure
94
125
95
126
- Monorepo with pnpm workspaces and Turborepo
96
-
- Core code in `packages/rivetkit/`
127
+
- Core code in `packages/core/`
97
128
- Platform implementations in `packages/platforms/`
98
129
- Driver implementations in `packages/drivers/`
99
130
100
131
## Development Notes
101
132
102
-
- Prefer classes over factory functions
103
133
- Use zod for runtime type validation
104
134
- Use `assertUnreachable(x: never)` for exhaustive type checking in switch statements
105
-
- Follow existing patterns for P2P networking
106
135
- Add proper JSDoc comments for public APIs
107
136
- Ensure proper error handling with descriptive messages
108
137
- Run `pnpm check-types` regularly during development to catch type errors early. Prefer `pnpm check-types` instead of `pnpm build`.
@@ -112,3 +141,58 @@ This ensures imports resolve correctly across different build environments and p
112
141
## Test Guidelines
113
142
114
143
- Do not check if errors are an instanceOf WorkerError 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
+
### `examples/*/package.json`
150
+
151
+
- Always name the example `example-{name}`
152
+
- Always use `workspace:*` for dependencies
153
+
- Use `tsx` unless otherwise instructed
154
+
- Always have a `dev` and `check-types` scripts
155
+
-`dev` should use `tsx --watch` unless otherwise instructed
156
+
-`check-types` should use `tsc --noEmit`
157
+
158
+
### `examples/*/README.md`
159
+
160
+
Always include a README.md. The `README.md` should always follow this structure:
161
+
162
+
```md
163
+
# {human readable title} for RivetKit
164
+
165
+
Example project demonstrating {specific feature} with [RivetKit](https://rivetkit.org).
166
+
167
+
[Learn More →](https://github.com/rivet-gg/rivetkit)
0 commit comments