| name | multitenancy-guard |
| description | Enforces tenant and soft-delete query guards for backend changes. |
multitenancy-guard
Use when changing backend data access in apps/server/*.
When to use
- Any MongoDB query changes
- Any list/read/update/delete service/controller change
- Any auth/tenant-scoped endpoint updates
Hard rules
- Apply soft-delete guard consistently (
isDeleted: false) where required by existing patterns.
- Never allow cross-tenant reads/writes in enterprise (
ee/) code paths.
- Keep
users._id as canonical DB user reference; do not use legacy auth provider user.id as foreign key.
- Enterprise code (
ee/): every tenant-scoped MongoDB query must include organization guard.
- Self-hosted (non-
ee/): organization guard is optional for single-tenant deployments.
Execution checklist
- Inspect query filters in changed code paths.
- Verify soft-delete guards are present where expected.
- If editing
ee/ code, verify organization guards are present.
- Confirm serializers are still used for outbound responses.
- Run targeted tests for affected module/package.
Quick verification
- Search for query changes in edited files:
rg -n "find\(|findOne\(|aggregate\(|update|delete|organization|isDeleted" apps/server
- Run scoped tests:
bun run test --filter=@genfeedai/api