Skip to the content.

nestjs-mtenant

npm version License: MIT

NestJS module for multi-tenancy with deep integration into Sequelize and TypeORM. Tenant context is propagated automatically through every request scope using nestjs-cls, so your models and entities are scoped to the correct tenant without any per-query boilerplate.

Key Features

Compatibility

nestjs-mtenant NestJS Node.js Sequelize TypeORM
1.x 11.x >= 20 6.x 0.3.x

Documentation

Quick Example

// 1. Decorate your model/entity
@MTEntity()
@Table({})
export class User extends Model<User> {
  id: string;
  tenant: string;
  username: string;
}

// 2. Register the module
@Module({
  imports: [
    MTModule.forRoot({ for: [User] }),
  ],
})
export class AppModule {}

// 3. All queries are automatically scoped — no changes needed in services
const users = await User.findAll(); // WHERE tenant = 'acme' (from X-Tenant-ID header)

Repository

Source code and issue tracker: github.com/AlexanderC/nestjs-mtenant