클린 레이어드 아키텍처
/src
├── user
│ ├── domain
│ ├── application
│ ├── infrastructure
│ └── interface/presentation
│
├── order
│ ├── domain
│ ├── application
│ ├── infrastructure
│ └── interface/presentation
│
├── product
│ ├── domain
│ ├── application
│ ├── infrastructure
│ └── interface/presentation
│
├── shared (공통 유틸, 에러 핸들링, 베이스 클래스)
│
└── config (전체 설정, DI 컨테이너, 라우팅 등)
클린 아키텍처 내부 코딩 규칙 체크리스트
구체적인 레이어드 구조
/src
├── user
│ ├── domain
│ │ ├── entity
│ │ │ └── User.java
│ │ ├── valueobject
│ │ │ └── UserId.java
│ │ ├── repository
│ │ │ └── UserRepository.java
│ │ └── service
│ │ └── UserDomainService.java
│ │
│ ├── application
│ │ ├── usecase
│ │ │ ├── RegisterUserUseCase.java
│ │ ├── dto
│ │ │ ├── RegisterUserCommand.java
│ │ │ ├── RegisterUserResponse.java
│ │ └── service
│ │ └── UserApplicationService.java (필요시 UseCase 통합 관리용)
│ ├── infrastructure
│ │ ├── repository
│ │ │ └── UserRepositoryImpl.java (UserRepository 인터페이스 구현체 class!)
│ │ │ └── UserJPARepository.java (Spring Data JPA를 연결한 진짜 Interface)
│ │ ├── Entity
│ │ │ └── UserEntity.java (DB테이블 매핑용 Entity)
│ │ ├── mapper
│ │ └── UserEntityMapper.java (Entity <-> Domain 매핑)
│ │
│ └── interface(Presntation)
│ ├── controller
│ │ └── UserController.java (UserController)
│ └── dto
│ ├── RegisterUserRequest.java
│ ├── RegisterUserResponse.java
│ ├── SendUserEmailRequest.java
│ └── SendUserEmailResponse.java
[HTTP Request]
↓
[UserController] (RequestDTO 수신 → Command 변환 → UseCase 호출)
↓
[RegisterUserUseCase] (Command 수신 → Domain 로직 호출 → 저장)
↓
[User Entity] (비즈니스 규칙 적용 및 생성)
↓
[UserRepository] (Domain Interface → Infra 구현체)
↓
[UseCase] (결과 반환)
↓
[UserController] (ResponseDTO 변환 후 클라이언트에 응답)
[UseCase]
↓
[UserRepository (Domain Interface)]
↓
[UserRepositoryImpl (Infrastructure Adapter)]
↓
[UserJPARepository (Spring Data JPA)]
↓
[UserEntity (DB 테이블 매핑)]
RegisterUserUseCase, CreateOrderUseCase 등 명확한 행동 하나)execute(), handle())UseCase는 명확하고 엄격한 책임 구분이 있다. 하지만 만드는데 매우 큰 보수가 드며, 초반 비용이 비싸다.
MVC방식은 간단하고 유연한 관리 방식, SRP 위반 위험이 존재한다.