Most CRM projects we take on start the same way: "We need customers, deals, orders… and sales staff should only see their own customers." That last sentence is where things get messy.
After building several custom CRMs for SMEs with NestJS + PostgreSQL, we've settled on a structure that keeps permissions out of the controllers and makes "who can see what" easy to change later. Here's the setup.
What we'll cover:
A module layout that scales past 10 modules
Roles vs permissions (and why we store permissions, not roles, in checks)
A @RequirePermissions() decorator + guard
Record-level scoping: "own", "team", "all"
An audit log interceptor
Examples use NestJS 10+, TypeScript and Prisma, but the ideas work with TypeORM too.
1.…