Allra 백엔드 API 설계 및 패키지 구조 규칙. Use when creating REST APIs, DTOs, or organizing backend code structure.
This skill inherits all available tools. When active, it can use any tool Claude has access to.
Allra 백엔드 팀의 API 설계, DTO 네이밍, 패키지 구조 표준을 정의합니다.
이 가이드는 다음 환경을 기준으로 작성되었습니다:
참고: 프로젝트별로 사용하는 기술 스택이나 버전이 다를 수 있습니다. 프로젝트에 맞게 조정하여 사용하세요.
도메인별 패키지 구조를 권장합니다:
└── {domain}
├── api // 컨트롤러 레이어
├── dto // 데이터 전송 객체
├── entity // JPA 엔티티
├── enums // Enum 정의 (선택)
├── repository // 데이터 접근 계층
└── service // 비즈니스 로직
참고: 프로젝트에 따라 controller, model, dao 등 다른 이름을 사용할 수 있습니다. 중요한 것은 레이어별 책임을 명확히 분리하는 것입니다.
└── user
├── api
│ └── UserController.java
├── dto
│ ├── UserSignUpEventDto.java // 내부 사용
│ ├── request
│ │ └── SignUpRequest.java
│ └── response
│ └── SignUpResponse.java
├── entity
│ └── User.java
├── repository
│ ├── UserRepository.java
│ └── UserRepositorySupport.java
└── service
└── UserService.java
{Operation}Request
SignUpRequest, UpdateUserRequest{Operation}Response
SignUpResponse, UserDetailResponse내부에서만 사용하는 DTO는 Dto 접미사 추가:
UserSignUpEventDto, UserSummaryDtoDTO 같은 단순 클래스들은 가능하면 대부분 record로 생성
// Request/Response
public record SignUpRequest(
String email,
String password,
String name
) {}
public record SignUpResponse(
Long userId,
String email
) {}
// 내부 사용 DTO
public record UserSignUpEventDto(
Long userId,
String email,
LocalDateTime signUpAt
) {}
@RestController
@RequestMapping("/api/v1/users")
public class UserController {
// GET /api/v1/users - 목록 조회
@GetMapping
public List<UserResponse> getUsers() { }
// GET /api/v1/users/{id} - 단건 조회
@GetMapping("/{id}")
public UserDetailResponse getUser(@PathVariable Long id) { }
// POST /api/v1/users - 생성
@PostMapping
public SignUpResponse createUser(@RequestBody @Valid SignUpRequest request) { }
// PUT /api/v1/users/{id} - 전체 수정
@PutMapping("/{id}")
public UserResponse updateUser(
@PathVariable Long id,
@RequestBody @Valid UpdateUserRequest request
) { }
// PATCH /api/v1/users/{id} - 부분 수정
@PatchMapping("/{id}")
public UserResponse patchUser(
@PathVariable Long id,
@RequestBody @Valid PatchUserRequest request
) { }
// DELETE /api/v1/users/{id} - 삭제
@DeleteMapping("/{id}")
public void deleteUser(@PathVariable Long id) { }
}
참고: API 버저닝(/api/v1/...)은 프로젝트 정책에 따라 선택적으로 적용합니다.
모든 Request DTO는 Bean Validation 사용:
public record SignUpRequest(
@NotBlank(message = "이메일은 필수입니다")
@Email(message = "올바른 이메일 형식이 아닙니다")
String email,
@NotBlank(message = "비밀번호는 필수입니다")
@Size(min = 8, message = "비밀번호는 최소 8자 이상이어야 합니다")
String password,
@NotBlank(message = "이름은 필수입니다")
String name
) {}
Allra 표준 형식 (예시):
성공 응답:
{
"data": { ... },
"message": "요청이 성공적으로 처리되었습니다"
}
에러 응답:
{
"error": {
"code": "USER_NOT_FOUND",
"message": "사용자를 찾을 수 없습니다",
"details": []
}
}
참고: 응답 형식은 프로젝트별로 다를 수 있습니다. 일관성 있는 형식을 유지하는 것이 중요합니다.
이 skill은 다음 상황에서 자동으로 적용됩니다:
// 1. 패키지 구조 생성
kr.co.allra.product/
├── api/ProductController.java
├── dto/
│ ├── request/CreateProductRequest.java
│ └── response/ProductResponse.java
├── entity/Product.java
├── repository/ProductRepository.java
└── service/ProductService.java
// 2. Request DTO
public record CreateProductRequest(
@NotBlank String name,
@NotNull BigDecimal price
) {}
// 3. Response DTO
public record ProductResponse(
Long id,
String name,
BigDecimal price,
LocalDateTime createdAt
) {}
// 4. Controller
@RestController
@RequestMapping("/api/v1/products")
public class ProductController {
@PostMapping
public ProductResponse createProduct(
@RequestBody @Valid CreateProductRequest request
) {
return productService.createProduct(request);
}
}
// QueryDSL 결과를 위한 내부 DTO
public record ProductSummaryDto(
Long id,
String name,
Long orderCount
) {
@QueryProjection
public ProductSummaryDto {}
}
// 이벤트 전달용 내부 DTO
public record ProductCreatedEventDto(
Long productId,
String productName,
LocalDateTime createdAt
) {}
새로운 API를 만들 때 확인사항:
Dto 접미사가 있는가?