Qadam Roadmap
проектdocs/Agents/rules/architecture-vertical-slices.md

NestJS Backend

Обновлён 1 апр. 2026 г., 12:41 · 0 комментариев


title: Organize Code by Feature Using Vertical Slices impact: CRITICAL impactDescription: Dramatically improves discoverability and reduces cross-team conflicts tags: architecture, vertical-slices, organization

Паспорт документа

  • Статус документа: living standard
  • Актуально на: 28 марта 2026 года
  • Владелец: backend/platform-команда
  • Пересмотр: при изменении инженерной практики, CI/CD, архитектурных правил или локального workflow
  • Область применения: внутренние rule/reference-card документы для инженерной команды
  • Связанные документы:

Organize Code by Feature Using Vertical Slices

Impact: CRITICAL

Code is organized by feature/domain, not by technical layer. Each feature in the NestJS backend is a self-contained module. On the frontend, components are colocated with their pages.

Incorrect (traditional layered architecture):

src/
  controllers/
    catalogController.ts
    sellerController.ts
  services/
    catalogService.ts
    sellerService.ts
  repositories/
    catalogRepository.ts
    sellerRepository.ts

This creates problems: changes to one feature require touching files scattered across multiple directories.

Correct (vertical slice architecture):

# NestJS Backend
src/modules/
  catalog/
    catalog.controller.ts
    catalog.service.ts
    catalog.module.ts
    repositories/
      catalog.repository.ts
    dto/
      catalog-filter.dto.ts
      catalog-response.dto.ts
  seller/
    seller.controller.ts
    seller.service.ts
    seller.module.ts
    repositories/
      seller.repository.ts
    dto/
      create-seller.dto.ts

# Next.js Frontend
app/
  item/[slug]/
    page.tsx              # Server Component
    ClientItemView.tsx    # Client Component (interactivity)
  seller/
    items/
      page.tsx
      new/page.tsx
components/
  CourseCard.tsx           # Shared across features
  FilterSidebar.tsx

Each feature module is self-contained with:

  • Controller: HTTP layer (thin, delegates to service)
  • Service: Business logic and orchestration
  • Repository: Data access (Prisma queries)
  • DTOs: Input validation and response shaping
  • Tests: Unit and integration tests for the module