refactor: clean-architecture적으로 책임 분리 및 예외 및 검증 강화, 디자인패턴 적용
This commit is contained in:
+16
-7
@@ -295,7 +295,7 @@ R1은 `registrationEndAt` 정각까지 포함한다. 따라서 `now.isAfter(regi
|
||||
|
||||
### 5.5 구현 메모
|
||||
|
||||
- application은 `RegistrationContextLoader` port만 알고, `JpaRegistrationContextLoader`가 실제 User → Lesson 락 순서와 JPA 조회 전략을 구현한다
|
||||
- application은 `RegistrationExecutionScopeLoader.open()`으로 실행 범위를 확보한다. 실제 User → Lesson `FOR UPDATE`는 `JpaRegistrationExecutionScopeLoader`가 구현하고 application contract에는 lock 용어를 노출하지 않는다
|
||||
- Spring Data Repository의 `@Lock(LockModeType.PESSIMISTIC_WRITE)`는 infrastructure adapter 뒤에서만 사용한다
|
||||
- `RegisterCourseUseCase`/`CancelRegistrationUseCase` mutation 전체에 `@Transactional`을 건다. 락은 커밋 시점에 풀린다
|
||||
- H2와 PostgreSQL 모두 `FOR UPDATE`를 지원하지만 **락 타임아웃 적용 방식은 같지 않다**
|
||||
@@ -646,17 +646,26 @@ User 락은 R5~R7 직렬화와 일관된 판정을 담당하고, DB UNIQUE는 R4
|
||||
| `web/error` | `ApiExceptionHandler`, `FailureHttpMapper`, `FailureMetrics` | failure → HTTP/log/metric 표현 |
|
||||
| `application/registration` | `RegisterCourseUseCase`, `CancelRegistrationUseCase`, `GetRegistrationsQuery` | transaction과 업무 흐름 orchestration |
|
||||
| `application/lesson` | `GetLessonsQuery`, `GetLessonQuery` | 강의 조회 UseCase |
|
||||
| `application/idempotency` | `IdempotencyPolicy`, `CleanupIdempotencyUseCase` | replay/TTL/cleanup 의미 |
|
||||
| `application/*/port` | `RegistrationContextLoader`, `RegistrationReader`, `RegistrationWriter`, `LessonQueryPort`, `SemesterQueryPort`, `IdempotencyPort` | application이 요구하는 persistence capability |
|
||||
| `domain/registration` | `RegistrationContext`, `RegistrationPolicy`, `RegistrationRule` | decision data와 ordered policy |
|
||||
| `application/idempotency` | `IdempotencyCoordinator`, `CleanupIdempotencyUseCase` | normalize/TTL/replay 판정/record orchestration |
|
||||
| `application/*/port` | `RegistrationExecutionScopeLoader`, `RegistrationDecisionContextLoader`, `CancellationContextLoader`, `RegistrationReader`, `RegistrationWriter`, `LessonQueryPort`, `SemesterQueryPort`, `IdempotencyPort` | application이 요구하는 업무 capability |
|
||||
| `domain/registration` | `RegistrationContext`, snapshot, `RegistrationPolicy`, `RegistrationWindowGuard` | persistence와 독립된 신청 decision model/policy |
|
||||
| `domain/registration/rule` | R1~R8 rule | 한 규칙당 한 변경 이유 |
|
||||
| `domain/schedule` | `LessonSchedulePolicy`, `ScheduleConflictChecker` | 시간표 invariant/충돌 |
|
||||
| `infrastructure/persistence` | `Jpa*Adapter`, `JpaRegistrationContextLoader` | Spring Data/JPA query, lock, pagination, projection |
|
||||
| `domain/schedule` | `ScheduleSlot`, `LessonSchedulePolicy`, `ScheduleConflictChecker` | persistence와 독립된 시간표 invariant/충돌 |
|
||||
| `infrastructure/persistence` | `Jpa*Adapter`, `JpaRegistrationExecutionScopeLoader`, `JpaRegistrationDecisionContextLoader`, `JpaCancellationContextLoader`, `JpaSnapshotMapper` | JPA Entity ↔ snapshot/read model 변환, query, lock, pagination |
|
||||
| `infrastructure/scheduling` | `IdempotencyRetentionJob` | scheduler adapter |
|
||||
| `failure` | `ApplicationFailure`, `SystemInvariantViolation` | HTTP와 독립된 실패 의미 |
|
||||
| `infrastructure/persistence/repository` | Spring Data repository | JPA adapter가 사용하는 persistence mechanism |
|
||||
|
||||
의존 방향은 `web -> application -> domain/port <- infrastructure`를 유지한다. `ArchitectureTest`가 application의 raw repository/Spring Data JPA 접근, domain의 상위 계층 접근, web의 infrastructure 직접 접근을 금지한다.
|
||||
의존 방향은 `web -> application -> domain/port <- infrastructure`를 유지한다.
|
||||
|
||||
아키텍처 정책은 **strict clean boundary**로 고정한다.
|
||||
|
||||
- Application/Domain에는 JPA Entity가 전달되지 않는다.
|
||||
- Port는 snapshot/read model/command만 사용한다.
|
||||
- Domain은 Spring Framework/JPA annotation에 의존하지 않는다.
|
||||
- Spring wiring은 `config/DomainPolicyConfig`에서 수행한다.
|
||||
- Query는 `LessonListView`, `LessonDetailView`, `ActiveRegistrationView` 같은 read model을 infrastructure에서 조립한다.
|
||||
- `ArchitectureTest`가 위 의존 규칙을 자동 검증한다.
|
||||
|
||||
---
|
||||
|
||||
|
||||
Reference in New Issue
Block a user