monorepo-template / backend
Cursor rule19 starsChanged 16 days agoApache-2.0View on GitHub
Worker-to-Worker RPC - bindings.worker() by name, WorkerEntrypoint callee, typed RPC deferred, requestId propagation.
- Reads credentials
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 4,144 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository59 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .agents/skills/vercel-react-best-practices/AGENTS.mdAGENTS.md
- hooks/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- hooks/CLAUDE.mdCLAUDE.md
- .cursor/rules/backend/hono-gateway.mdcCursor rule
- .cursor/rules/backend/ports.mdcCursor rule
- .cursor/rules/backend/workers-cache.mdcCursor rule
- .cursor/rules/backend/workers-config.mdcCursor rule
- .cursor/rules/contracts/contracts.mdcCursor rule
- .cursor/rules/core/agent-instructions.mdcCursor rule
- .cursor/rules/core/boundaries.mdcCursor rule
- .cursor/rules/core/guardrails.mdcCursor rule
- .cursor/rules/core/turborepo.mdcCursor rule
- .cursor/rules/core/worktrees.mdcCursor rule
- .cursor/rules/frontend/react.mdcCursor rule
- .cursor/rules/frontend/tailwind.mdcCursor rule
- .cursor/rules/frontend/tanstack-query.mdcCursor rule
- .cursor/rules/frontend/tanstack-router.mdcCursor rule
- .cursor/rules/frontend/vite-config.mdcCursor rule
- .cursor/rules/ops/cd.mdcCursor rule
- .cursor/rules/ops/changesets.mdcCursor rule
- .cursor/rules/ops/ci.mdcCursor rule
- .cursor/rules/ops/previews.mdcCursor rule
- .cursor/rules/ops/quality-report.mdcCursor rule
- .cursor/rules/ops/release.mdcCursor rule
- .cursor/rules/quality/code-style.mdcCursor rule
- .cursor/rules/quality/comments.mdcCursor rule
- .cursor/rules/quality/knip.mdcCursor rule
- .cursor/rules/quality/lint-config.mdcCursor rule
- .cursor/rules/quality/markdown-style.mdcCursor rule
- .cursor/rules/quality/naming.mdcCursor rule
- .cursor/rules/quality/reporting.mdcCursor rule
- .cursor/rules/quality/simplicity.mdcCursor rule
- .cursor/rules/quality/testing.mdcCursor rule
- .cursor/rules/quality/typescript-config.mdcCursor rule
- .cursor/rules/tests/front-react.mdcCursor rule
- .cursor/rules/tests/hono-workers.mdcCursor rule
- cfSkill
- changesetSkill
- front-vitestSkill
- git-commitSkill
- honoSkill
- monorepo-agent-setupSkill
- pnpmSkill
- react-doctorSkill
- reviewSkill
- review-stackSkill
- run-appSkill
- security-auditSkill
- skills-updateSkill
- tanstack-configSkill
- tanstack-querySkill
- tanstack-routerSkill
- turborepoSkill
- ui-ux-design-best-practicesSkill
- vercel-react-best-practicesSkill
- workers-best-practicesSkill
- skills-updateSkill
The file
We split this service-bindings.mdc into the rules it gives an agent
2 rules. About 0 are common, 0 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 13
Call env.BINDING.method() from a route handler or service module, and await every call: RPC client methods are always async.
- Very specific: line 20
Default-export the entrypoint class, or export a named class and set exportName on the caller.
≈ “Common” is an estimate: at least 1 in 5 of the 6,668 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: "Worker-to-Worker RPC - bindings.worker() by name, WorkerEntrypoint callee, typed RPC deferred, requestId propagation."
alwaysApply: false
globs: **/cloudflare.config.ts,apps/worker-*/src/**/*.ts,apps/queue-*/src/**/*.ts,apps/webhook-*/src/**/*.ts,apps/mcp-*/src/**/*.ts
---
# Service Bindings (Worker-to-Worker RPC)
## Caller
- Bind by Worker-name string in the caller's `env`: `FOO: bindings.worker({ worker: "worker-foo-production" })`, the name taken from the `Deployment` table so each mode binds the callee's matching Worker. `exportName` selects a named `WorkerEntrypoint` export (default: the default export) and is required when binding a named class.
- A string reference types the binding as a plain `Fetcher`, without RPC method types. The cf docs' typed form passes the callee's `defineWorker` config, which imports another app's `cloudflare.config.ts` and fails `pnpm boundaries` ([boundaries.mdc](../core/boundaries.mdc)). Typed cross-Worker RPC is deferred to the first `worker-*`; decide it in that change. Never augment `Env` by hand to type a binding.
- Call `env.BINDING.method()` from a route handler or service module, and `await` every call: RPC client methods are always async. Never `env.BINDING.fetch()` when RPC methods are the goal; the exception is a cacheable hot read path ([workers-cache.mdc](workers-cache.mdc)).
- Payload schemas live in `@repo/dtos-common/rpc` ([contracts.mdc](../contracts/contracts.mdc)).
- Cloudflare propagates no custom id across a binding: pass `requestId` as an explicit RPC argument (or queue message field) and log it the same way; traces nest on their own.
## Callee
- Extend `WorkerEntrypoint` from `cloudflare:workers` and add public methods - those are what callers invoke. RPC methods cannot live on a plain `export default { fetch }` handler.
- Default-export the entrypoint class, or export a named class and set `exportName` on the caller.
- Bindings are `this.env` (a class property of `WorkerEntrypoint`: `this.env.GREETING`, `this.env.D1`); RPC methods take only their own arguments, no `request` / `env` parameters.
- Errors lose their class across a binding, so a thrown `HTTPException` reaches the gateway's `errorHandler` as a 500. Return expected outcomes as a result union from `@repo/dtos-common/rpc`; throw an `Error` with a serializable `name` / `code` for the unexpected, which the caller maps by those fields, never `instanceof`. `HTTPException` stays in the Hono gateway.
## After a binding change
1. Callee: exported `WorkerEntrypoint` class with public RPC methods.
2. Caller: `bindings.worker()` in `cloudflare.config.ts`, named per mode.
3. Order: the callee takes a lower `monorepo.deployOrder` than every caller, so it is live before a caller binds it. Remove an RPC method one release after the last caller stops calling it.
4. Shared payload schemas in `dtos-common/rpc` if needed.
5. `pnpm types`, then `pnpm check-types`.
6. The first `worker-*` binding also adds the `createTestHarness` Node suite (checklist in `packages/vitest-config/AGENTS.md`), keeping the pool suites.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

