dryvPacks

@dryv/nestjsv0.9.0

NestJS feature controllers, services and modules for HTTP operations.

NestJS Backend AdapterBackendInjectPublished 7 days ago2 downloads

dryv pack add @dryv/nestjs

Injects NestJS 12 modules into a project, following the NestJS module structure. The pack selects Bun for package-manager actions; Bun runs the generated application and supplies the Node compatibility APIs used by the Nest ecosystem.

text
<app slot>/app.module.ts                  managed: imports the group modules (and DatabaseModule)
<app slot>/database/database.module.ts    scaffold: yours (driver, connection, migrations)
<destination>/<group>/<group>.module.ts   managed: imports the group's feature modules
<destination>/<group>/features/<feature>/
  <feature>.controller.ts                 managed: routes each `http` facet, calls the service contract
  <feature>.service.ts                    managed: abstract service contract
  <feature>.module.ts                     managed: binds the contract to your implementation
<destination>/common/server/              shared cookie decorator and schema-validation pipe

The controller routes each http facet (GET /users/{id} → @Get("/users/:id")) and calls the abstract <Group><Feature>Service. The feature module binds that token to the project's implementation and registers its use cases:

ts
providers: [
  { provide: BookingsService, useClass: BookingsServiceImpl satisfies Type<BookingsService> },
  CreateBookingUseCase,
  FindBookingsUseCase,
],

satisfies Type<…> makes type checking fail when the implementation drifts from the contract. AppModule imports DatabaseModule only when the feature modules use generated entities.

It generates no DTOs, entities, implementations or use cases. It imports them through slots the project binds:

yaml
packs:
  types: { source: …/inject/types/typescript }
  dtos:
    {
      source: …/class-validator,
      bind: { property.enum.types: …, property.types: … },
    }
  entities:
    { source: …/typeorm, bind: { property.enum.types: …, property.types: … } }
  use-cases: { source: …/your-use-cases-pack } # ServiceImpl per feature + use case per operation
  server:
    source: …/inject/backend/nestjs
    destination: { $ref: "#/destinations/modules" } # e.g. src/modules
    destinations:
      app: { $ref: "#/destinations/app" } # e.g. src (app.module.ts, database/)
    bind:
      schema.validation: { $ref: "#/packs/dtos" } # or zod / joi
      schema.persistence: { $ref: "#/packs/entities" } # optional
      operation.implementation: { $ref: "#/packs/use-cases" }
      operation.usecase: { $ref: "#/packs/use-cases" }
      module.provider: { $ref: "#/packs/use-cases" } # optional feature-level provider classes
Bound validation packParameters and resultsValidation
class-validatorDTO classesNest's global ValidationPipe
zodz.infer<typeof XSchema>generated SchemaValidationPipe(XSchema)
joiRecord<string, unknown>generated SchemaValidationPipe(XSchema)

When persistence is bound, the feature module registers the entities its operations use with TypeOrmModule.forFeature([...]). The pipe duck-types zod and Joi, so the output compiles with whichever library the project uses.

Test: bun scripts/test-pack.ts inject/backend/nestjs renders the shared IR twice (over class-validator + TypeORM, and over zod) with a test implementation pack, typechecks both against the real framework, boots them, sends valid and invalid requests, and boots the full AppModule → group → feature assembly.

Use it

The executable Usage fixture shows every activation and binding.

Slots

  • needs schema.validation, operation.implementation, operation.usecase (required)
  • needs schema.persistence (optional)
  • needs module.provider (optional; registers provider classes used by the feature's operations)
  • provides operation.server (the feature module)

Output slots

  • app: app.module.ts and the database/ scaffold.

Generated tests

Vitest specs, regenerated with the contracts:

  • <feature>.controller.e2e.spec.ts: each operation's route, input binding (path, query, headers, cookies, body), contract status code and response passthrough, plus rejection of an invalid body, with the project implementation mocked. Valid payloads come from the bound schema.examples pack; without one, body checks are todo.
  • app.e2e.spec.ts (app slot): the assembled AppModule boots and serves every contract route (no 404).

vitest.config.ts is scaffolded in the app slot; run vitest run --root <app slot>. With pnpm, approve esbuild's build script (pnpm approve-builds), which Vitest needs.

Layout. Each feature is written under <group>/features/<feature>/ (module, controller, service, use cases), so business logic and HTTP code stay apart from the schema/ folders other packs write.

Layout. The service contract and its implementation share one file (<feature>.service.ts): the abstract contract on top, <Feature>ServiceImpl below delegating to the use cases. operation.implementation is optional; bind it only to replace the generated implementation. Feature barrels (index.ts) are no longer generated. Specs go to the test slot (test-app for the application spec) and the vitest config to the package slot; map them with destinations.

Named calendar-date HTTP parameters are strings validated by CalendarDatePipe. The pipe checks the calendar day and preserves the original YYYY-MM-DD value, including across server timezones. Array response signatures retain their element types. Each HTTP operation also gets a named immutable route constant containing its canonical operation id, method and path.

Groups/features are semantic ownership; output paths, repositories and use-case placement belong to pack layout. Projects can choose an explicit private pack for a different submodule layout without introducing new contract families. Event/listener/workflow and transition contracts already carry semantic intent. Durable outbox dispatch, retries and listener idempotency require a separate runtime implementation; folder generation is not proof of delivery.