Menu

Structuring a NestJS CRM: Modules, Roles and Record-Level Permissions
📰

Structuring a NestJS CRM: Modules, Roles and Record-Level Permissions

DEV Community: nestjs·Tấn Phát Digital·about 7 hours ago
#XsRXydTZ
#devtonestjs#devto#dev#user#permissions
Long article (1602 words) — no AI summary yet.
Reading 0:00
15s threshold

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.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.