agentleFS
datallmhubdatallmhub/claude-governance/nestjs-react/CLAUDE.md

claude-governance / nestjs-react

CLAUDE.md35 starsChanged 5 months agoMITView on GitHub

Multi-tenant SaaS — NestJS 10 / React 18. Each organization is strictly isolated at the data level. Developer level: see dev-level.md. Violations here are bugs, not style issues. Architecture - controller → service → repository. No layer skipping. - One feature per NestJS module (TasksModule, ProjectsModule). Export services only through exports; import modules, never inject across module boundaries. - Controllers may: validate DTOs, extract auth context, call services. - Controllers must not: access repositories, implement business rules, map entities to…

  • Reads credentials

The file

Show its rules and text

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

16 rules. About 0 are common, 3 are distinctive, and 13 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 13

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Tenant isolation: every repository query MUST filter by organizationId.

    line 15
  2. Very specific:

    Public IDs only: use publicId (UUID) in all URLs and API responses.

    line 17
  3. Distinctive:

    Migration immutability: never edit an existing TypeORM migration.

    line 19
  4. Very specific:

    Always use class-validator + class-transformer.

    line 33
  5. Very specific:

    Always use @Injectable() services injected via constructor.

    line 37
  6. Very specific:

    Always register a global ValidationPipe with whitelist: true and forbidNonWhitelisted: true.

    line 38
  7. Very specific:

    Always use @UseGuards(JwtAuthGuard) on protected routes.

    line 39
  8. Very specific:

    Always map responses in a TransformInterceptor or dedicated mapper — never in controllers.

    line 40
  9. Very specific:

    All business exceptions extend DomainException with an ErrorCode enum.

    line 43
  10. Very specific:

    Always use typed Repository<Entity> (TypeORM) or the Prisma generated client.

    line 48
  11. Very specific:

    Always handle isLoading and isError in data-fetching components.

    line 66
  12. Distinctive:

    Every repository integration test must verify organization isolation (cross-tenant data must not be accessible).

    line 90
  13. Very specific:

    If stuck after 2 failed attempts on the same problem: stop and tell the user to run /model claude-opus-4-8.

    line 114
  14. Distinctive:

    Never suggest haiku for tasks involving entities, migrations, security, or multi-tenancy.

    line 115
  15. Very specific:

    Module imports: if TasksService needs ProjectsService, import ProjectsModule in TasksModule — never import the service file directly across …

    line 134
  16. Very specific:

    TypeORM migrations: run npm run migration:run after every new migration.

    line 135

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 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

[your-project] — Claude Code Governance

Project Context

Multi-tenant SaaS — NestJS 10 / React 18. Each organization is strictly isolated at the data level. Developer level: see dev-level.md.


CRITICAL — Non-negotiable

Violations here are bugs, not style issues.

  • Tenant isolation: every repository query MUST filter by organizationId. Never query by entity ID alone.
  • organizationId source: extract from JWT claims via @CurrentUser() decorator only. Never from request body, path variable, or query parameter.
  • Public IDs only: use publicId (UUID) in all URLs and API responses. Never expose internal id (integer).
  • No secrets in code: tokens, passwords, keys always via ConfigService. Never process.env in services or controllers.
  • Migration immutability: never edit an existing TypeORM migration. Always create a new timestamped script.

Backend Rules

Architecture

  • controller → service → repository. No layer skipping.
  • One feature per NestJS module (TasksModule, ProjectsModule). Export services only through exports; import modules, never inject across module boundaries.
  • Controllers may: validate DTOs, extract auth context, call services.
  • Controllers must not: access repositories, implement business rules, map entities to responses.

DTOs & validation

  • Separate CreateXxxDto, UpdateXxxDto, and XxxResponseDto for every endpoint.
  • Always use class-validator + class-transformer. Never use raw @Body() without a typed DTO.
  • Entities never leave the persistence layer — services expose DTOs only.

NestJS patterns

  • Always use @Injectable() services injected via constructor. Never new Service().
  • Always register a global ValidationPipe with whitelist: true and forbidNonWhitelisted: true.
  • Always use @UseGuards(JwtAuthGuard) on protected routes. Use @Roles() + RolesGuard for authorization.
  • Always map responses in a TransformInterceptor or dedicated mapper — never in controllers.

Exceptions

  • All business exceptions extend DomainException with an ErrorCode enum.
  • Handled exclusively in AllExceptionsFilter (@Catch()).

Data access

  • Collection endpoints must return paginated results (PaginatedResponseDto<T>). Never unbounded arrays.
  • Always use typed Repository<Entity> (TypeORM) or the Prisma generated client. Never raw SQL without parameterization.

Correct repository signature example

findByProjectPublicIdAndOrganizationId(
  projectPublicId: string,
  organizationId: number,
  options: IPaginationOptions,
): Promise<Pagination<TaskEntity>>;

Frontend Rules

  • unknown + type guard — never any.
  • Fetch logic in /api only — never inside a component or hook body beyond calling API functions.
  • shadcn/ui components everywhere — no raw HTML elements for interactive UI.
  • Always handle isLoading and isError in data-fetching components.
  • Global state → /store. Server state → TanStack Query only.

Security Rules

Validation

  • Backend: global ValidationPipe + class-validator on all DTOs.
  • Frontend: Zod + react-hook-form at form layer.

Logging — never log email, accessToken, refreshToken, password, user full name.

CORS

  • Dev: [your-dev-origin]. Prod: [your-domain.com]. Never origin: true or wildcard in production.

Testing Rules

  • Service layer: Jest unit tests with mocked repositories.
  • Controller layer: @nestjs/testing + Supertest e2e per module.
  • Repository layer: Testcontainers PostgreSQL integration tests.
  • Every repository integration test must verify organization isolation (cross-tenant data must not be accessible).

Modification Rules

SituationAction
Change < 10 linesTargeted diff only — never rewrite the full file
New DB change neededNew TypeORM migration — never edit existing migration
New fileOnly if no existing file can be extended

Cost Optimization

Model switching is manual. Suggest /model when the task warrants it:

Task typeSuggestion
Docs, renaming, simple syntax fixesSuggest /model claude-haiku-4-5
Feature dev, bug fix, architecture (default)Stay on claude-sonnet-4-6
Blocked after 2 attempts, security reviewSuggest /model claude-opus-4-8
  • If stuck after 2 failed attempts on the same problem: stop and tell the user to run /model claude-opus-4-8.
  • Never suggest haiku for tasks involving entities, migrations, security, or multi-tenancy.

Available Commands

CommandPurpose
/gov-checkAudit current file against governance rules
/security-reviewSecurity checklist on current file
/scaffold <domain>Generate complete CRUD feature (module, DTOs, service, controller, migration)
/new-migration <description>Generate next TypeORM migration script

Known Gotchas

  • JWT expiry: access token = 15 min, refresh token = 7 days. Silent refresh handled by Axios interceptor in /api/client.ts. Do not add manual refresh logic elsewhere.
  • Global pipes: ValidationPipe is registered once in main.ts. Do not add per-route validation pipes unless transforming groups.
  • Module imports: if TasksService needs ProjectsService, import ProjectsModule in TasksModule — never import the service file directly across modules.
  • TypeORM migrations: run npm run migration:run after every new migration. synchronize: true is forbidden in all environments except local scratch DBs.
  • Pagination: task lists can exceed 10,000 rows. Never return unbounded arrays from collection endpoints.
  • CORS: configured for [your-dev-origin] (dev) and [your-domain.com] (prod) only.

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.