← Back to Blog

RFC: Lightweight Java Code Generator for Hilla

Context

Vaadin Flow and Hilla provide powerful ways to build modern web applications. Hilla, in particular, connects Java backend models with a React/TypeScript frontend through a TypeScript generator. This generator is the result of significant effort and has proven itself in production use. However, its architecture introduces complexity that makes it harder to extend quickly for new features.

Currently, the generator spans multiple Maven modules and npm packages. Its test setup is also split into Java tests (for the parser) and TypeScript tests (for the generator). This separation brings the risk of divergence between the two, especially if the Java output does not perfectly match what the TypeScript generator expects. Additionally, the two sides communicate through an OpenAPI definition: while valuable for documenting APIs, it cannot capture all required details, so custom tags are used. These architectural choices add robustness but also mean that implementing new functionality can take considerable time—sometimes to the point of abandoning certain improvements altogether.

A complementary approach is to build a Java-only lightweight generator, reducing these layers of complexity and accelerating feature development. In parallel, a proposal has emerged for a WebAssembly (Wasm) toolkit that allows writing Java-based views running client-side in the browser. These views would still need to communicate with a Java backend, making code generation a key component.

This RFC introduces two proof-of-concept repositories:

Repositories

jackson-parser

This repository contains the lightweight generator.

Key features:

Examples of what the lightweight generator can do:

wasm-flow

This repository contains a proof-of-concept WebAssembly toolkit that mirrors Hilla but for Java views, which can look almost identical to Flow views.

Proposal

  1. Adopt a lightweight Java-only generator as a foundation for shared type and endpoint generation.

    • Reduces architectural complexity and external dependencies.
    • Simplifies adding new features.
    • Provides a single testing model within Java.
  2. Position wasm-flow as a sibling to Hilla:

    • Hilla: React + TypeScript, generated with TypeScript.
    • Wasm Flow: Java + WebAssembly, generated with Java.
    • Both share the same server communication pattern.
  3. Unify communication tooling across Hilla and wasm-flow through a common generator.

    • Ensures consistency.
    • Avoids duplication of codegen logic.
    • Enables faster prototyping of new features.

Future Ideas

In addition to the examples already listed, the lightweight generator could support AI-driven, real-time interface generation. Beyond producing models, validators, or editors, it could generate dynamic field definitions and UI components tailored for assembly by large language models. With these building blocks in place, an LLM could efficiently construct dynamic frontends while consuming fewer tokens and less complexity.

This approach aligns with Vaadin's broader exploration of AI-assisted development. Hilla developers could contribute by providing lightweight, well-defined components that make it easier for AI to assemble UIs on the fly. Furthermore, these components could include Markdown-ready definitions, making them usable both in traditional UIs and within conversational interfaces.


Author: Luciano Vernaschi