AI-friendly, compile-safe Spring Boot scaffolding with DDD-friendly defaults, a Modulith-ready layout, and an installable Codex skill.
Overview · Why this structure · Features · Quick Start · Codex Skill · Generated Structure · Commands · Development
SpringBoot Generator CLI is a TypeScript-based CLI for generating modern Spring Boot projects and business modules.
It defaults to a pragmatic architecture:
sg newcreates a fresh Spring Boot project baselinesg g modulegenerates feature modules inapi / application / domain / infrastructure--style layeredkeeps the old layered generators available for compatibility- v1 follows Modulith-style package boundaries without forcing Spring Modulith as a hard dependency
- the CLI is the engine, and the bundled skill is the workflow layer for Codex and similar agents
Classic global folders like controller/, service/, repository/, entity/, and dto/ look simple at first, but they usually age badly.
They tend to create:
- scattered feature logic
- weak module ownership
- large procedural service classes
- hard-to-review cross-folder changes
This project makes package-by-feature the default so each business module stays easy to read, test, and extend.
AI can generate Spring Boot code, but teams still need stable scaffolding.
- prompts drift, but project structure should not
- ad hoc output often breaks imports, build files, or persistence wiring
- agents need deterministic commands they can rerun and verify
This project gives agents a reusable primitive: deterministic, compile-safe Spring Boot structure with a documented CLI and an installable skill.
- DDD-friendly module scaffolding
- Modulith-ready package layout
- Custom business fields via
--fields - Installable skill for Codex and similar agents
- Legacy layered compatibility mode
- EJS templates with explicit imports
- TypeScript tests, CI, and Maven smoke compilation
- Simple CLI commands with a low learning curve
npm install
npm run buildnpm start -- --helpnpx springboot-generator-cli@latest --helpsg new demo-app
cd demo-appRecommended defaults:
- Style:
ddd-modulith - Java:
21 - Spring Boot:
3.5.x - Common starter set:
web,jpa,validation,lombok,h2
sg g module UserWith custom business fields:
sg g module Product --fields "name:string,price:decimal,active:boolean"sg new old-style-app --style layered
sg g module User --style layered
sg g controller User --style layeredInstall the skill:
npx skills add https://github.com/YIbaikaishui/springboot-generator-cli --skill springboot-generatorUse it when you want an agent to:
- scaffold a new Spring Boot project with
ddd-modulithdefaults - generate a DDD-friendly module inside an existing codebase
- prefer stable, compile-safe scaffolding over one-off AI file generation
Skill behavior:
- the CLI is the engine
- the skill is the distribution and workflow layer
- the skill prefers
npx springboot-generator-cli@latest - when developing this repo itself, it can fall back to
node dist/cli.js
Default module output:
user/
├── api/
│ ├── UserController.java
│ ├── UserCreateRequest.java
│ ├── UserUpdateRequest.java
│ └── UserResponse.java
├── application/
│ └── UserApplicationService.java
├── domain/
│ ├── User.java
│ └── UserRepository.java
└── infrastructure/
└── persistence/
├── UserJpaEntity.java
├── UserJpaRepository.java
└── UserRepositoryImpl.java
Responsibilities:
api: HTTP entrypoints and request or response modelsapplication: use-case orchestration and transaction boundariesdomain: business model and repository abstractioninfrastructure: persistence and external implementation details
Create a new Spring Boot project.
| Option | Description |
|---|---|
-p, --package <package> |
Base package name, default com.example |
-d, --directory <directory> |
Target directory |
-s, --style <style> |
Project style: ddd-modulith or layered, default ddd-modulith |
Generate code artifacts.
Supported types:
module- recommendedcontroller- legacy layered generatorservice- legacy layered generatorrepository- legacy layered generatorentity- legacy layered generatordto- legacy layered generator
| Option | Description |
|---|---|
-f, --fields <fields> |
Business fields for modules, e.g. name:string,price:decimal |
-p, --package <package> |
Package name suffix |
-d, --directory <directory> |
Target directory, default src/main/java |
-m, --module <module> |
Explicit module directory name |
-s, --style <style> |
Module style: ddd-modulith or layered, default ddd-modulith |
--no-crud |
Skip CRUD-oriented boilerplate |
--no-rest |
Skip REST endpoints |
--no-jpa |
Skip JPA-related output |
--no-lombok |
Skip Lombok annotations |
Current v1 note:
ddd-modulithintentionally requires the default CRUD + REST + JPA baseline--no-crud,--no-rest, and--no-jpaare currently rejected for DDD modules with a clear CLI message
Inspect the current Spring Boot project and print basic metadata.
npm install
npm run build
npx vitest runSmoke compile the generated Maven project:
npm run smoke:mavenIf your default JAVA_HOME is not Java 21, override it:
SMOKE_JAVA_HOME=/path/to/jdk-21 npm run smoke:mavenWindows PowerShell:
$env:SMOKE_JAVA_HOME='C:\path\to\jdk-21'
npm run smoke:mavenCurrent CI checks:
npm run buildnpx vitest runnpm run smoke:mavennpm pack --dry-run
src/
├── cli.ts
├── commands/
├── generators/
├── templates/
├── types/
└── utils/
templates/
├── ddd/
└── *.ejs
- optional Spring Modulith starter support
- richer aggregate and domain event templates
- stricter port and adapter generation mode
- richer test template generation
- customizable template preset system
MIT