monorepo-template
AGENTS.md18 starsChanged 59 days agoApache-2.0View on GitHub
A minimal, production-oriented monorepo starter: pnpm workspaces + Turborepo, Cloudflare Workers + Hono, and a React (Vite) SPA styled with Tailwind CSS v4. front-app talks to worker-api over HTTP; Worker-to-Worker calls use service-binding RPC. Architecture diagram: README.md. pnpm install, then pnpm dev (all dev servers). One-time machine setup (cf telemetry off, pnpm run login, pnpm prepare for the Vite+ pre-commit hooks): README "Getting started". pnpm run login is cf auth login; bare pnpm login is the npm-registry builtin. A new…
- Reads credentials
- Installs packages
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about checking a change actually works.
Of the AGENTS.md files we read, the 11,773 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 repository60 other files it gives its agents.
- .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/service-bindings.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/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
- playwright-cliSkill
- pnpmSkill
- react-doctorSkill
- reviewSkill
- review-stackSkill
- run-appSkill
- security-auditSkill
- skills-updateSkill
- tanstack-configSkill
- tanstack-devtoolsSkill
- tanstack-querySkill
- tanstack-routerSkill
- turborepoSkill
- ui-ux-design-best-practicesSkill
- vercel-react-best-practicesSkill
- workers-best-practicesSkill
- skills-updateSkill
The file
We split this AGENTS.md into the rules it gives an agent
3 rules. About 0 are common, 0 are distinctive, and 3 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.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 81
Dependencies: add every third-party dependency to the catalog in pnpm-workspace.yaml and reference it as "catalog:" (one-offs install via …
- Very specific: line 85
Every app under apps/ bumps together as one Changesets fixed group, so one vX.Y.Z tag is a valid release coordinate.
- Very specific: line 112
Run dev servers through the harness's background-task mechanism (never a bare &) and stop them when done.
≈ “Common” is an estimate: at least 1 in 5 of the 16,595 AGENTS.md 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
Monorepo Agent Instructions
Project Overview
A minimal, production-oriented monorepo starter: pnpm workspaces + Turborepo, Cloudflare Workers + Hono, and a React (Vite) SPA styled with Tailwind CSS v4. front-app talks to worker-api over HTTP; Worker-to-Worker calls use service-binding RPC. Architecture diagram: README.md.
Quick Start
pnpm install, then pnpm dev (all dev servers). One-time machine setup (cf telemetry off, pnpm run login, pnpm prepare for the Vite+ pre-commit hooks): README "Getting started". pnpm run login is cf auth login; bare pnpm login is the npm-registry builtin.
A new worker under apps/ needs monorepo.deployOrder (lower promotes first; gateways before the SPAs that call them) and monorepo.healthPath (public probe path, or null for no public HTTP surface) in its package.json, then pnpm install before turbo commands. Nothing else lists apps: the changeset group, the root --filter='./apps/*' scripts, and CD all discover them.
Worker Prefixes
| Prefix | Example | Role | Production surface |
worker-api | worker-api | HTTP gateway (sticky name) | Public HTTP only |
worker- | worker-account | Business logic | RPC only via service bindings |
queue- | queue-email | Queue-only consumer | queue() handler; no public HTTP |
webhook- | webhook-example | External webhook ingress | Public HTTP for provider callbacks |
mcp- | mcp-tools | MCP server | Public HTTP MCP (SSE / streamable HTTP); tools call worker-* via RPC |
front- | front-app | React SPA | Vite → gateway over HTTP only |
A Worker that is both RPC and a queue consumer keeps prefix worker-* with the dual-handler layout; queue-* is for queue-only consumers.
Where to Put Things
App-local detail: apps/*/AGENTS.md and packages/*/AGENTS.md.
| Task | Location |
| HTTP route | apps/worker-api/src/routes/<feature>.ts → mount in src/index.ts |
| Zod schemas | packages/dtos-common/src/{api,rpc,queue,webhook}/ |
| Shared enums | packages/enums-common; worker-local under apps/<worker>/src/enums/ |
Request id (X-Request-Id) | requestIdMiddleware in packages/hono-middleware: minted per request by the gateway, never sent by the SPA |
| Hono middleware shared by public-HTTP Workers | packages/hono-middleware (one export per middleware; each app registers them in its own index.ts) |
| DB schema / migrations | apps/<owner>/src/db/ (one owner; never packages/db-*) |
| Frontend feature | apps/front-app/src/{pages,routes,services,hooks,components}/ |
| Agent rules | .claude/rules/<cat>/<name>.md and its .cursor/rules/<cat>/<name>.mdc twin, in the same change (rule core/agent-instructions) |
| Bindings / secrets | env in apps/<worker>/cloudflare.config.ts: bindings.text() for plain values, bindings.secret() for secrets with a bindings.text() fake in the test mode |
| Tests (unit) | apps/<app>/tests/ + @repo/vitest-config (Node, front-*) or @repo/vitest-config/workers (Cloudflare pool, every Worker); every new test passes the authoring gate in rule quality/testing |
| Tests (multi-Worker integration) | Wrangler createTestHarness() from a Node suite - only once a second Worker + service binding exists, and never replacing the per-app pool suites; see packages/vitest-config/AGENTS.md |
Queue-only / dual-handler workers: handlers/request.ts, handlers/message.ts, shared services/, minimal index.ts.
Environment
Node 24 (≥ 24.11, the floor Vite+ vp requires) and the exact pnpm version pinned in root package.json. A Worker app may keep a gitignored .env for local secret values, which cf dev loads; the shell works too (SENTRY_DSN=<dsn> pnpm dev; Turbo passes SENTRY_DSN through to worker-api#dev), and unset leaves Sentry off in dev. Never a .dev.vars: it breaks the Vitest pool, which skips only an unreadable .env. The agent sandbox denies reading a Worker .env, and the Cloudflare Vite plugin aborts on an env file it cannot read, so .claude/settings.json sets SKIP_ENV_FILES=1 and each app's vite.config.ts turns it into envDir: false: sandboxed cf dev / cf build start without the .env values (Sentry off). Every front-app .env* file holds only public VITE_* values; frontend dev overrides go in .env, which the sandboxed dev server skips in favor of the src/config/env.ts defaults. Local ports: rule backend/ports.
A worktree is a fresh checkout: run pnpm install --frozen-lockfile --prefer-offline in it before any turbo command. Sparse-checkout and .worktreeinclude policy: rule core/worktrees.
cf CLI
Cloudflare tooling is the cf CLI (beta) over each app's typed cloudflare.config.ts, run through the package scripts or pnpm --filter=<app> exec cf …, never a global install. The root wrangler devDependency stays only for wrangler tail, a single wrangler secret put, and wrangler preview delete / preview secret put. Find a command with pnpm exec cf cli search "<task>" - keep the query anonymous, the action and resource type only, never names, IDs, domains, or tokens - then read <command> --help (cf schema <command words> for the API request shape) and try it with --dry-run before running it. Results are JSON on stdout, messages and errors on stderr. In a non-interactive session a destructive command without --force prints Aborted. and exits 0, so a zero exit does not prove anything changed; --force can also be an API parameter, so read --help before passing it. Never run cf dev, cf build, cf deploy, or cf init in a directory without cloudflare.config.ts: autoconfiguration rewrites the project. Agents never run cf auth login. Modes, bindings, Build Output, and the Local Explorer: skill cf.
Root Scripts (pnpm)
pnpm run lists every root script. Non-obvious ones:
| Command | Description |
pnpm run check | Fastest tier: types, then lint, format, both syncpack checks, and the hook suite as parallel //# root tasks |
pnpm run fix | types, deps:fix, deps:format, lint:fix, then format:fix (format last) |
pnpm run ci | Full local PR gate: pnpm run types, pnpm run boundaries, one turbo run --continue=dependencies-successful of every check, pnpm run audit. Reports all failures in one pass |
pnpm run ci:affected | ci scoped with --affected, minus audit - mid-task only, never a substitute for ci |
pnpm run ci:agent | ci with lint:agent, --output-logs=errors-only, --log-order=grouped |
pnpm run ci:sandbox | ci:agent minus build: front-app declares .env* as build inputs, and turbo aborts traversal on one the sandbox cannot read. They are all readable through the **/apps/front-app/.env* allow once the settings patch lands; until then only .env and .env.production are. Ask the user to run pnpm run ci for build coverage |
pnpm lint:agent | Lint with --format=agent, no auto-fix |
pnpm react-doctor / :changed | Offline React Doctor scan of front-*; :changed after React edits (rule frontend/react) |
pnpm types | cf workers types per Worker: regenerates the gitignored .cloudflare/types/index.d.ts (global Env) from cloudflare.config.ts. Cached by Turbo, and check-types depends on it |
pnpm boundaries | Package tags vs turbo.json |
pnpm hooks:test | sh -n plus the regression table for hooks/ |
pnpm spell:check / spell:words | cspell over the repo, dotfiles included / unknown words only, one per line. Vocabulary: .cspell/project-words.txt (not in check or ci) |
pnpm knip / knip:production / knip:agent | Unused files, exports, deps; --production --strict; one line per symbol. Diagnostic only, never in ci |
pnpm jscpd | Whole-repo copy/paste scan (.jscpd.json). Report-only, never in check or ci: the PR Code quality comment shows only the duplication and Knip findings a PR adds or resolves (rule ops/quality-report) |
pnpm deps:check / deps:fix / deps:format | syncpack lint (catalog: for third-party, workspace:* for @repo/**) / autofix / field ordering |
pnpm preview:deploy / preview:delete | Worker Preview of every app (branch-slug name). Outward-facing; denied to agents (rule ops/previews) |
pnpm release:check | Changeset gate, also in ci, ci:agent, ci:sandbox, and PR CI: fails when a shipped path or an app's runtime catalog entry changed with no changeset since origin/main, on a non-app name, a title over 100 characters or a heading, and on major without CHANGESET_ALLOW_MAJOR=1. Diffs tracked files only: git add a new changeset first |
pnpm release:status | Read-only release plan: every pending changeset and the next versions |
Dependencies: add every third-party dependency to the catalog in pnpm-workspace.yaml and reference it as "catalog:" (one-offs install via catalogMode: prefer but fail syncpack lint); internal packages use "workspace:*".
Releases
Every app under apps/ bumps together as one Changesets fixed group, so one vX.Y.Z tag is a valid release coordinate. Nothing is published to npm; a release is a git tag plus a Cloudflare Workers promote.
- A PR that changes what an app ships carries a changeset naming the affected apps, never an
@repo/*package:pnpm changeset --patch <app>[,<app>] -m '<title>'(or--minor;--empty -m '<reason>'when nothing observable changes), thengit addit and runpnpm release:check. Tests, docs, and tooling need none. Writing and bump rules: ruleops/changesets; the procedure: skillchangeset. - Merging the
chore: releasePR is the release act; nov*tag is ever pushed by hand.gatevalidates the merged commit onmain, then the tag is cut and handed to CD.
Release state machine, recovery, and rollback: rule ops/release; contributor walkthrough: .changeset/README.md.
Scoping
- Turbo filters (
--filter=<pkg>,--filter=...pkg...,--affected) apply tocheck-types,test,build,dev,deploy,upload,preview,types. Prefer scoped turbo while iterating;--affectedis for GitHub CI. Run package scripts from the root or withpnpm -w- a raw package script bypasses Turbo dependencies. Never combine-wwith--filter: pnpm adds the root project to the selection and runs the command there too. - Lint, format, and syncpack are
//#root tasks - one whole-repo pass at repo-root CWD. Nevercdinto a package to lint; narrow with a path:pnpm --filter=front-app run lint:check. Why: rulescore/turborepo,quality/lint-config. - Lint contract: iterate with
pnpm lint:fix, finish withpnpm lint:agentand read only that output (file:line:col: severity plugin(rule): message help:); never parse the TTY-dependentlint:checkoutput. On a fresh clone, runpnpm typesbefore a barepnpm lint:fix/pnpm lint:agent: type-aware lint reads the gitignored.cloudflare/types, whichcheck,fix, and theci*scripts generate first. Suppressions:oxlint-disable*only (rulequality/code-style). Type checking stays with tsc viaturbo run check-types. - Knip is a diagnostic, not a gate: neither CI nor
pnpm run ciruns it, and the PRCode qualitycomment lists what a change adds or resolves; never blanket-ignore; per-override rationale in rulequality/knip.
Verifying a change (agents)
| Goal | Command |
| One workspace's tests | pnpm turbo run test --filter=<ws> (a cache hit replays the log; --force re-executes) |
| One test file | pnpm --filter=<ws> exec vitest run tests/<path>.test.ts |
| Fast static recheck | pnpm run check |
After editing a cloudflare.config.ts | pnpm types, then pnpm check-types |
| Mid-task iteration | pnpm run ci:affected |
| Full gate - required before finishing or opening a PR | pnpm run ci, or pnpm run ci:agent for machine-readable output |
| Full gate inside a sandbox | pnpm run ci:agent; fall back to pnpm run ci:sandbox if traversal aborts, then hand build back to the user |
| Run, smoke, browser-check, local traces, Preview probe | skill run-app |
Run dev servers through the harness's background-task mechanism (never a bare &) and stop them when done.
Agent tooling
Dual-tree layout, sync policy, hooks, skills, MCP: skill monorepo-agent-setup; hook scripts: hooks/AGENTS.md. Every apps/*, packages/*, and hooks/ directory has an AGENTS.md + CLAUDE.md pair - give new packages the same. turbo query and remote-cache provisioning: rule core/turborepo.
Subagents (read-only): explorer, planner, verifier, bundle-analyzer, docs-researcher, reviewer (launched by /review). They load this file and the always-on rules at start, and path-scoped rules when they Read a matching file. Use explorer / planner instead of the built-in Explore / Plan, which load neither CLAUDE.md nor .claude/rules/; if you use a built-in anyway, restate the binding constraints in the prompt. The human-only /review and /review-stack commands are described in README.md.
- Main thread: iterative work, phases sharing context, a small targeted change, latency-sensitive work.
- Plan mode: an uncertain approach or a multi-file change; skip it when the diff fits one sentence.
- Skill: a reusable procedure in the current context (
/review,/git-commit). - Subagent: output you will never re-read, a tool restriction the main thread cannot express, or a reviewer who is not the author. Never for a trivial or strictly sequential step, or one sharing mutable state with the main thread.
toolsis the only real least-privilege gate. ParentacceptEditsoverrides a subagent'spermissionMode; omitEdit/Write/Bashfor read-only agents.- Agents never write scratch files into the working tree. Findings come back in the reply.
Enforced Boundaries
pnpm boundaries (inside pnpm run ci) fails on tag violations; rules in root turbo.json boundaries.tags, rationale in rule core/boundaries.
- Nothing may import an
app, itscloudflare.config.tsincluded. Worker-to-Worker: a service binding by Worker name in the caller'scloudflare.config.ts(bindings.worker({ worker: "worker-foo-production" })), never a package import. - A new app/package needs
turbo.jsonwith"extends": ["//"]and atagsentry (app,contracts,contracts-base,framework,lib, orconfig).
Decision Checklist
- Worker-to-Worker call? Service binding RPC, not HTTP.
- DB access? Schema + binding in one owning
worker-*/queue-*undersrc/db/- neverpackages/db-*, never the same DB binding on multiple apps. Others use RPC or a queue. - Public HTTP only for gateway, webhooks, MCP, and frontends - not for business RPC or queue-only workers.
- SPA to API?
front-*andworker-*both build with the Cloudflare Vite plugin (cf dev/cf build), each its own Worker with its owncloudflare.config.ts;front-*is assets-only. Never co-locate the gateway as a ViteauxiliaryWorkersentry or put API routes in the assets Worker. - Testing a branch remotely? Worker Previews (the
ctx.isPreviewbranch ofcloudflare.config.ts, built under--mode production, +pnpm preview:deploy), never Version URLs or a new mode. A Preview's service bindings reach the production callee.
Contribution
- HTTP contracts live in
@repo/dtos-common; updateworker-apiandfront-apptogether. - CD (
cd.yml, ruleops/cd) and branch Previews (preview.yml, ruleops/previews) are paused until theCD_ENABLED/PREVIEWS_ENABLEDrepository variables aretrue.
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.

