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
| NestJS | Kest | Notes |
|---|---|---|
@Module({ imports, providers, controllers, exports }) | @Module(imports = [...], providers = [...], controllers = [...], exports = [...]) | A wiring mistake fails the build with a message naming the class |
@Injectable() | @Injectable | Constructor 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"), @Header | Parameters bind by name; a whole object works for @Query and @Body |
class-validator DTO | constraint annotations on a data class | @NotBlank, @Email, @Pattern, groups, custom constraints; message = on each |
class-transformer | @Exclude, @Expose, @Transform, ClassSerializerInterceptor | Jackson under the hood |
ValidationPipe | ValidationPipe | Registered once with usePipes |
Guards, @UseGuards, @Roles | Guard, @UseGuards, @Roles, @Authenticated, @Public | @Authenticated needs no global guard |
| Interceptors (RxJS) | Interceptor with next.handle() | Plain code: before, call, after. No Observable |
Exception filters, @Catch | ExceptionFilter, and @ControllerAdvice with @ExceptionHandler | Advice is the Spring-style single class for all controllers |
| Middleware | Middleware, 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, @OneToMany | the same names | Plus select/insert/update flags, transformers, simple-array, simple-json, jsonb |
@nestjs/jwt, social login | JwtModule, Authenticators (JWT, API key, Basic), OAuth2Provider | Strategies are small functions |
@nestjs/schedule | @Cron, @Interval, @Timeout | |
@nestjs/bullmq | queue and queue-redis | |
@nestjs/event-emitter | @OnEvent | |
@nestjs/microservices | microservices-* packages | Same patterns: @MessagePattern, @EventPattern |
@nestjs/graphql (code-first) | graphql (schema-first) | You write the SDL; @Resolver, @Query, @Mutation, @ResolveField |
@nestjs/swagger | api-docs | Reference site with sandbox, OpenAPI 3 export |
@nestjs/terminus | health | |
Test.createTestingModule | Testing.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
openclasses.@Async,@Retry,@Cacheable,@Transactionaland your own@MethodAspectannotations 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
- Create the project with
kest new, or add the packages you need (see the package catalogue). - Port modules one by one: the structure maps directly.
- Port DTOs to data classes with constraint annotations.
- Replace RxJS pipelines in interceptors and sagas with plain code or
Stream<T>. - Move tests to
Testing.createModule; they run against real servers.