Backend Foundation — BE Claude.md
Next module →
Backend Foundation — 01

BE Claude.md
The AI Onboarding Brief.

CLAUDE.md is the single file that transforms a generic AI into a NestJS expert that knows your exact stack, port numbers, folder layout, and rules before it writes a single line of code.

Read time18 min
LevelIntermediate
Quiz3 questions
TrackBackend Foundation
01 — the problem

The AI starts every session knowing nothing about your project.

Without a briefing file, you repeat yourself every session. The AI invents paths that don't exist, uses outdated libraries, and ignores your naming conventions.

Imagine hiring a senior backend developer. On day one you wouldn't say "build the orders feature" and walk away. You'd give them a quick onboarding brief — what the project is, how the code is organized, what commands to run, what rules to never break. CLAUDE.md is exactly that onboarding brief, written once, read automatically at the start of every session.

Without CLAUDE.md, the AI guesses your stack. With it, the AI knows your NestJS version, your MongoDB port, your path aliases, and your test commands before you type a single prompt.

Before
No CLAUDE.md
Copy-paste stack rules into every chat. AI uses relative paths, wrong exception classes, and forgets your conventions by the next session.
After
CLAUDE.md in repo root
AI reads one file at session start. Knows the stack, folder layout, Docker ports, and mandatory rules without you saying a word.
02 — what goes in it

Five sections that turn a generic AI into a NestJS specialist.

Every backend CLAUDE.md needs the same five building blocks, structured so the AI reads it fast and retains everything.

SectionWhat it containsWhy it matters
Project & StackNestJS version, MongoDB port, Docker Compose summaryPrevents invented connection strings and wrong library imports
Cheat-sheet commandsnpm run start:dev, npm run test, npm run lintAI runs correct commands without asking you every time
Folder blueprintModule scaffold, DTO location, schema location, spec co-location ruleEvery generated module looks identical to the existing codebase
Path aliases@common/*, @config/* — relative paths forbiddenEliminates ../../.. import chains across module boundaries
Mandatory rulesNever touch unrelated modules, update docs/db-schema.md on schema changes, link to skill filesHard guardrails that override the AI's default behaviour
03 — tiffinconnect example

How TiffinConnect wired its CLAUDE.md.

TiffinConnect is a NestJS + MongoDB subscription marketplace for tiffin (meal box) deliveries. Here is the exact structure baked into its CLAUDE.md.

markdown
## Project
TiffinConnect — subscription marketplace API
Stack: NestJS 10, MongoDB (port 27018), Docker Compose

## Commands
| Task           | Command                  |
|----------------|--------------------------|
| Run dev        | npm run start:dev        |
| Run tests      | npm run test             |
| Lint + fix     | npm run lint             |
| Build          | npm run build            |

## Module scaffold — every feature follows this layout
src/[feature]/
  [feature].module.ts
  [feature].controller.ts   ← route handlers only, no logic
  [feature].service.ts      ← all business logic here
  dto/
    create-[feature].dto.ts
  schemas/
    [feature].schema.ts
  [feature].service.spec.ts ← co-located with service

## Path aliases (tsconfig.paths)
@common/*  → src/common/*
@config/*  → src/config/*
NEVER use ../../ across module boundaries.

## Mandatory rules
- Never modify code outside the feature you were asked to build
- Update docs/db-schema.md whenever a Mongoose schema changes
- Read skills/error-handling.SKILL.md before throwing any error
- Read skills/unit-test.SKILL.md before writing any spec file
- MongoDB runs on port 27018 (not the default 27017)

## Domain docs — load on demand only
| File                       | Read before working on           |
|----------------------------|----------------------------------|
| docs/order-lifecycle.md    | Orders, subscriptions, planner   |
| docs/business-rules.md     | Any business logic               |
| docs/db-schema.md          | Any schema or query work         |
| docs/api-contracts.md      | Any endpoint work                |

The /init shortcut: For an existing project, run /init in Claude Code. It reads your codebase, detects the stack, and generates a starter CLAUDE.md automatically. Edit it to add your guardrails and it is production-ready within minutes.

04 — how it differs from generic

Backend CLAUDE.md vs a generic one.

A generic CLAUDE.md tells the AI what project it is on. A backend CLAUDE.md gives it operational precision — specific ports, module scaffolds, and skill file triggers.

Generic
Vague stack reference
"This is a Node.js project using MongoDB." — AI still guesses connection strings, ports, and folder layout.
Backend-specific
Precision on every detail
MongoDB on port 27018 via Docker, @common/* alias, spec co-located with service, skill file triggered before error throw. Zero guessing.

The key difference is trigger wiring. A generic file describes the project. A backend CLAUDE.md instructs the AI: "read this skill file before doing X." That wiring turns passive documentation into active guardrails that fire at the right moment every session.

Do not paste 500 lines of business rules into CLAUDE.md. Keep it to stack facts, commands, scaffold rules, and a reference table pointing to docs/ files. Business logic lives in the docs folder, not here.

05 — do's and don'ts

Rules for keeping CLAUDE.md effective over time.

A stale or bloated CLAUDE.md is worse than none — it feeds the AI incorrect rules and wastes context tokens.

Do
Keep it brief and scannable
Use markdown tables and bullet lists. The AI reads structure faster than prose.
Do
Update it when the stack evolves
New global error handler? New library version? Update the briefing file immediately — treat it like a code change.
Do
State what NOT to do
AIs are eager to help. "Never use ../../ across modules" is as important as any positive rule.
Don't
Explain the business pitch
The AI needs "subscription marketplace API", not why meal delivery will disrupt the food industry.
Don't
Paste code snippets
Show the structural pattern, never the full implementation. Implementations live in skill files.
Don't
Use vague rules
"Write clean code" is meaningless. "Run npm run lint before completing any task" is a guardrail.
Check your understanding
1. TiffinConnect's MongoDB runs on port 27018. Where in the project should this be documented so the AI never invents the wrong connection string?
Correct.Not quite — the correct answer is highlighted above.
2. Which section of a backend CLAUDE.md contains trigger wiring like "Read skills/error-handling.SKILL.md before throwing any error"?
Correct.Not quite — the correct answer is highlighted above.
3. You have an existing NestJS project with no CLAUDE.md. What is the fastest way to generate a starter one?
Correct.Not quite — the correct answer is highlighted above.