Kest

Search

Search the documentation

Kest

Migrating from NestJS

Every NestJS concept next to its Kest equivalent, what changes, and what to watch for.

If you know NestJS you already know most of Kest: the same modules, providers, controllers, guards, pipes, interceptors and filters, in the same order. What changes is the language (Kotlin or Java instead of TypeScript) and how the wiring happens: at build time by a processor, not at run time by reflection.

Concept by concept

NestJSKestNotes
@Module({ imports, providers, controllers, exports })@Module(imports = [...], providers = [...], controllers = [...], exports = [...])A wiring mistake fails the build with a message naming the class
@Injectable()@InjectableConstructor injection only; by inject() for circular references
@Controller('users'), @Get(':id')@Controller("/users"), @Get("/{id}")Path variables use {id}
@Param('id'), @Query('q'), @Body(), @Body('name'), @Headers('x')@Param, @Query, @Body, @Body("name"), @HeaderParameters bind by name; a whole object works for @Query and @Body
class-validator DTOconstraint annotations on a data class@NotBlank, @Email, @Pattern, groups, custom constraints; message = on each
class-transformer@Exclude, @Expose, @Transform, ClassSerializerInterceptorJackson under the hood
ValidationPipeValidationPipeRegistered once with usePipes
Guards, @UseGuards, @RolesGuard, @UseGuards, @Roles, @Authenticated, @Public@Authenticated needs no global guard
Interceptors (RxJS)Interceptor with next.handle()Plain code: before, call, after. No Observable
Exception filters, @CatchExceptionFilter, and @ControllerAdvice with @ExceptionHandlerAdvice is the Spring-style single class for all controllers
MiddlewareMiddleware, useMiddleware(..., forRoutes)
ConfigModule, ConfigService.get<T>()ConfigModule, config.get<T>(), getOrThrow<T>(), registerAs, forFeature.env precedence matches NestJS
forRootAsync({ inject, useFactory })forRootAsync { config: ConfigService -> ... }Available on ORM, JWT, cache, queue, mailer, throttler, metrics, tracing
TypeOrmModule, @InjectRepository(User)OrmModule, @InjectRepository(User::class, "main")Repository<T> for SQL, MongoRepository<T> for MongoDB
@Entity, @Column, @OneToManythe same namesPlus select/insert/update flags, transformers, simple-array, simple-json, jsonb
@nestjs/jwt, social loginJwtModule, Authenticators (JWT, API key, Basic), OAuth2ProviderStrategies are small functions
@nestjs/schedule@Cron, @Interval, @Timeout
@nestjs/bullmqqueue and queue-redis
@nestjs/event-emitter@OnEvent
@nestjs/microservicesmicroservices-* packagesSame patterns: @MessagePattern, @EventPattern
@nestjs/graphql (code-first)graphql (schema-first)You write the SDL; @Resolver, @Query, @Mutation, @ResolveField
@nestjs/swaggerapi-docsReference site with sandbox, OpenAPI 3 export
@nestjs/terminushealth
Test.createTestingModuleTesting.createModule<AppModule> { ... }Real servers: startHttp returns a client

What is different

  • No decorators-as-metadata at run time. Annotations are read by a Kotlin Symbol Processing (KSP) step. The result is plain generated code you can read under build/generated.
  • No async/await, no RxJS. Handlers run on virtual threads, so write blocking code that reads top to bottom. See the concurrency model.
  • Method decorators need open classes. @Async, @Retry, @Cacheable, @Transactional and your own @MethodAspect annotations work through a generated subclass.
  • Entities are data classes. Updates use copy(); repositories return new objects.
  • Schema-first GraphQL only. Code-first, federation, scalars and directives are listed in What is not built yet.

A typical controller, side by side

// NestJS
@Controller('orders')
export class OrdersController {
  constructor(private readonly orders: OrdersService) {}
  @Post() @UseGuards(JwtAuthGuard)
  create(@Body() dto: CreateOrderDto) { return this.orders.create(dto); }
}
// Kest
@Controller("/orders") @Authenticated
class OrdersController(private val orders: OrdersService) {
    @Post fun create(@Body dto: CreateOrderDto) = orders.create(dto)
}

Steps

  1. Create the project with kest new, or add the packages you need (see the package catalogue).
  2. Port modules one by one: the structure maps directly.
  3. Port DTOs to data classes with constraint annotations.
  4. Replace RxJS pipelines in interceptors and sagas with plain code or Stream<T>.
  5. Move tests to Testing.createModule; they run against real servers.