← スキル一覧に戻る

spring-api-rules
by Griotold
spring boot 4, java 25, sns, Cladue Code
⭐ 0🍴 0📅 2026年1月19日
SKILL.md
name: spring-api-rules description: Define controllers, services, repositories, entities, DTOs for Spring Boot REST API. Use when user mentions API, endpoint, controller, service, repository, entity, DTO, CRUD, domain, feature, function, or REST creation. allowed-tools: Read, Write, Edit, Glob, Grep, Bash, LSP
Spring API Development Rules
Standard rules for Spring Boot REST API development in this project.
Package Structure
com.apiece.springboot_sns_sample
├── controller/ # REST API controllers
│ └── dto/ # Request/Response DTOs
├── domain/ # Domain packages
│ └── user/ # User domain
│ ├── User.java # Entity
│ ├── UserRepository.java
│ ├── UserService.java
│ └── UserException.java
└── config/ # Configuration classes
Common Rules
- Constructor injection using
@RequiredArgsConstructorwhere possible - No field injection (
@Autowiredon fields) @ConfigurationPropertiesclasses should be written as records- Use Lombok
@Getteractively for entities and classes (except DTOs which use records)
Controller
- Use
@RestController - Do not use
@RequestMappingat class level; write full endpoint path on each method - Return type:
ResponseEntity<T> - Naming:
*Controller
DTO
- Only controller DTOs go in
controller/dtopackage - Use Java
record - Request:
toEntity()method - Response:
from(Entity)static factory
Domain
Each domain is organized under domain/{domainName}/ package:
{Domain}.java- Entity{Domain}Repository.java- Data access{Domain}Service.java- Business logic{Domain}Exception.java- Domain exception
Entity
protecteddefault constructor@GeneratedValue(strategy = GenerationType.IDENTITY)- Associations:
FetchType.LAZYby default - No FK constraints in database; use
@JoinColumnwithout FK constraints
Repository
- Extends
JpaRepository<Entity, ID> - Follow Spring Data JPA query method naming conventions
Service
- Use
@Transactionalonly when necessary:- Use when multiple write operations must be in a single transaction
- Use when Dirty Checking is needed (entity modification without explicit save)
- Do NOT use for single Repository operations (they handle transactions automatically)
- Do NOT use for simple read operations
Exception Handling
- Domain exceptions:
domain/{domainName}/{Domain}Exception.java - Global handling with
@RestControllerAdvice
API Shell Script
When creating a new API, create a shell script in src/main/resources/http/:
- File naming: lowercase with resource name (e.g.,
post.sh,follow.sh) - Include curl commands for all endpoints (POST, GET, PUT, DELETE)
- Use
BASE_URL="http://localhost:8080"variable - Use
-b cookies.txtfor authenticated requests - Add descriptive echo statements before each curl command
- Start with
#!/bin/bashshebang
スコア
総合スコア
40/100
リポジトリの品質指標に基づく評価
✓SKILL.md
SKILL.mdファイルが含まれている
+20
○LICENSE
ライセンスが設定されている
0/10
○説明文
100文字以上の説明がある
0/10
○人気
GitHub Stars 100以上
0/15
○最近の活動
3ヶ月以内に更新がある
0/10
○フォーク
10回以上フォークされている
0/5
✓Issue管理
オープンIssueが50未満
+5
✓言語
プログラミング言語が設定されている
+5
○タグ
1つ以上のタグが設定されている
0/5
レビュー
💬
レビュー機能は近日公開予定です