agentleFS
ingsergiovtingsergiovt/claude-code-hexagonal-kit/CLAUDE.md

claude-code-hexagonal-kit

CLAUDE.md1 starsChanged 36 days agoMITView on GitHub

Next.js (App Router) full-stack app with hexagonal architecture, SOLID and unit tests. No database: an in-memory adapter keeps pnpm dev zero-setup. No auth (out of scope for the demo). Example module: orders (place / cancel / list orders). Business rules live in the domain. The UI validates input (Zod) and translates; adapters store and fetch. For domain or application changes: write or adjust the test first, see it fail, then write the code, then pnpm check. Use the skills: new-module,…

  • Reads credentials

The file

We split this CLAUDE.md into the rules it gives an agent

8 rules. About 0 are common, 1 is distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Only src/composition imports infrastructure.

    line 35
  2. Very specific:

    Use the skills: new-module, new-use-case, new-adapter, connect-ui.

    line 45
  3. Very specific:

    Never weaken or bypass the guardrails: do not edit .dependency-cruiser.cjs, .claude/hooks/ or .claude/settings.json, and do not use …

    line 57
  4. Very specific:

    Never put business rules in src/app or in adapters.

    line 58
  5. Very specific:

    Never call Date.now(), new Date() or Math.random() in domain or application code.

    line 59
  6. Very specific:

    Never leave console.log or commented-out code.

    line 60
  7. Distinctive:

    Never skip validation of external input.

    line 61
  8. Very specific:

    Stop: if src/ changed, typecheck and tests must pass or you are sent back to fix them.

    line 69

≈ “Common” is an estimate: at least 1 in 5 of the 26,980 CLAUDE.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
CLAUDE.md

Claude Code Hexagonal Kit

Next.js (App Router) full-stack app with hexagonal architecture, SOLID and unit tests. No database: an in-memory adapter keeps pnpm dev zero-setup. No auth (out of scope for the demo).

@AGENTS.md

Commands

  • pnpm dev / pnpm build - run / build the app
  • pnpm test - Vitest (domain, application, infrastructure, hooks)
  • pnpm arch - dependency-cruiser layer rules (messages explain the fix)
  • pnpm typecheck, pnpm lint
  • pnpm check - lint + typecheck + test + arch. Run it before saying you are done.

Architecture map

src/app/            Next.js pages + server actions (driving adapter). Zod validation lives here.
src/modules/<name>/
  domain/           entities, value objects, domain errors, ports. Pure TypeScript.
  application/      use cases: make<UseCase>(deps) factories. Depend on domain only.
  infrastructure/   adapters implementing ports (in-memory repo, clock, id generator)
  index.ts          module public API (never exports infrastructure)
src/composition/    composition root: the ONLY place adapters are wired into use cases
src/shared/         tiny shared kernel, only if truly needed (does not exist yet)

Example module: orders (place / cancel / list orders).

Layer rules (enforced by .dependency-cruiser.cjs)

  1. domain imports nothing from other layers and no npm packages. Time and ids come in through ports (Clock, IdGenerator).
  2. application imports only domain (and shared). No next, react, zod, adapters.
  3. infrastructure may import domain; never app or composition.
  4. Only src/composition imports infrastructure.
  5. src/app imports modules only via @/modules/<name> (index.ts) or @/composition/<name>.
  6. A module never imports another module's internals, only its index.ts.
  7. No circular dependencies.

Business rules live in the domain. The UI validates input (Zod) and translates; adapters store and fetch.

Workflow

For domain or application changes: write or adjust the test first, see it fail, then write the code, then pnpm check. Use the skills: new-module, new-use-case, new-adapter, connect-ui. Use the architecture-reviewer subagent on a finished diff and test-writer for missing tests.

Conventions

  • Files kebab-case; one use case per file; tests beside the code (order.ts -> order.test.ts).
  • Types/classes PascalCase, functions camelCase. Ports are interfaces named for the role (OrderRepository); adapters name the technology (InMemoryOrderRepository).
  • Money is integer cents. Domain objects are immutable; operations return new objects.
  • Domain failures are DomainError subclasses with a code; the UI turns them into friendly messages.
  • Inside a module use relative imports; elsewhere use @/.

Never

  • Never weaken or bypass the guardrails: do not edit .dependency-cruiser.cjs, .claude/hooks/** or .claude/settings.json, and do not use eslint-disable / @ts-ignore to get around a rule. If a rule blocks you, explain to the user what you need.
  • Never put business rules in src/app or in adapters.
  • Never call Date.now(), new Date() or Math.random() in domain or application code.
  • Never leave console.log or commented-out code. Never commit secrets or .env files.
  • Never skip validation of external input.

Hooks

Rules are enforced, not suggested (.claude/settings.json):

  • PostToolUse on edits to src/**/*.ts(x): runs pnpm arch; a violation comes back to you with the rule and the fix.
  • PreToolUse: edits to the guardrail files above are blocked.
  • Stop: if src/ changed, typecheck and tests must pass or you are sent back to fix them.

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.