Spring Boot Project Creator
Overview
Generates a fully configured Spring Boot project from scratch using the Spring Initializr API. The skill walks the user through selecting project parameters, choosing an architecture style (DDD or Layered), configuring data stores, and setting up Docker Compose for local development. The result is a build-ready project with standardized structure, dependency management, and configuration.
When to Use
- Bootstrap a new Spring Boot 3.x or 4.x project with a standard structure.
- Initialize a backend microservice with JPA, SpringDoc OpenAPI, and Docker Compose.
- Scaffold a project following either DDD (Domain-Driven Design) or Layered (Controller/Service/Repository/Model) architecture.
- Set up local development infrastructure with PostgreSQL, Redis, and/or MongoDB via Docker Compose.
- Trigger phrases: "create spring boot project", "new spring boot app", "bootstrap java project", "scaffold spring boot microservice", "initialize spring boot backend", "generate spring boot project".
Prerequisites
Before starting, ensure the following tools are installed:
- Java Development Kit (JDK): Version 17+ (Java 21 recommended for Spring Boot 3.x/4.x)
- Apache Maven: Build tool (Spring Initializr generates Maven projects by default)
- Docker and Docker Compose: For running local infrastructure services
- curl and unzip: For downloading and extracting the project from Spring Initializr
Instructions
Follow these steps to create a new Spring Boot project.
1. Gather Project Configuration
Ask the user for the following project parameters using AskUserQuestion. Provide sensible defaults:
| Parameter |
Default |
Options |
| Group ID |
com.example |
Any valid Java package name |
| Artifact ID |
demo |
Kebab-case identifier |
| Package Name |
Same as Group ID |
Valid Java package |
| Spring Boot Version |
3.4.5 |
3.4.x, 4.0.x (check start.spring.io for latest) |
| Java Version |
21 |
17, 21 |
| Architecture |
User choice |
DDD or Layered |
| Docker Services |
User choice |
PostgreSQL, Redis, MongoDB (multi-select) |
| Build Tool |
maven |
maven, gradle |
2. Generate Project with Spring Initializr
Use curl to download the project scaffold from start.spring.io.
Base dependencies (always included):
web β Spring Web MVC
validation β Jakarta Bean Validation
data-jpa β Spring Data JPA
testcontainers β Testcontainers support
Conditional dependencies (based on Docker Services selection):
- PostgreSQL selected β add
postgresql
- Redis selected β add
data-redis
- MongoDB selected β add
data-mongodb
curl -s https://start.spring.io/starter.zip \
-d type=maven-project \
-d language=java \
-d bootVersion=3.4.5 \
-d groupId=com.example \
-d artifactId=demo \
-d packageName=com.example \
-d javaVersion=21 \
-d packaging=jar \
-d dependencies=web,data-jpa,postgresql,validation,testcontainers \
-o starter.zip
unzip -o starter.zip -d ./demo
rm starter.zip
cd demo
3. Add Additional Dependencies
Edit pom.xml to add SpringDoc OpenAPI and ArchUnit for architectural testing.
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.8.15</version>
</dependency>
<dependency>
<groupId>com.tngtech.archunit</groupId>
<artifactId>archunit-junit5</artifactId>
<version>1.4.1</version>
<scope>test</scope>
</dependency>
4. Create Architecture Structure
Based on the user's choice, create the package structure under src/main/java/<packagePath>/.
Option A: Layered Architecture
src/main/java/com/example/
βββ controller/ # REST controllers (@RestController)
βββ service/ # Business logic (@Service)
βββ repository/ # Data access (@Repository, Spring Data interfaces)
βββ model/ # JPA entities (@Entity)
β βββ dto/ # Request/Response DTOs (Java records)
βββ config/ # Configuration classes (@Configuration)
βββ exception/ # Custom exceptions and @ControllerAdvice
Create placeholder classes for each layer:
- config/OpenApiConfig.java β SpringDoc OpenAPI configuration bean
- exception/GlobalExceptionHandler.java β
@RestControllerAdvice with standard error handling
- model/dto/ErrorResponse.java β Standard error response record
Option B: DDD (Domain-Driven Design) Architecture
src/main/java/com/example/
βββ domain/ # Core domain (framework-free)
β βββ model/ # Entities, Value Objects, Aggregates
β βββ repository/ # Repository interfaces (ports)
β βββ exception/ # Domain exceptions
βββ application/ # Use cases / Application services
β βββ service/ # @Service orchestration
β βββ dto/ # Input/Output DTOs (records)
βββ infrastructure/ # External adapters
β βββ persistence/ # JPA entities, Spring Data repos
β βββ config/ # Spring @Configuration
βββ presentation/ # REST API layer
βββ controller/ # @RestController
βββ exception/ # @RestControllerAdvice
Create placeholder classes for each layer:
- infrastructure/config/OpenApiConfig.java β SpringDoc OpenAPI configuration bean
- presentation/exception/GlobalExceptionHandler.java β
@RestControllerAdvice with standard error handling
- application/dto/ErrorResponse.java β Standard error response record
5. Configure Application Properties
Create src/main/resources/application.properties with the selected services.
Always include:
spring.application.name=${artifactId}
springdoc.swagger-ui.doc-expansion=none
springdoc.swagger-ui.operations-sorter=alpha
springdoc.swagger-ui.tags-sorter=alpha
If PostgreSQL is selected:
spring.datasource.driver-class-name=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/${POSTGRES_DB:postgres}
spring.datasource.username=${POSTGRES_USER:postgres}
spring.datasource.password=${POSTGRES_PASSWORD:changeme}
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true
If Redis is selected:
spring.data.redis.host=localhost
spring.data.redis.port=6379
spring.data.redis.password=${REDIS_PASSWORD:changeme}
If MongoDB is selected:
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.authentication-database=admin
spring.data.mongodb.username=${MONGO_USER:root}
spring.data.mongodb.password=${MONGO_PASSWORD:changeme}
spring.data.mongodb.database=${MONGO_DB:test}
6. Set Up Docker Compose
Create docker-compose.yaml at the project root with only the services the user selected.
services:
postgresql:
image: postgres:17
ports:
- "5432:5432"
environment:
POSTGRES_USER: ${POSTGRES_USER:-postgres}
POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-changeme}
POSTGRES_DB: ${POSTGRES_DB:-postgres}
volumes:
- ./postgres_data:/var/lib/postgresql/data
redis:
image: redis:7
ports:
- "6379:6379"
command: redis-server --requirepass ${REDIS_PASSWORD:-changeme}
volumes:
- ./redis_data:/data
mongodb:
image: mongo:8
ports:
- "27017:27017"
environment:
MONGO_INITDB_ROOT_USERNAME: ${MONGO_USER:-root}
MONGO_INITDB_ROOT_PASSWORD: ${MONGO_PASSWORD:-changeme}