spring-feature-cli
v0.4.0
Published
CLI to generate Spring Boot boilerplate
Maintainers
Readme
spring-feature-cli
spring-feature-cli (spfc) generates complete, feature-based vertical slices — entity, repository, service and controller — with consistent naming and package structure, in a single command. It can also configure your application.properties through an interactive wizard.
Why
Every new feature in a Spring Boot project starts the same way: create four files across four packages, wire up the same imports, repeat the same naming conventions. Doing it by hand is slow and error-prone; copying from an existing feature drags leftover code along. spfc automates that first step so every feature starts clean and consistent.
Installation
npm install -g spring-feature-cliUsage
Generate a feature
Run inside your Spring Boot project:
spfc generate user
# or
spfc g userThe CLI detects your root package automatically (from the class annotated with @SpringBootApplication) and generates:
src/main/java/com/example/app/
└── user/
├── controller/UserController.java
├── domain/User.java
├── repository/UserRepository.java
└── service/UserService.javaUser— JPA entity with an auto-generatedLongidUserRepository— Spring DataJpaRepositoryUserService—@Servicestub ready to fill inUserController—@RestControllermapped to/api/user
Configure application.properties
spfc init
# or
spfc iLaunches an interactive wizard that asks for:
- Database engine (PostgreSQL, MySQL or H2)
- Hibernate
ddl-autostrategy (create,update,validate,none) - Database name, username and password
It shows a configuration summary, asks for confirmation, and writes src/main/resources/application.properties with the datasource, JPA/Hibernate and SQL-logging settings. The existing file is only overwritten after explicit confirmation.
How it works
- Walks up from the current directory until it finds a
pom.xmlcontainingspring-boot-starter(project root detection). - Locates the
@SpringBootApplicationclass and reads itspackagedeclaration to resolve the root package. - Renders Handlebars templates with the feature and package context, and writes the files following a feature-based (vertical slice) structure.
Requirements
- Node.js >= 20.17
- A Maven-based Spring Boot project (
pom.xmlwithspring-boot-starter)
Project structure
bin/index.js → CLI entry point
src/commands/ → Command definitions (commander)
src/actions/ → Generation and wizard logic
src/validations/ → Input validation layer
src/utils/ → Project scanning, package resolution, template rendering, logging
src/templates/ → Handlebars templates for the generated code
src/config/ → Architecture layouts and DB engine presetsBuilt with commander, @inquirer/prompts, handlebars and chalk.
