Files
lcbp3/.agents/skills/nestjs-best-practices/rules/arch-feature-modules.md
admin ef16817f38
All checks were successful
Build and Deploy / deploy (push) Successful in 4m44s
260223:1415 20260223 nextJS & nestJS Best pratices
2026-02-23 14:15:06 +07:00

2.3 KiB

title, impact, impactDescription, tags
title impact impactDescription tags
Organize by Feature Modules CRITICAL 3-5x faster onboarding and development architecture, modules, organization

Organize by Feature Modules

Organize your application into feature modules that encapsulate related functionality. Each feature module should be self-contained with its own controllers, services, entities, and DTOs. Avoid organizing by technical layer (all controllers together, all services together). This enables 3-5x faster onboarding and feature development.

Incorrect (technical layer organization):

// Technical layer organization (anti-pattern)
src/
├── controllers/
   ├── users.controller.ts
   ├── orders.controller.ts
   └── products.controller.ts
├── services/
   ├── users.service.ts
   ├── orders.service.ts
   └── products.service.ts
├── entities/
   ├── user.entity.ts
   ├── order.entity.ts
   └── product.entity.ts
└── app.module.ts  // Imports everything directly

Correct (feature module organization):

// Feature module organization
src/
├── users/
   ├── dto/
      ├── create-user.dto.ts
      └── update-user.dto.ts
   ├── entities/
      └── user.entity.ts
   ├── users.controller.ts
   ├── users.service.ts
   ├── users.repository.ts
   └── users.module.ts
├── orders/
   ├── dto/
   ├── entities/
   ├── orders.controller.ts
   ├── orders.service.ts
   └── orders.module.ts
├── shared/
   ├── guards/
   ├── interceptors/
   ├── filters/
   └── shared.module.ts
└── app.module.ts

// users.module.ts
@Module({
  imports: [TypeOrmModule.forFeature([User])],
  controllers: [UsersController],
  providers: [UsersService, UsersRepository],
  exports: [UsersService], // Only export what others need
})
export class UsersModule {}

// app.module.ts
@Module({
  imports: [
    ConfigModule.forRoot(),
    TypeOrmModule.forRoot(),
    UsersModule,
    OrdersModule,
    SharedModule,
  ],
})
export class AppModule {}

Reference: NestJS Modules