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
In this repository6 other files it gives its agents.
- angular-only/CLAUDE.mdCLAUDE.md
- java-react/CLAUDE.mdCLAUDE.md
- nextjs/CLAUDE.mdCLAUDE.md
- python-fastapi-react/CLAUDE.mdCLAUDE.md
- react-only/CLAUDE.mdCLAUDE.md
- vue-only/CLAUDE.mdCLAUDE.md
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
- Very specific: line 15
Tenant isolation: every repository query MUST filter by organizationId.
- Very specific: line 17
Public IDs only: use publicId (UUID) in all URLs and API responses.
- Distinctive: line 19
Migration immutability: never edit an existing TypeORM migration.
- Very specific: line 33
Always use class-validator + class-transformer.
- Very specific: line 37
Always use @Injectable() services injected via constructor.
- Very specific: line 38
Always register a global ValidationPipe with whitelist: true and forbidNonWhitelisted: true.
- Very specific: line 39
Always use @UseGuards(JwtAuthGuard) on protected routes.
- Very specific: line 40
Always map responses in a TransformInterceptor or dedicated mapper — never in controllers.
- Very specific: line 43
All business exceptions extend DomainException with an ErrorCode enum.
- Very specific: line 48
Always use typed Repository<Entity> (TypeORM) or the Prisma generated client.
- Very specific: line 66
Always handle isLoading and isError in data-fetching components.
- Distinctive: line 90
Every repository integration test must verify organization isolation (cross-tenant data must not be accessible).
- Very specific: line 114
If stuck after 2 failed attempts on the same problem: stop and tell the user to run /model claude-opus-4-8.
- Distinctive: line 115
Never suggest haiku for tasks involving entities, migrations, security, or multi-tenancy.
- Very specific: line 134
Module imports: if TasksService needs ProjectsService, import ProjectsModule in TasksModule — never import the service file directly across …
- Very specific: line 135
TypeORM migrations: run npm run migration:run after every new migration.
≈ “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.
Files
[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 internalid(integer). - No secrets in code: tokens, passwords, keys always via
ConfigService. Neverprocess.envin 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 throughexports; 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, andXxxResponseDtofor 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. Nevernew Service(). - Always register a global
ValidationPipewithwhitelist: trueandforbidNonWhitelisted: true. - Always use
@UseGuards(JwtAuthGuard)on protected routes. Use@Roles()+RolesGuardfor authorization. - Always map responses in a
TransformInterceptoror dedicated mapper — never in controllers.
Exceptions
- All business exceptions extend
DomainExceptionwith anErrorCodeenum. - 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 — neverany.- Fetch logic in
/apionly — never inside a component or hook body beyond calling API functions. - shadcn/ui components everywhere — no raw HTML elements for interactive UI.
- Always handle
isLoadingandisErrorin data-fetching components. - Global state →
/store. Server state → TanStack Query only.
Security Rules
Validation
- Backend: global
ValidationPipe+class-validatoron 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]. Neverorigin: trueor 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
| Situation | Action |
| Change < 10 lines | Targeted diff only — never rewrite the full file |
| New DB change needed | New TypeORM migration — never edit existing migration |
| New file | Only if no existing file can be extended |
Cost Optimization
Model switching is manual. Suggest /model when the task warrants it:
| Task type | Suggestion |
| Docs, renaming, simple syntax fixes | Suggest /model claude-haiku-4-5 |
| Feature dev, bug fix, architecture (default) | Stay on claude-sonnet-4-6 |
| Blocked after 2 attempts, security review | Suggest /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
| Command | Purpose |
/gov-check | Audit current file against governance rules |
/security-review | Security 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:
ValidationPipeis registered once inmain.ts. Do not add per-route validation pipes unless transforming groups. - Module imports: if
TasksServiceneedsProjectsService, importProjectsModuleinTasksModule— never import the service file directly across modules. - TypeORM migrations: run
npm run migration:runafter every new migration.synchronize: trueis 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.
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.

