agentleFS
yeochul-jeonyeochul-jeon/spring-boot-claude-skill/skills/spring-principles/SKILL.md

spring-principles

Skill3 starsChanged 7 months agoMITView on GitHub

Use whenever writing, reviewing, or refactoring Java/Spring

The file

Files
SKILL.md

Spring Principles

Spring/Java 코드를 작성·리뷰·리팩터링할 때 적용할 설계 원칙 모음. 다른 모든 spring-* 스킬은 완료 직전에 이 스킬의 체크리스트로 자가 검증한다.

절대 원칙

  1. 필드 주입 금지 — 생성자 주입 + final 필드. Lombok @RequiredArgsConstructor 또는 명시 생성자.
  2. Controller는 Entity를 직접 반환·수신하지 않는다 — DTO 매핑 필수.
  3. Anemic domain 회피 — 비즈니스 규칙은 Entity/VO 내부에 둔다.

자가 검증 체크리스트

Spring 코드 완성 직전 아래 항목을 전부 확인한다. 위반 항목은 templates/ 의 Before/After 가이드를 적용해 수정한다.

DI & 의존성

  • @Autowired 필드 주입이 없음
  • 주입 받는 모든 필드가 private final
  • 생성자가 하나면 @RequiredArgsConstructor, 여럿이면 명시 생성자 + @Bean

계층 분리

  • Controller가 Entity를 직접 반환하지 않음 (DTO 매핑)
  • Controller가 Repository를 직접 호출하지 않음
  • Service 계층에 @Transactional 이 위치함
  • @Transactional(readOnly = true) 를 조회 메서드에 적용했는가

Domain

  • 비즈니스 규칙(검증, 상태 전이)이 Service가 아닌 Entity/VO 내부에 있음
  • Primitive Obsession이 있는 값(금액·이메일·주소 등)은 VO로 추출했는가
  • VO는 setter가 없다 (불변) — record 또는 생성자만 허용

테스트 용이성

  • new로 직접 생성 가능한 클래스 (불필요한 정적 의존 없음)
  • @Bean은 @Configuration 에만 있음

grep 자동 검증 패턴

체크리스트 실행 전 아래 명령으로 명백한 위반을 빠르게 탐지한다. <SRC> 는 프로젝트의 src/main/java 절대 경로.

# A: @Autowired 필드 주입 탐지
grep -rn "@Autowired" <SRC>

# B: Controller 메서드가 Entity를 직접 반환하는지 (타입명 기반 — 수동 확인 병행)
grep -rn "public.*Entity\b\|public Order\|public Product\|public Member" <SRC>/*/controller/

# C: @Transactional이 Controller에 잘못 위치
grep -rn "@Transactional" <SRC>/*/controller/

# F: VO에 setter 존재 (불변성 위반)
grep -rn "public void set" <SRC>/*/domain/Money.java <SRC>/*/domain/*Vo.java 2>/dev/null

# G: private final 필드 전무 (생성자 주입 미사용)
grep -rn "private final" <SRC> | wc -l   # 0 이면 경고

결과가 있으면 해당 templates/ Before→After 를 적용한다.

사용법

다른 스프링 스킬(spring-init, spring-web, spring-persistence 등)에서 코드를 작성하고 나면 이 SKILL.md를 읽고 체크리스트를 실행한다. 위반 항목이 발견되면:

  1. templates/<해당-패턴>.md 의 ## Before → ## After 변환을 적용한다.
  2. 변환 이유를 ## 왜 섹션으로 사용자에게 설명한다.

references/ 목록

파일설명
di.md생성자 주입 원칙, 순환 참조 탐지
separation-of-concerns.mdController/Service/Repository 각 책임, @Transactional 경계
testability.md테스트하기 쉬운 설계 기준
rich-domain.mdEntity에 행위 부여, VO 도입
anti-patterns.md흔한 안티패턴 목록

templates/ 목록

파일변환
constructor-injection.md필드 주입 → 생성자 주입
dto-entity-separation.mdEntity 직접 반환 → DTO 매핑
rich-domain.mdAnemic Entity + Service 로직 → Entity 메서드
template-method-pattern.md반복 try-catch → 템플릿 메서드
value-object.mdPrimitive 타입 → VO

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.