short20s.mp4
JavaFactory is a tool that uses LLMs to automatically generate repetitive Java code. It produces results that are more predictable and stable than those of traditional AI code generators. JavaFactory operates based on two core components:
-
Pattern Definition: Define each unit of work in natural language (e.g., test generation, implementation generation, etc.)
-
Annotation-Based Reference Collection: Explicitly specify the required classes using annotations.
Once defined, these patterns can be reused repeatedly to generate various types of code — such as implementations, tests, and fixtures.
The following demo shows an example where 400 lines of code were generated, and all tests passed:


Repetitive tasks can be defined as a single pattern. A pattern clearly specifies what to generate, how to generate it, and which classes to reference.
A pattern consists of two main parts:
## Goal
{{ user_defined_goal }}
## Rules
{{ user_defined_rules }}
## Output
{{ expected_format }}
## Example
{{ typical_example_code }}
<< {role_name1 } >>
{{ class source }}
<< {role_name1 } >>
{{ class source }}
....
You can configure the System Prompt and User Prompt for each task, and JavaFactory provides a dedicated UI for this purpose.
- Edit system prompt configuration
Goal, Rules, Output, Example can be customized
- Edit user prompt configuration
Determine which classes should be included in the user prompt.
The classes to be used in a pattern are explicitly scoped using annotations. When a class is annotated with a specific role, it will be automatically included if it matches the reference targets defined in the pattern.
Annotations are categorized into two main types:
-
@JavaFactoryData
- Recursively collects the classes specified in
referencedData
. - Example: Domain models, entities, and other data-related classes.
- Recursively collects the classes specified in
-
@JavaFactoryApi
- Collects only one level of
referencedApi
. - Optionally allows specifying the implementation, test, and fixture classes for the API.
- Example: API interfaces such as Reader, Writer, Validator.
- Collects only one level of
You can explicitly control which classes are needed for code generation and how far the reference collection should go.
- If you've experienced unpredictable results or maintainability issues on former code generation
- If you want more than just simple generation — you want to explicitly control the task unit and reference structure
- For example: Environments with repeating patterns like layered architecture
- Tasks like the following can be automated repeatedly after defining the rule once:
- dao-repository-implementation
- dao-repository-test
- dao-repository-fixture
- domain-api-implementation
- domain-api-test
- domain-api-fixture
In such structures, I recommend designing the red boxes manually, and letting JavaFactory automate the blue boxes.