agentleFS
louisbrulenaudetlouisbrulenaudet/monorepo-template/AGENTS.md

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

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
  1. Very specific:

    Dependencies: add every third-party dependency to the catalog in pnpm-workspace.yaml and reference it as "catalog:" (one-offs install via …

    line 81
  2. Very specific:

    Every app under apps/ bumps together as one Changesets fixed group, so one vX.Y.Z tag is a valid release coordinate.

    line 85
  3. Very specific:

    Run dev servers through the harness's background-task mechanism (never a bare &) and stop them when done.

    line 112

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

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

PrefixExampleRoleProduction surface
worker-apiworker-apiHTTP gateway (sticky name)Public HTTP only
worker-worker-accountBusiness logicRPC only via service bindings
queue-queue-emailQueue-only consumerqueue() handler; no public HTTP
webhook-webhook-exampleExternal webhook ingressPublic HTTP for provider callbacks
mcp-mcp-toolsMCP serverPublic HTTP MCP (SSE / streamable HTTP); tools call worker-* via RPC
front-front-appReact SPAVite → 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.

TaskLocation
HTTP routeapps/worker-api/src/routes/<feature>.ts → mount in src/index.ts
Zod schemaspackages/dtos-common/src/{api,rpc,queue,webhook}/
Shared enumspackages/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 Workerspackages/hono-middleware (one export per middleware; each app registers them in its own index.ts)
DB schema / migrationsapps/<owner>/src/db/ (one owner; never packages/db-*)
Frontend featureapps/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 / secretsenv 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:

CommandDescription
pnpm run checkFastest tier: types, then lint, format, both syncpack checks, and the hook suite as parallel //# root tasks
pnpm run fixtypes, deps:fix, deps:format, lint:fix, then format:fix (format last)
pnpm run ciFull 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:affectedci scoped with --affected, minus audit - mid-task only, never a substitute for ci
pnpm run ci:agentci with lint:agent, --output-logs=errors-only, --log-order=grouped
pnpm run ci:sandboxci: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:agentLint with --format=agent, no auto-fix
pnpm react-doctor / :changedOffline React Doctor scan of front-*; :changed after React edits (rule frontend/react)
pnpm typescf 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 boundariesPackage tags vs turbo.json
pnpm hooks:testsh -n plus the regression table for hooks/
pnpm spell:check / spell:wordscspell 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:agentUnused files, exports, deps; --production --strict; one line per symbol. Diagnostic only, never in ci
pnpm jscpdWhole-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:formatsyncpack lint (catalog: for third-party, workspace:* for @repo/**) / autofix / field ordering
pnpm preview:deploy / preview:deleteWorker Preview of every app (branch-slug name). Outward-facing; denied to agents (rule ops/previews)
pnpm release:checkChangeset 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:statusRead-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), then git add it and run pnpm release:check. Tests, docs, and tooling need none. Writing and bump rules: rule ops/changesets; the procedure: skill changeset.
  • Merging the chore: release PR is the release act; no v* tag is ever pushed by hand. gate validates the merged commit on main, 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 to check-types, test, build, dev, deploy, upload, preview, types. Prefer scoped turbo while iterating; --affected is for GitHub CI. Run package scripts from the root or with pnpm -w - a raw package script bypasses Turbo dependencies. Never combine -w with --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. Never cd into a package to lint; narrow with a path: pnpm --filter=front-app run lint:check. Why: rules core/turborepo, quality/lint-config.
  • Lint contract: iterate with pnpm lint:fix, finish with pnpm lint:agent and read only that output (file:line:col: severity plugin(rule): message help:); never parse the TTY-dependent lint:check output. On a fresh clone, run pnpm types before a bare pnpm lint:fix / pnpm lint:agent: type-aware lint reads the gitignored .cloudflare/types, which check, fix, and the ci* scripts generate first. Suppressions: oxlint-disable* only (rule quality/code-style). Type checking stays with tsc via turbo run check-types.
  • Knip is a diagnostic, not a gate: neither CI nor pnpm run ci runs it, and the PR Code quality comment lists what a change adds or resolves; never blanket-ignore; per-override rationale in rule quality/knip.

Verifying a change (agents)

GoalCommand
One workspace's testspnpm turbo run test --filter=<ws> (a cache hit replays the log; --force re-executes)
One test filepnpm --filter=<ws> exec vitest run tests/<path>.test.ts
Fast static recheckpnpm run check
After editing a cloudflare.config.tspnpm types, then pnpm check-types
Mid-task iterationpnpm run ci:affected
Full gate - required before finishing or opening a PRpnpm run ci, or pnpm run ci:agent for machine-readable output
Full gate inside a sandboxpnpm 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 probeskill 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.
  • tools is the only real least-privilege gate. Parent acceptEdits overrides a subagent's permissionMode; omit Edit/Write/Bash for 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, its cloudflare.config.ts included. Worker-to-Worker: a service binding by Worker name in the caller's cloudflare.config.ts (bindings.worker({ worker: "worker-foo-production" })), never a package import.
  • A new app/package needs turbo.json with "extends": ["//"] and a tags entry (app, contracts, contracts-base, framework, lib, or config).

Decision Checklist

  1. Worker-to-Worker call? Service binding RPC, not HTTP.
  2. DB access? Schema + binding in one owning worker-* / queue-* under src/db/ - never packages/db-*, never the same DB binding on multiple apps. Others use RPC or a queue.
  3. Public HTTP only for gateway, webhooks, MCP, and frontends - not for business RPC or queue-only workers.
  4. SPA to API? front-* and worker-* both build with the Cloudflare Vite plugin (cf dev / cf build), each its own Worker with its own cloudflare.config.ts; front-* is assets-only. Never co-locate the gateway as a Vite auxiliaryWorkers entry or put API routes in the assets Worker.
  5. Testing a branch remotely? Worker Previews (the ctx.isPreview branch of cloudflare.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; update worker-api and front-app together.
  • CD (cd.yml, rule ops/cd) and branch Previews (preview.yml, rule ops/previews) are paused until the CD_ENABLED / PREVIEWS_ENABLED repository variables are true.

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.