Skip to content
Back to skills

Spring Boot Service Design

ASecurity

Structures a Spring Boot service into thin controllers, transactional services and typed config, tested with slice tests instead of full context starts.

  • 3 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added November 15, 2026
ai-agentsjavaspringapi

Works with

  • api

Security analysis

A100/100

Scanned November 15, 2026

npx -y skills add workspace-templates/ai-agent-templates --skill spring-boot-service-design --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Spring Boot Service Design?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Spring Boot Service Design
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/workspace-templates-spring-boot-service-design/badge)](https://www.skillsdirectory.com/skills/workspace-templates-spring-boot-service-design)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: spring-boot-service-design
description: Structures a Spring Boot service into thin controllers, transactional services and typed config, tested with slice tests instead of full context starts.
---

# Spring Boot service design

Thin controllers, transactional services, typed config, sliced tests.

## Steps

1. Package by feature (`orders`, `billing`), not by layer. Inside each: `OrderController`, `OrderService`, `OrderRepository`, DTO records and the entity.
2. Controllers only translate HTTP: bind and validate (`@Valid`, Bean Validation annotations), call one service method, map to a response record. No repository calls, no business rules.
3. Services own the rules and the transaction boundary: `@Transactional` on the public method, `readOnly = true` for queries. Do not annotate controllers or repositories for transactions.
4. Never return JPA entities from controllers. Use Java records as request and response DTOs, mapped explicitly, so a column change never changes the API.
5. Use constructor injection only (one constructor needs no annotation). No field `@Autowired`.
6. Replace scattered `@Value` with `@ConfigurationProperties` on a record, with `@Validated` constraints, so a missing setting stops startup with a clear message.
7. Handle errors in one `@RestControllerAdvice` that maps domain exceptions to ProblemDetail responses.
8. Test by slice: `@WebMvcTest` with `MockMvc` and a mocked service for controllers; `@DataJpaTest` with Testcontainers for repositories; plain JUnit with mocks for services. Keep `@SpringBootTest` for a few end-to-end checks.
9. Guard against lazy loading traps: set `spring.jpa.open-in-view=false` and fetch what a use case needs with explicit queries or `@EntityGraph`.

## Rules

- Never put business logic in a controller or an entity setter chain.
- Never catch `Exception` in a service to hide it.

## Report

Structure created or changed, settings flipped, and tests added with their run time.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.