Kest

Search

Search the documentation

CLI

The command line

kest new, kest generate and the Gradle tasks, the equivalents of nest new and nest generate.

The kest tool writes the boilerplate you would otherwise copy: a whole project, or one class at a time, wired into the nearest module.

Install

./gradlew :cli:installDist          # in the Kest checkout
packages/cli/build/install/kest/bin/kest list

Inside any generated project the same tool runs as a Gradle task, so nothing needs installing:

./gradlew kest --args="g controller users"

kest new

kest new shop --package com.acme.shop --orm postgres
OptionMeaning
--packageBase package (default app.<name>)
--templateapi (HTTP, the default), worker (no HTTP: queues, schedules, events) or microservice
--ormpostgres, mysql or mongo: adds the ORM, a database connection in Main.kt, and for SQL a migrations entry point
--kest-versionVersion of the framework to depend on
--local <path>Build against a checkout of Kest instead of a published version (a composite build)

It writes the Gradle build (Kotlin, KSP and the Kest BOM), AppModule, Main, a health controller, .env, a test, and the kest task. --orm postgres or mysql also adds migrationGenerate, migrationRun and migrationRevert tasks.

cd shop && gradle wrapper && ./gradlew run

kest generate

kest g resource orders          # module, controller, service, model and DTOs: a CRUD API
kest g controller admin/users   # in the folder admin/users
kest g guard auth

generate has the alias g. Each schematic also has a short alias.

SchematicAliasWrites
modulemoa @Module
controllercoa @Controller with a first route
servicesan @Injectable
resourceresmodule, controller, service, model and Create/Update DTOs, wired together
guardgua Guard
interceptoritcan Interceptor
pipepia Pipe
filterfan ExceptionFilter
middlewaremia Middleware
decoratorda parameter decorator: annotation plus resolver
aspectasa method decorator: annotation plus wrapper
gatewaygaa WebSocket gateway, declared like a controller (adds the websocket dependency)
resolverrsa GraphQL resolver, declared like a controller (adds the graphql dependency)
processorpra queue processor (adds the queue dependency)
entity, repository, dtoe, r, dtORM entity, repository, validated DTO
libraryliba Gradle subproject under libs/, included and added to your build

Wiring into modules

Like nest g, the new class is added to the nearest @Module: the one in the same folder, else the closest one above, else AppModule. A controller goes into controllers, a service, guard or processor into providers, a module or resource into imports, and the import line is added. --no-update-module skips that. A file that already exists is never overwritten.

@Module(
    imports = [JacksonJsonModule::class, ValidationModule::class, OrdersModule::class],
    controllers = [HealthController::class],
    providers = [AuthGuard::class],
)
class AppModule

Migrations from the command line

The SQL project template writes a Migrations.kt entry point and three Gradle tasks:

./gradlew migrationGenerate -Pname=add_phone    # compare entities with the database, write the migration
./gradlew migrationRun
./gradlew migrationRevert

See Migrations.

What is tested

The generated project, with every schematic applied, builds with Gradle; a plain api project was started and answered requests, with validation. The CLI's own tests cover naming, module editing and the generated layout.