fastify-boilerplate
AGENTS.md474 starsChanged 11 days agoMITView on GitHub
Instructions for AI coding assistants (Cursor, Claude Code, GitHub Copilot, etc.) A production-ready Fastify 5 boilerplate using Clean Architecture, CQRS, DDD, and functional programming. TypeScript strict mode, ESM-only, Node in the version of .nvmrc (native TS execution, no build step). Always run pnpm check after making changes. If it fails on formatting, import order or other safe fixes, run pnpm check:fix, then pnpm check again. Detailed rules live in .agents/rules/, one file per area. The paths list in each file's…
- Reads credentials
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 31,700 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 repositoryOne other file it gives its agents.
- CLAUDE.mdCLAUDE.md
The file
We split this AGENTS.md into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 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.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 22
Always run pnpm check after making changes.
- Very specific: line 82
No classes except errors: everything else is a factory function that returns an object.
- Very specific: line 106
Use the built-in exceptions in src/shared/exceptions/exceptions.ts.
- Very specific: line 111
Always include a descriptive message: throw new NotFoundException('User with id X not found')
≈ “Common” is an estimate: at least 1 in 5 of the 40,246 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
AGENTS.md
Instructions for AI coding assistants (Cursor, Claude Code, GitHub Copilot, etc.)
Project overview
A production-ready Fastify 5 boilerplate using Clean Architecture, CQRS, DDD, and functional programming.
TypeScript strict mode, ESM-only, Node in the version of .nvmrc (native TS execution, no build step).
Quick reference
| What | Where |
| Package manager | pnpm (never npm or yarn) |
| Linter + formatter | Biome (never ESLint or Prettier) |
| Validation after changes | pnpm check (runs biome check && tsc --noEmit) |
| Unit tests | pnpm test:unit (node:test) |
| E2E tests | pnpm test:e2e (Cucumber + Gherkin, needs Postgres) |
| Architecture validation | pnpm deps:validate (dependency-cruiser) |
| DB migrations | pnpm db:migrate (DBMate) |
Always run pnpm check after making changes. If it fails on formatting, import order or other safe fixes, run pnpm check:fix, then pnpm check again.
Path-specific rules
Detailed rules live in .agents/rules/, one file per area. The paths list in each file's
frontmatter says which files it covers: read the matching rule before changing those files.
Claude Code loads them automatically through the .claude/rules symlink.
| Rule | Covers |
clean-architecture.md | Layer responsibilities, services, when to split a file |
cqrs.md | Buses, action creators, handlers, middlewares, calls from routes/resolvers |
database.md | Repositories, mappers, SQL, migrations |
api.md | REST routes, TypeBox schemas, GraphQL resolvers, server setup |
modules.md | Module structure, dependency injection, adding a module |
testing.md | Unit, E2E and load tests |
infra.md | Environment config, Docker, CI, release, dependencies, git hooks |
Architecture
Layer boundaries
The dependency flow is strictly inward: Route/Resolver → Handler → (Service) → Domain + Repository.
The domain is pure and never calls repositories; see clean-architecture.md for what each layer does.
The folders and what each file holds: README.
Handlers get repositories through DI and use them only through their port interfaces: from
src/shared/db/ or database/ they import nothing but port files (*.port.ts), never an
adapter or the DB client. Repositories never import handlers or services, the domain never imports
request schemas (*.schema.ts), and src/shared never imports a module. pnpm deps:validate
enforces all of this. SQL belongs in repository files only.
Module independence
Modules do not import from each other, except another module's domain events
(domain/*.events.ts), which are the cross-module contract; pnpm deps:validate enforces
this. Everything else goes through the CQRS buses:
- Commands/queries for request-response
- Events for fire-and-forget notifications
Coding conventions
- Biome enforces formatting and most style rules (quotes, indentation, kebab-case file names,
no
enum(use aconstobject with a derived type, e.g.UserRoles), noanyoutside tests, noconsole(use the injectedlogger)): rely onpnpm checkinstead of restating them - Code, comments, identifiers, log and error messages are in English
- Application code (
src/,tests/) readsprocess.envonly insrc/config/env.ts, which validates it; everything else importsenvfrom#src/config/index.ts. The one exception issrc/instrumentation.ts, which runs via--importbefore the config is loaded - TypeScript:
strict: true; always include the.tsextension in imports (ESM); preferimport type { Foo } from './bar.ts' - Path aliases:
#src/*maps to./src/*,#tests/*maps to./tests/*(Node subpath imports inpackage.json, nottsconfig.json). A file in a parent folder is imported through an alias, never with../(BiomenoRestrictedImportsenforces it);./is for the same folder and below
Factory functions
No classes except errors: everything else is a factory function that returns an object. The
Cucumber World in tests/support/ is a class because Cucumber requires it.
- Name: the camelCase key Awilix derives from the file name (
create-user.handler.ts→createUserHandler,user.repository.ts→userRepository), so searching for a dependency finds its factory. Nomakeorcreateprefix. Factories outside the container are named after what they produce (requestBus,tracingMiddleware). - Parameter: one destructured
Dependenciesobject, or none when the factory needs nothing (e.g. a pure domain). Factories outside the container take what they need (requestBus(label),tracingMiddleware(bus)). - Return type: inferred. Annotate it only when the factory implements an interface, so
TypeScript checks the implementation against it: a repository port
(
userRepository(...): UserRepository),Mapper<...>, a bus type. - Exports: in a file that default-exports a factory, every function lives inside it, public ones on the
returned object and private helpers as inner closures. Besides the default-exported factory,
such a file exports only types, schemas and, in handler files, the action creator: never
standalone functions. Stateless helpers in
src/shared/(e.g.with-timeout.ts) are plain exported functions.
Exceptions
- Exceptions carry a transport-neutral
code(ErrorCodeinsrc/shared/exceptions/), never an HTTP status: each transport maps it at its edge (see the API rule, Errors), so handlers serve every transport alike - Use the built-in exceptions in
src/shared/exceptions/exceptions.ts. The error that caused one goes incause(the nativeErroroption);ArgumentInvalidExceptiontakes the invalid fields (subErrors) instead - Domain errors extend one of them and may set a stable
reasonfor clients (e.g.UserAlreadyExistsError→USER_ALREADY_EXISTS) - Always include a descriptive message:
throw new NotFoundException('User with id X not found')
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.

