Build Your Own Generator Customization
Section titled “Build Your Own Generator Customization”ZenWave SDK generates Spring Boot in Java by default. A customization is a Maven jar of Handlebars templates and Java helpers. The official plugins load it through their templates option, so the same ZDL, OpenAPI and AsyncAPI models generate code for another stack. A customization does not define a plugin of its own.
This guide has two readers: you and your coding agent. Each step has an Agent: block with instructions to follow and a Human: line that explains why the step exists.
How to use this guide
Section titled “How to use this guide”- Create an empty folder and put a
base-project/inside it. It is a small working project in your stack (.NET, Node.js, Go, Java, …) that shows the patterns you want generated: layers, naming, persistence, messaging and tests. It must build, and its tests must pass. - Give this guide to your coding agent in one of two ways:
- Copy the prompt below, open your agent in that folder, and paste it. The agent fetches this guide as Markdown.
- Or download
CUSTOMIZATION-GUIDE.mdinto the folder, check it, and tell your agent:Read CUSTOMIZATION-GUIDE.md and create a ZenWave customization from my base project.
Read https://www.zenwave360.io/docs/build-your-own-customization.md and create a ZenWave customization from my base project The downloaded CUSTOMIZATION-GUIDE.md has the same content as the page you are reading, in Markdown so you can save it to disk. The instructions are the same.
Reference customizations
Section titled “Reference customizations”These customizations follow this recipe. Read their code when a step needs a concrete example.
| Target | Status | Source | What to look at |
|---|---|---|---|
| Spring Boot, Java | Default | backend-application-default | The official templates and helpers you replace: BackendApplicationProjectTemplates and its .hbs files. |
| Spring Boot, Kotlin | Official | kotlin-backend-application | The project shape to copy: one module, *Templates extends ProjectTemplates, helpers, .hbs templates, provided dependencies. |
| Quarkus, Java | Beta, unofficial | zenwave-quarkus | The working documents (docs/), the shared test models, and the e2e/ loop with regenerate.sh. |
What runs where
Section titled “What runs where”The generator always runs on the JVM, from the jbang CLI, the Maven plugin or the IDE. Your customization is a Java Maven module: its *Templates and *Helpers classes are Java, built with Java 17 or later.
The Handlebars templates can emit any language. A .NET, Node.js or Go customization is still a Java Maven module, and its templates write C#, TypeScript or Go files into your project. Only the build of the customization itself needs Java and Maven. The generated project keeps its own toolchain.
Code formatting after generation only runs for files registered as JAVA or KOTLIN. For other languages, register templates with a null output type and format the output with your own tools.
Step 1 · Prerequisites and inputs
Section titled “Step 1 · Prerequisites and inputs”Human: the base project is your definition of good code. The generator can only reproduce patterns that someone wrote down first.
Agent:
- Check the three inputs. Ask the human for anything missing, and do not guess. If nobody can answer, write your assumption under “Open questions” in
docs/target-stack.mdand continue:base-project/: run its install, build and test commands (for examplenpm ci,dotnet build,mvn verify). Write down the exact commands and confirm they pass. If you cannot run them, for example without network access, write that down too.- Target stack name, for example
dotnet,nestjsorquarkus. It names the modules and the Java package. - ZenWave SDK version: the version the users of this customization run. The
provideddependencies use it.
- Check the tools: JDK 17 or later, Maven and git.
- Get the ZenWave SDK source at that version, for example a clone of zenwave-sdk next to this folder. Before you use an
io.zenwave360.sdktype, method, option or model key, read it in that source. Do not rely on memory. - Create this layout in the same folder as
base-project/(the folder the human gave you, not a new subfolder). Do not modifybase-project/:
my-customization/
├── base-project/ # input, read-only
├── AGENTS.md # how to work in this repo (see below)
├── pom.xml # Maven reactor (step 4)
├── docs/
│ ├── target-stack.md # step 2
│ ├── customization.md # step 3
│ ├── tasks.md # step 5
│ └── sdk-coupling.md # step 7
├── test-resources/ # shared models (step 4)
├── <stack>-backend-application/ # templates + helpers (step 4)
└── e2e/ # generate, build, test (step 6)
- Write a short
AGENTS.md: what this repo is, where the pattern and stack are (docs/target-stack.md), where the contract is (docs/customization.md), where the status is (docs/tasks.md, with its marks), and the rule from item 3 about reading the SDK source.
Step 2 · Analyse the base project
Section titled “Step 2 · Analyse the base project”Human: you get one page to review and approve before any template exists. A wrong decision is cheapest to fix here.
Agent: read all of base-project/ and write docs/target-stack.md with these sections. Write only what the base project shows. List anything else under “Open questions” for the human.
-
General purpose. This is a ZenWave customization: a Maven jar of Handlebars templates and helpers, with no plugin of its own, selected with the
templatesoption on the official plugins. It copies the project shape ofkotlin-backend-application. Its dependencies on the official plugins whose templates it replaces areprovided. -
Modules. A table with the role of each module: parent,
test-resources,<stack>-backend-application,e2e, and one module per extra plugin you replace (for example AsyncAPI). -
Target stack. Language and version, framework, build tool, dependency wiring, and the layer and package layout. Map that layout to a ZenWave project layout such as
CleanHexagonalProjectLayoutorLayeredProjectLayout. Then naming conventions, persistence (ORM, repositories, migrations), mapping between DTOs and entities, REST controllers, messaging (in-process events, broker), and test style (unit, in-memory, integration, HTTP). Cite a base project file for each item.ZenWave layouts are Java packages: each
layout.*Packageis a dotted name that becomes a folder in the target path. For a folder-based language, record the folder of each layer, and the layout package that maps to it, so step 3 can use them. -
Hard constraints on generated code. Rules the base project follows that generated code must keep, for example “no framework types in the domain” or “repositories behind an interface”.
-
Version pinning. Templates write sources into an existing project. They do not emit build files, the application entry point, wrappers, Docker Compose or a README. Those files, and every library version, belong to the base project and the e2e scaffold.
-
Testing. Unit tests in the customization module, and the e2e loop from step 6.
-
Open questions.
Stop and ask the human to review docs/target-stack.md.
Step 3 · Write the contract
Section titled “Step 3 · Write the contract”Human: this file is the contract. Templates are written against it, and you review the customization one row at a time.
Agent: write docs/customization.md.
- How templates are selected. One row per official plugin you replace:
| Official plugin | Templates class | Option value |
|---|---|---|
BackendApplicationDefaultPlugin | <Stack>BackendApplicationTemplates | new <package>.<Stack>BackendApplicationTemplates |
OpenAPIControllersPlugin | <Stack>OpenAPIControllersTemplates | new <package>.<Stack>OpenAPIControllersTemplates |
SpringWebTestClientPlugin | <Stack>HttpTestTemplates | new <package>.<Stack>HttpTestTemplates |
AsyncAPIGeneratorPlugin | <Stack>AsyncAPITemplates | <package>.<Stack>AsyncAPITemplates (a class name, no new) |
Keep only the plugins the base project needs. The backend one is the core.
-
Target files. Read the official templates class in the SDK source (
BackendApplicationProjectTemplatesfor the backend) and the Kotlin one (BackendApplicationKotlinTemplates). For each template they register, add a row: the target file in your stack, and when it is generated (each aggregate, each entity, each service, once, only with events, …). Use the same path placeholders, such as{{entity.name}}and{{service.name}}. Write each target path as source folder + layout package + file name: the official templates usesrc/main/javaandsrc/test/javaas source folders, and yours can be anything, for examplesrcandtest. The template list a template belongs to (entityTemplates,serviceTemplates,singleTemplates, …) sets how often it runs: read the list fields ofProjectTemplatesin the SDK source. A list you leave empty generates nothing.If a concept does not fit an existing option value, for example raw SQL where
persistenceoffersjpaandmongodb, write it down as an open question. -
Additions and removals. Mark the files your stack adds that the official templates do not have, for example a repository implementation. List the official templates you do not register, and why.
-
Substitutions. For each concept (inbound service, service implementation, entity, repository, mapper, domain events and listeners, REST controller, tests), write what the target stack uses instead of the Spring Boot default. Cite the base project file it comes from.
Stop and ask the human to review docs/customization.md.
Step 4 · Scaffold the Maven module
Section titled “Step 4 · Scaffold the Maven module”Human: copying a proven project shape means build, test and packaging problems are already solved.
Agent: create the Maven reactor. Mirror kotlin-backend-application file by file.
- Parent
pom.xml: a property with the ZenWave SDK version, dependency management for the official plugins, and the module list. test-resources: the models every other module tests with, on the classpath (zdl/,openapi/openapi.yml,asyncapi/asyncapi.yml). Start from the SDK test models, for examplecustomer-address-relational.zdlinzenwave-sdk-test-resources, plus a model that describes the base project’s own domain. Other modules depend on this one and keep no copies.<stack>-backend-application: a jar withprovideddependencies on the official plugins it replaces:
<dependency>
<groupId>io.zenwave360.sdk.plugins</groupId>
<artifactId>backend-application-default</artifactId>
<version>${zenwave-sdk.version}</version>
<scope>provided</scope>
</dependency>
<!-- same for openapi-controllers and openapi-spring-webtestclient, if you replace them -->
- A templates class that extends
io.zenwave360.sdk.zdl.ProjectTemplates, sets its templates folder in the constructor, registers templates withaddTemplate(...)and adds its helpers ingetTemplateHelpers. This is the shape ofBackendApplicationKotlinTemplates:
public class MyStackBackendApplicationTemplates extends ProjectTemplates {
// options are bound onto public fields with the same name
public PersistenceType persistence = PersistenceType.jpa;
protected Function<Map<String, Object>, Boolean> skipEntity = (model) -> is(model, "vo", "input");
@Override
public List<Object> getTemplateHelpers(Generator generator) {
var helpers = new ArrayList<>(super.getTemplateHelpers(generator));
if (generator instanceof BackendApplicationDefaultGenerator backendGenerator) {
helpers.add(new MyStackBackendApplicationHelpers(backendGenerator));
}
return helpers;
}
public MyStackBackendApplicationTemplates() {
setTemplatesFolder("com/example/zenwave/mystack/BackendApplicationDefaultGenerator");
var layoutNames = new ProjectLayout();
// copied from the Kotlin customization: change the source folder, template, file name and output type for your stack
this.addTemplate(this.entityTemplates, "src/main/kotlin", "core/domain/{{persistence}}/Entity.kt",
layoutNames.entitiesPackage, "{{entity.name}}.kt", KOTLIN, skipEntity, false);
// ...one addTemplate per row of docs/customization.md
}
}
- Templates live under
src/main/resources/<templates folder>/<source folder>/<template location>.hbs. In the example above that issrc/main/resources/com/example/zenwave/mystack/BackendApplicationDefaultGenerator/src/main/kotlin/core/domain/jpa/Entity.kt.hbs. - A first unit test that runs the official plugin with your templates on a
test-resourcesmodel, as the Kotlin tests do:
Plugin plugin = new BackendApplicationDefaultPlugin()
.withZdlFile("classpath:zdl/customer-address-relational.zdl")
.withTargetFolder("target/projects/customer-address")
.withOption("templates", "new " + MyStackBackendApplicationTemplates.class.getName())
.withOption("basePackage", "com.example.customers")
.withOption("persistence", PersistenceType.jpa)
.withOption("style", ProgrammingStyle.imperative)
.withOption("forceOverwrite", true)
.withOption("haltOnFailFormatting", false);
new MainGenerator().generate(plugin);
// assert the generated files exist and contain the expected types
- An empty
e2emodule, filled in step 6.
Run mvn install and confirm it passes before you write templates.
Step 5 · Templates and helpers, one slice at a time
Section titled “Step 5 · Templates and helpers, one slice at a time”Human: small slices keep every diff reviewable, and docs/tasks.md shows progress at a glance.
Agent:
- Write
docs/tasks.md: one task per group of rows ofdocs/customization.md, grouped by module. Marks:[ ]not started,[/]in progress,[x]done or ready for review,[!]blocked. Only one task is[/]at a time. Update the mark when a task moves. - Start with a thin vertical slice: entity, repository port, inbound service and service implementation. Then do the remaining rows.
- For each template:
- Start from the official
.hbs(or the Kotlin one) for that slot, and rewrite it so its output matches the base project file for the same concept. - Register it with
addTemplate(list, sourceFolder, templateLocation, targetPackage, targetFile, outputType, skip, skipOverwrite). Thelistsets how often it runs:entityTemplatesonce per entity,serviceTemplatesonce per service,singleTemplatesonce, and so on. ThesourceFolderis part of both the template location and the target path.targetPackageis a layout placeholder fromProjectLayout, such aslayoutNames.entitiesPackage, rendered as a folder.skipis a function of the template model that returnstrueto skip the file. WithskipOverwriteset totrue, an existing file is kept unless the user passesforceOverwrite: use it for files developers edit by hand. - Partials resolve relative to the template that includes them.
- Start from the official
- Helpers:
- A helper is a public method on your helpers class, called from templates by name. When the default helpers already compute what you need, use them.
- A helper with the same name as an SDK helper replaces it for your templates, as the Kotlin
javaTypedoes. - To see the model a template receives, run
jbang zw -p ZdlToJsonPlugin zdlFile=zenwave-model.zdland read the SDK source of the helper or model key you use.
- Add or extend a unit test with each slice: assert the target files exist and contain the types the contract names.
- Run
mvn installafter each slice. A slice is[x]when its unit tests pass and its output builds in the e2e loop.
Step 6 · The e2e loop
Section titled “Step 6 · The e2e loop”Human: your base project’s own tests are the acceptance test. Generated code that passes them follows your patterns.
Agent:
- Scaffold. Copy
base-project/toe2e/src/test/resources/projects/<name>/. Keep the build files, wrapper, configuration and Docker files. Remove the hand-written domain code that the generator now produces. Addzenwave-model.zdlwith the model of that domain. Write down indocs/e2e-scaffold.mdhow the scaffold was made and what you changed. - E2E test. A test in
e2ecopies the scaffold totarget/projects/<name>/, replaces itszenwave-model.zdlwith thetest-resourcesmodel, runs the official plugins with yourtemplatesoption into the copy, then runs the base project’s build and test commands from step 1 on the copy. Skip e2e tests in a normal build and run them with a property, as the SDK does withe2e.tests.skip:mvn install -De2e.tests.skip=false. - Regenerate in place. Add
e2e/regenerate.sh <name> [--force|--clean]. It reinstalls the templates, then regenerates the checked-in project. By default it writes only missing files and keeps hand-edited ones.--forceoverwrites every generated file.--cleandeletes the generated source folders first. - Loop. Generate, build, test. When something fails, fix the template or helper, never the generated file, and run again. Record each template fix in
docs/tasks.md. - Keep two e2e projects if you can: one hand-finished, with the full test suite, and one generated fresh, that at least compiles and passes architecture tests.
The zenwave-quarkus e2e runs the plugins through zenwave-sdk-maven-plugin in a Maven profile of the scaffold project, because the scaffold is a Maven project. For a non-JVM scaffold, the e2e test can run the plugins in Java with MainGenerator, as the unit test in step 4 does.
Step 7 · Record the SDK coupling
Section titled “Step 7 · Record the SDK coupling”Human: the templates option is the only documented extension point. Everything else is SDK internals, and this file turns an SDK upgrade into a checklist.
Agent: write docs/sdk-coupling.md.
- Decision. Say whether you keep every template local, including ones identical to upstream, or load some from the SDK jar. zenwave-quarkus keeps all of them local: one folder holds the whole output, and an upstream change never alters the generated code silently. The cost is porting upstream fixes by hand.
- Last synced. The SDK version or commit, and the date. Update it after every port.
- What we depend on. A table: SDK surface, used by, stability, what a change breaks. Include at least: the
templatesoption (documented);ProjectTemplatestemplate lists,addTemplate,setTemplatesFolder,getTemplateHelpers; option binding onto public fields of the templates class; the upstream helpers your templates call; helper name precedence; partial resolution; the model keys your templates read; and the SDK utility classes your helpers call. Mark everything except thetemplatesoption as internal. - How breaks are detected. Compile errors from
mvn install, render errors and missing files from the unit tests, wrong output from the e2e loop. Say what is not covered: a model key that renders blank in a branch no e2e model exercises. - When bumping the SDK. Diff upstream templates and Java since the last synced commit, check the templates classes for renamed or split lists, port the fixes that apply, run the full build with e2e, update “Last synced”.
Step 8 · Package and use
Section titled “Step 8 · Package and use”Human: users keep the official plugins and their options. Only the templates option and one dependency change.
Agent: install with mvn install, or deploy the jar to a Maven repository your users can reach. Then document these three ways to use it in the customization’s README.
With a .zw file in ZenWave Editor:
@import("com.example:mystack-backend-application:1.0.0")
config {
zdlFile "zenwave-model.zdl"
plugins {
BackendApplicationDefaultPlugin {
templates "new com.example.zenwave.mystack.MyStackBackendApplicationTemplates()"
}
}
}
With the Maven plugin, add the customization as a plugin dependency and set templates in configOptions:
<plugin>
<groupId>io.zenwave360.sdk</groupId>
<artifactId>zenwave-sdk-maven-plugin</artifactId>
<version>${zenwave.version}</version>
<executions>
<execution>
<id>backend-application</id>
<goals><goal>generate</goal></goals>
<configuration>
<generatorName>BackendApplicationDefaultPlugin</generatorName>
<configOptions>
<zdlFile>${project.basedir}/zenwave-model.zdl</zdlFile>
<templates>new com.example.zenwave.mystack.MyStackBackendApplicationTemplates</templates>
<basePackage>com.example.customers</basePackage>
</configOptions>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>io.zenwave360.sdk.plugins</groupId>
<artifactId>backend-application-default</artifactId>
<version>${zenwave.version}</version>
</dependency>
<dependency>
<groupId>com.example</groupId>
<artifactId>mystack-backend-application</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
With the jbang CLI, add the jar with --deps, as described in Customizing Generated Code.
Step 9 · Definition of done
Section titled “Step 9 · Definition of done”Human: use this list to review the work, or hand it to a second agent as a review checklist.
Agent: the customization is done when all of these are true:
docs/target-stack.mdanddocs/customization.mdare reviewed by the human, and their open questions are answered.- Every row of
docs/customization.mdhas a registered template, or is listed as not registered with a reason. - Every task in
docs/tasks.mdis[x], or[!]with a reason the human accepted. mvn installpasses with unit tests that cover every templates class.mvn install -De2e.tests.skip=falsegenerates the e2e projects and passes the base project’s build and tests on them.- Generated code respects every hard constraint in
docs/target-stack.md. docs/sdk-coupling.mdlists the SDK surfaces used and the last synced SDK version.- The README shows how to use the customization from
.zw, Maven and jbang.
Further reading
Section titled “Further reading”- Customizing Generated Code: layouts, single template overrides, classpath extension.
- Kotlin Backend Application: the official customization this recipe copies.
- Arcadia Editions Modulith, Quarkus (beta): an application generated with zenwave-quarkus.
- Generating Quarkus with ZenWave SDK: blog post about zenwave-quarkus.