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 listInside 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| Option | Meaning |
|---|---|
--package | Base package (default app.<name>) |
--template | api (HTTP, the default), worker (no HTTP: queues, schedules, events) or microservice |
--orm | postgres, mysql or mongo: adds the ORM, a database connection in Main.kt, and for SQL a migrations entry point |
--kest-version | Version 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 runkest 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 authgenerate has the alias g. Each schematic also has a short alias.
| Schematic | Alias | Writes |
|---|---|---|
module | mo | a @Module |
controller | co | a @Controller with a first route |
service | s | an @Injectable |
resource | res | module, controller, service, model and Create/Update DTOs, wired together |
guard | gu | a Guard |
interceptor | itc | an Interceptor |
pipe | pi | a Pipe |
filter | f | an ExceptionFilter |
middleware | mi | a Middleware |
decorator | d | a parameter decorator: annotation plus resolver |
aspect | as | a method decorator: annotation plus wrapper |
gateway | ga | a WebSocket gateway, declared like a controller (adds the websocket dependency) |
resolver | rs | a GraphQL resolver, declared like a controller (adds the graphql dependency) |
processor | pr | a queue processor (adds the queue dependency) |
entity, repository, dto | e, r, dt | ORM entity, repository, validated DTO |
library | lib | a 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 AppModuleMigrations 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 migrationRevertSee 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.