Spring Boot Architecture logo

Spring Boot Architecture

Community
j4flmao
spring-boot-architecture

Use this skill when the user says 'Spring Boot structure', 'Spring architecture', 'Spring Boot clean arch', 'Spring layered', 'Spring hexagonal', 'Spring WebFlux', 'Spring Data', 'Spring Boot folder', or when building a Spring Boot application. This skill enforces: package-by-feature (not by layer), hexagonal architecture with ports and adapters, Spring stereotypes correctly applied (@Repository in infrastructure, not domain), constructor injection (no @Autowired on fields), and MVC vs WebFlux decision guide. Requires Spring Boot (pom.xml or build.gradle). Do NOT use for: Kotlin Multiplatform, non-Spring Java, or frontend Angular.

Overview

Publisherj4flmao
Repositoryagent-skills
Skill namespring-boot-architecture
Stars
41
Forks
6
Bundled files
8
LicenseMIT
Links
  • Markdown instructions

    A SKILL.md file the model loads on demand, so it only costs tokens when a request actually matches.

  • Works with any LLM

    AI skills are plain Markdown, not provider-specific code, so this works with GPT, Claude, Gemini, Grok, or a local model.

  • 8 bundled files

    Scripts, templates, and references the model can read while it works. Files are read-only and never executed.

  • Open source

    Published by j4flmao on GitHub. Read the source before you install it.

Installation

Install the Spring Boot Architecture AI skill in TypingMind to use it with any LLM, or drop it into another agent that reads SKILL.md.

1

Install in TypingMind

TypingMind installs a skill straight from its GitHub folder — it reads SKILL.md, bundles the resource files, and stores the result locally.

  1. Open the app and go to Plugins → Skills.
  2. Choose "Install from GitHub".
  3. Paste the skill folder URL below and confirm.
    https://github.com/j4flmao/agent-skills/tree/main/skills/backend/spring-boot/architecture
  4. Enable the skill in any chat where you want it available.
Plugins → Skills → Add skill → From GitHub URL, then paste the folder URL and press Continue.
2

Install in another agent

Any agent that reads the Agent Skills format can use this skill — copy the folder into that agent's skills directory.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/j4flmao/agent-skills.git /tmp/agent-skills
mkdir -p .claude/skills
cp -r /tmp/agent-skills/skills/backend/spring-boot/architecture .claude/skills/spring-boot-architecture
Restart Claude Code after copying so it picks up the new skill.

Use it in TypingMind

Enable Spring Boot Architecture in any TypingMind chat and the model takes it from there. Its name and description sit in the system prompt, and the moment a request matches, the model loads the full instructions itself — you never invoke it by hand, and it costs no tokens until it is actually used.

The model loads Spring Boot Architecture on its own as soon as a request matches it.

Works with any AI model

AI skills are plain Markdown instructions rather than provider-specific code, so Spring Boot Architecture is not tied to the model it was written for. Install it once in TypingMind and use it with GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama, or a local model you run yourself — all on your own API keys.

  • Loaded only when it is needed

    The system prompt carries just the name and description. The instructions are fetched on the first matching request, so an idle skill costs nothing.

  • Switch models mid-chat

    Because the skill is instructions rather than code, changing model does not break it — the next model reads the same SKILL.md.

Skill instructions

This is the SKILL.md content the model loads. Read it before installing — a skill is instructions your model will follow.

Spring Boot Architecture

Purpose

Structure Spring Boot applications with package-by-feature and hexagonal architecture. Domain has zero Spring imports. Annotations only in infrastructure and presentation.

Agent Protocol

Trigger

Exact user phrases: "Spring Boot structure", "Spring architecture", "Spring Boot clean arch", "Spring layered", "Spring hexagonal", "Spring WebFlux", "Spring Data", "Spring Boot folder", "Spring project layout".

Input Context

Before activating, verify:

  • pom.xml or build.gradle has spring-boot-starter dependency.
  • The feature or module being created is known.

Output Artifact

No file output. Produces folder structure and code examples as text.

Response Format

Folder structure:

src/main/java/com/project/{feature}/
  domain/
  application/
  infrastructure/
  presentation/

Code: Java class-level only. Package declaration omitted.

No preamble. No postamble. No explanations. No filler/hedging/transitions. Compress output — why use many token when few do trick.

Completion Criteria

  • Package-by-feature (com.project.orders, com.project.users), not by layer (com.project.controllers, com.project.services).
  • Domain package has zero Spring imports (@Entity is the sole exception, but prefer pure POJOs).
  • Interfaces (ports) in domain/, implementations (adapters) in infrastructure/.
  • Constructor injection used everywhere. No @Autowired on fields.
  • @Transactional at application service level, not controller level.
  • @ExceptionHandler in @ControllerAdvice for error mapping.

Max Response Length

Folder structure: unlimited. Code: 20 lines per example.

Workflow

Step 1: Package by Feature

com.project/
  Application.java                        -- @SpringBootApplication
  config/
    SecurityConfig.java
    ObjectMapperConfig.java
    OpenApiConfig.java
  shared/
    BaseEntity.java
    DomainEvent.java
    PagedResult.java
  {feature}/
    domain/
      Order.java                          -- Domain entity (POJO)
      OrderStatus.java                    -- Value object / enum
      OrderRepository.java                -- Port (interface)
      OrderService.java                   -- Domain service
    application/
      in/
        PlaceOrderUseCase.java            -- Inbound port interface
        CancelOrderUseCase.java
      out/
        OrderEventPublisher.java          -- Outbound port interface
        PaymentService.java
      dto/
        PlaceOrderCommand.java
        OrderResponse.java
        PagedOrdersQuery.java
    infrastructure/
      persistence/
        OrderJpaEntity.java               -- @Entity (JPA concern)
        OrderJpaRepository.java            -- Spring Data interface
        OrderJpaRepositoryImpl.java        -- Implements OrderRepository
      messaging/
        OrderKafkaPublisher.java
      adapters/
        PaymentGatewayAdapter.java
    presentation/
      OrderController.java                -- @RestController
      OrderControllerAdvice.java           -- @ExceptionHandler

Step 2: Hexagonal with Spring

java
// PORT (domain layer -- no Spring annotation)
public interface OrderRepository {
    Optional<Order> findById(OrderId id);
    Order save(Order order);
    Page<Order> findAll(Pageable pageable);
    void delete(OrderId id);
}

// ADAPTER (infrastructure layer -- Spring-managed)
@Component
public class OrderJpaRepositoryImpl implements OrderRepository {
    private final SpringDataOrderRepository springRepo;
    private final OrderJpaMapper mapper;

    public OrderJpaRepositoryImpl(SpringDataOrderRepository springRepo, OrderJpaMapper mapper) {
        this.springRepo = springRepo;
        this.mapper = mapper;
    }

    @Override
    public Order save(Order order) {
        OrderJpaEntity entity = mapper.toJpaEntity(order);
        OrderJpaEntity saved = springRepo.save(entity);
        return mapper.asDomain(saved);
    }

    @Override
    public Optional<Order> findById(OrderId id) {
        return springRepo.findById(id.getValue())
            .map(mapper::asDomain);
    }

    @Override
    public Page<Order> findAll(Pageable pageable) {
        return springRepo.findAll(pageable)
            .map(mapper::asDomain);
    }

    @Override
    public void delete(OrderId id) {
        springRepo.deleteById(id.getValue());
    }
}

// USE CASE (application layer)
@Service
public class PlaceOrderService implements PlaceOrderUseCase {
    private final OrderRepository orderRepo;
    private final OrderEventPublisher eventPublisher;

    public PlaceOrderService(OrderRepository orderRepo, OrderEventPublisher eventPublisher) {
        this.orderRepo = orderRepo;
        this.eventPublisher = eventPublisher;
    }

    @Transactional
    public OrderId execute(PlaceOrderCommand command) {
        Order order = Order.create(command.customerId(), command.items());
        order = orderRepo.save(order);
        eventPublisher.publish(new OrderPlacedEvent(order.getId()));
        return order.getId();
    }
}

// CONTROLLER (presentation layer)
@RestController
@RequestMapping("/v1/orders")
public class OrderController {
    private final PlaceOrderUseCase placeOrder;
    private final CancelOrderUseCase cancelOrder;

    public OrderController(PlaceOrderUseCase placeOrder, CancelOrderUseCase cancelOrder) {
        this.placeOrder = placeOrder;
        this.cancelOrder = cancelOrder;
    }

    @PostMapping
    public ResponseEntity<OrderResponse> create(@RequestBody @Valid PlaceOrderCommand command) {
        OrderId id = placeOrder.execute(command);
        return ResponseEntity.status(HttpStatus.CREATED)
            .body(new OrderResponse(id.getValue()));
    }

    @PostMapping("/{id}/cancel")
    public ResponseEntity<Void> cancel(@PathVariable UUID id) {
        cancelOrder.execute(new OrderId(id));
        return ResponseEntity.noContent().build();
    }
}

Step 3: MVC vs WebFlux Decision

Use Spring MVC whenUse WebFlux when
JDBC/JPA/ORM-based persistenceHigh concurrency (>10K req/s)
Standard REST APIStreaming / Server-Sent Events
Team is more familiar with blockingLong-lived connections
Existing MVC infrastructureWebSocket-heavy application
Transactional database operationsReactive database (R2DBC, MongoDB)
Mature library support neededBackpressure-aware processing

Step 4: Configuration Management

java
@Configuration
@ConfigurationProperties(prefix = "feature.order")
public class OrderConfig {
    private int maxItemsPerOrder = 50;
    private Duration paymentTimeout = Duration.ofSeconds(300);
    private List<String> supportedCurrencies = List.of("USD", "EUR");
    private boolean autoConfirmEnabled = true;

    public int getMaxItemsPerOrder() { return maxItemsPerOrder; }
    public void setMaxItemsPerOrder(int maxItemsPerOrder) { this.maxItemsPerOrder = maxItemsPerOrder; }
    public Duration getPaymentTimeout() { return paymentTimeout; }
    public void setPaymentTimeout(Duration paymentTimeout) { this.paymentTimeout = paymentTimeout; }
    public List<String> getSupportedCurrencies() { return supportedCurrencies; }
    public void setSupportedCurrencies(List<String> supportedCurrencies) { this.supportedCurrencies = supportedCurrencies; }
    public boolean isAutoConfirmEnabled() { return autoConfirmEnabled; }
    public void setAutoConfirmEnabled(boolean autoConfirmEnabled) { this.autoConfirmEnabled = autoConfirmEnabled; }
}

// application.yml
feature:
  order:
    max-items-per-order: 50
    payment-timeout-seconds: 300
    supported-currencies: USD, EUR
    auto-confirm-enabled: true

spring:
  datasource:
    url: ${DB_URL}
    username: ${DB_USER}
    password: ${DB_PASS}
  jpa:
    hibernate:
      ddl-auto: validate
    show-sql: false

Step 5: Exception Mapping with ControllerAdvice

java
@ControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(OrderNotFoundException.class)
    public ResponseEntity<ErrorResponse> handleNotFound(OrderNotFoundException ex) {
        return ResponseEntity.status(HttpStatus.NOT_FOUND)
            .body(new ErrorResponse("NOT_FOUND", ex.getMessage()));
    }

    @ExceptionHandler(OrderValidationException.class)
    public ResponseEntity<ErrorResponse> handleValidation(OrderValidationException ex) {
        return ResponseEntity.status(HttpStatus.BAD_REQUEST)
            .body(new ErrorResponse("VALIDATION", ex.getMessage(), ex.getErrors()));
    }

    @ExceptionHandler(MethodArgumentNotValidException.class)
    public ResponseEntity<ErrorResponse> handleMethodValidation(MethodArgumentNotValidException ex) {
        List<String> errors = ex.getBindingResult().getFieldErrors().stream()
            .map(e -> e.getField() + ": " + e.getDefaultMessage())
            .toList();
        return ResponseEntity.status(HttpStatus.BAD_REQUEST)
            .body(new ErrorResponse("VALIDATION", "Input validation failed", errors));
    }

    @ExceptionHandler(Exception.class)
    public ResponseEntity<ErrorResponse> handleGeneral(Exception ex) {
        log.error("Unhandled exception", ex);
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
            .body(new ErrorResponse("INTERNAL_ERROR", "An unexpected error occurred"));
    }
}

public record ErrorResponse(String code, String message, Object details) {
    public ErrorResponse(String code, String message) {
        this(code, message, null);
    }
}

Step 6: Testing with Hexagonal Architecture

java
@SpringBootTest
@AutoConfigureMockMvc
class OrderControllerTest {

    @Autowired private MockMvc mockMvc;
    @MockitoBean private PlaceOrderUseCase placeOrderUseCase;

    @Test
    void shouldCreateOrder() throws Exception {
        OrderId orderId = new OrderId(UUID.randomUUID());
        when(placeOrderUseCase.execute(any(PlaceOrderCommand.class)))
            .thenReturn(orderId);

        mockMvc.perform(post("/v1/orders")
                .contentType(MediaType.APPLICATION_JSON)
                .content("""
                    {"customerId":"cust-1","items":[{"productId":"prod-1","quantity":2,"unitPrice":19.99}]}
                """))
            .andExpect(status().isCreated())
            .andExpect(jsonPath("$.id").value(orderId.getValue().toString()));
    }

    @Test
    void shouldReturn400ForInvalidInput() throws Exception {
        mockMvc.perform(post("/v1/orders")
                .contentType(MediaType.APPLICATION_JSON)
                .content("""{"customerId":""}"""))
            .andExpect(status().isBadRequest());
    }
}

Architecture Decision Trees

Packaging Strategy

Feature count > 20?
  +-- Yes -> Can domain boundaries change?
  |   +-- Yes -> Package by feature (recommended)
  |   +-- No  -> Package by layer (only for tiny projects)
  +-- No  -> Package by feature (always default)

Hexagonal vs Layered

Need to swap infrastructure (DB, messaging) independently?
  +-- Yes -> Hexagonal (ports/adapters). Domain has zero framework deps.
  +-- No  -> Layered is simpler. Accept package coupling.

MVC vs WebFlux

Primary DB is relational (JPA/JDBC)?
  +-- Yes -> Use MVC. JPA is blocking, doesn't benefit from reactive.
  +-- No  -> Need >10K concurrent connections?
      +-- Yes -> WebFlux with R2DBC or MongoDB
      +-- No  -> MVC is simpler and better-supported

Common Pitfalls

  1. @Autowired field injection: Makes testing impossible without Spring context. Always use constructor injection.

  2. @Transactional at controller level: Too coarse. One controller method may call multiple services. Keep @Transactional at application service.

  3. Domain entities with JPA annotations: Pure domain objects should be POJOs. JPA entities are infrastructure concerns mapped separately.

  4. Circular dependencies between services: Usually signals missing domain concept. Extract shared logic into a third service.

  5. Service/Repository interfaces in the wrong layer: Domain defines the interface (port), infrastructure implements it (adapter).

  6. Using @Entity for domain entities: Creates tight coupling to JPA. Map JPA entities to domain objects via a mapper.

  7. LazyInitializationException: Accessing lazy-loaded relations outside a transaction. Use JOIN FETCH or entity graphs.

  8. Giant application service classes: More than 10 methods per service suggests missing domain subdivisions.

  9. @MockBean overuse in tests: Prefer @MockitoBean (Spring Boot 3.4+) or test slices for focused tests.

  10. Missing @Validated on @ConfigurationProperties classes: Properties binding silently fails without proper validation.

Best Practices

  1. Domain entities validated in constructors. Use factory methods like Order.create() that enforce invariants.

  2. @ExceptionHandler in @ControllerAdvice maps domain exceptions to HTTP. Controllers never have try-catch for domain logic.

  3. @Valid on controller request bodies for input validation. Domain entities are validated in domain constructors.

  4. @Profile for environment-specific beans. Dev, test, staging, production configurations are explicit.

  5. Spring Data JPA specifications for dynamic queries. Avoid creating repository methods for every query combination.

  6. Audit fields (createdAt, updatedAt) in base entity. Use @EnableJpaAuditing and @CreatedDate/@LastModifiedDate.

  7. Fluent builder pattern for complex domain objects. Avoid telescoping constructors.

  8. Record types for DTOs. Java 16+ records reduce boilerplate.

Compared With

FeatureSpring Boot MVCSpring Boot WebFluxQuarkus
Startup time2-4s2-4s<0.3s
Memory footprint~150MB~150MB~50MB
GraalVM supportLimitedLimitedFirst-class
Reactive supportNoYesYes (via RESTEasy Reactive)
JPA supportFullVia Hibernate ReactiveVia Panache
Testing@SpringBootTest@WebFluxTest@QuarkusTest
OpenAPIspringdoc-openapispringdoc-openapiSmallRye OpenAPI

Performance

  • Startup time: 2-4 seconds (depends on classpath scanning). Use @ComponentScan lazy initialization to reduce.
  • Memory: ~150MB base. Use -Xmx and -Xms flags to control.
  • Connection pool: HikariCP with 10 connections default. Tune based on DB max connections.
  • Response compression: Enable server.compression.enabled=true for text payloads.
  • Caching: Spring Cache abstraction with Redis/Caffeine for repeatable queries.
  • JPA batch size: spring.jpa.properties.hibernate.jdbc.batch_size=20 for bulk operations.
  • Read-only transactions: Mark queries as @Transactional(readOnly=true) for DB optimizations.

Tooling

ToolPurpose
Spring InitializrProject scaffolding
springdoc-openapiOpenAPI 3 documentation generation
MapStructEntity-DTO mapping code generation
LombokBoilerplate reduction
TestcontainersIntegration testing with real databases
ArchUnitArchitecture rule enforcement
Checkstyle / PMDCode quality
JaCoCoCode coverage
Gradle Enterprise / MavenBuild tooling
Spring Boot ActuatorHealth checks, metrics

Rules

  • Domain package has ZERO Spring framework imports.
  • Controller/Service/Repository stereotypes belong in presentation/application/infrastructure respectively.
  • Constructor injection always. Never @Autowired on fields.
  • @Transactional at application service level only. Never in controllers.
  • @ExceptionHandler in @ControllerAdvice maps domain exceptions to HTTP.
  • @Valid on controller request bodies for input validation.
  • Domain entities validated in constructors/factory methods.
  • Package-by-feature with hexagonal ports/adapters.
  • @Entity classes are infrastructure, not domain.
  • DTOs are Java records or plain classes, never reused across layers.
  • @ConfigurationProperties for type-safe external config.
  • Tests at controller level use MockMvc or WebTestClient.
  • @SpringBootTest only for integration tests. Use test slices for unit tests.
  • Profile-specific application-{profile}.yml files for environment separation.

References

  • references/spring-boot-auto-configuration.md — Spring Boot Auto-Configuration
  • references/spring-boot-testing-strategies.md — Spring Boot Testing Strategies
  • references/layered-architecture.md — Spring Boot Layered Architecture
  • references/reactive-webflux.md — Spring WebFlux Patterns
  • references/spring-boot-data-access.md — Spring Boot Data Access
  • references/spring-boot-observability.md — Spring Boot Observability
  • references/spring-boot-security.md — Spring Boot Security
  • references/spring-boot-testing.md — Spring Boot Testing

Shared References

Additional reference material for this skill, stored outside its own references/ folder.

  • ../references/architecture-patterns.md — Architecture Patterns in Spring Boot 3
  • ../references/code-organization.md — Code Organization in Spring Boot
  • ../references/deployment-pipelines.md — Deployment Pipelines in Spring Boot
  • ../references/error-handling.md — Error Handling in Spring Boot
  • ../references/performance-optimization.md — Performance Optimization in Spring Boot
  • ../references/security-best-practices.md — Security Best Practices in Spring Boot
  • ../references/state-management.md — State Management in Spring Boot
  • ../references/testing-strategies.md — Testing Strategies in Spring Boot

Handoff

No artifact produced. Next skill: backend-testing — test Spring Boot. Carry forward: package structure, DI configuration, persistence strategy (JPA/R2DBC).

Bundled files

The model reads these on demand while the skill is loaded. They are exposed as readable files and are never executed.

Frequently asked questions

What does the Spring Boot Architecture AI skill do?

Use this skill when the user says 'Spring Boot structure', 'Spring architecture', 'Spring Boot clean arch', 'Spring layered', 'Spring hexagonal', 'Spring WebFlux', 'Spring Data', 'Spring Boot folder', or when building a Spring Boot application. This skill enforces: package-by-feature (not by layer), hexagonal architecture with ports and adapters, Spring stereotypes correctly applied (@Repository in infrastructure, not domain), constructor injection (no @Autowired on fields), and MVC vs WebFlux decision guide. Requires Spring Boot (pom.xml or build.gradle). Do NOT use for: Kotlin Multiplatfo...

Why use Spring Boot Architecture on TypingMind?

Because you install it once and use it with any model. Spring Boot Architecture is plain Markdown rather than provider-specific code, so the same skill runs on GPT-5, Claude, Gemini, Grok, or a local model — and you can switch model mid-chat without it breaking. TypingMind runs on your own API keys, so you pay providers directly instead of a per-seat subscription, and your skills and chats stay in your own storage.

How do I install Spring Boot Architecture in TypingMind?

Open Plugins → Skills → Install from GitHub in TypingMind and paste https://github.com/j4flmao/agent-skills/tree/main/skills/backend/spring-boot/architecture. TypingMind reads its SKILL.md and bundles its files and installs it as a skill you can enable per chat.

Which AI models can use Spring Boot Architecture?

Any model you connect in TypingMind. AI skills are plain Markdown instructions rather than provider-specific code, so GPT, Claude, Gemini, Grok, and local models can all load this skill when a request matches it.

How many AI models can I use with Spring Boot Architecture?

As many as you like. As long as a model supports skills, you can use Spring Boot Architecture with it — GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama and more — all on TypingMind with your own API keys.

Is the Spring Boot Architecture AI skill free?

Yes. It is published on GitHub by j4flmao under the MIT license. You only pay your own AI provider for the tokens you use.

What are AI skills?

An AI skill is a reusable instruction bundle that teaches an AI model how to do one specific task. It follows the open Agent Skills format: a SKILL.md file with a name and description, plus any scripts, templates or reference files the model may need. The model reads the instructions only when your request matches the skill, so an installed skill costs nothing until it is used.

How are AI skills different from plugins or MCP servers?

A plugin or MCP server gives a model new tools to call — code that runs somewhere and returns a result. An AI skill gives the model knowledge and process instead: how to approach a task, which steps to follow, what good output looks like. Skills are plain Markdown, so they need no server, no API key and no runtime, and they work with any model.

View all

Set up your own AI workspace now

Get notified about new features and future giveaways by subscribing to our newsletter 👇