Files
stack/packages/mosaic/framework/skills/nestjs-best-practices/rules/arch-feature-modules.md
fargo 1a822493ba format: apply repo prettier (3.8.1) to the folded skills tree
963 markdown files reformatted with the repository's pinned prettier so
pnpm format:check covers the folded tree like every other repo file.

The formatter's embedded-language pass also normalized code fences
(TS semicolons, closed HTML tags in examples, lowercased CSS hex colors,
one renumbered list that skipped an index). Alphanumeric token deltas vs
the fold commit were audited file-by-file; all are formatter-equivalent
markup normalizations plus the four sanitized skills.
2026-08-19 14:37:17 -05: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