개발

헥사고날 아키텍처로 가기위한 기존 코드에 solid 적용 완료

정재익 2025. 8. 11. 18:46

헥사고날 아키텍처로의 전환 이전에 기본 soild를 준수하기 위해서
수만 줄의 코드를 수정하는 대공사를 진행했습니다.
 
개선 전 디렉토리 구조

  ├── controller/          # REST API 컨트롤러
  │   ├── AdminController.java        # 관리자 기능
  │   ├── AuthController.java         # 인증/로그인
  │   ├── CommentController.java      # 댓글 관리
  │   ├── NotificationController.java # 알림 기능
  │   ├── PaperController.java        # 롤링페이퍼
  │   ├── PostController.java         # 게시글 관리
  │   └── UserController.java         # 사용자 관리
  │
  ├── dto/                 # 데이터 전송 객체
  │   ├── auth/           # 인증 관련 DTO
  │   ├── comment/        # 댓글 관련 DTO
  │   ├── kakao/          # 카카오 API 관련 DTO
  │   ├── notification/   # 알림 관련 DTO
  │   ├── paper/          # 롤링페이퍼 관련 DTO
  │   ├── post/           # 게시글 관련 DTO
  │   └── user/           # 사용자 관련 DTO
  │
  ├── entity/             # JPA 엔티티
  │   ├── BaseEntity.java # 공통 엔티티 (생성일, 수정일)
  │   ├── comment/        # 댓글 엔티티
  │   ├── message/        # 메시지 엔티티
  │   ├── notification/   # 알림 엔티티
  │   ├── post/           # 게시글 엔티티
  │   ├── report/         # 신고 엔티티
  │   └── user/           # 사용자 엔티티
  │
  ├── global/             # 공통/전역 설정
  │   ├── auth/           # JWT, 카카오 인증 설정
  │   ├── config/         # Redis, QueryDSL 등 설정
  │   ├── event/          # 이벤트 처리
  │   ├── exception/      # 예외 처리
  │   ├── filter/         # JWT 필터
  │   ├── listener/       # 이벤트 리스너
  │   └── security/       # 보안 설정, 암호화
  │
  ├── repository/         # 데이터 액세스 계층
  │   ├── admin/          # 관리자 저장소
  │   ├── comment/        # 댓글 저장소
  │   ├── message/        # 메시지 저장소
  │   ├── notification/   # 알림 저장소
  │   ├── post/           # 게시글 저장소
  │   ├── token/          # 토큰 저장소
  │   └── user/           # 사용자 저장소
  │
  ├── service/            # 비즈니스 로직
  │   ├── admin/          # 관리자 서비스
  │   ├── auth/           # 인증 서비스
  │   ├── comment/        # 댓글 서비스
  │   ├── kakao/          # 카카오 API 서비스
  │   ├── notification/   # 알림 서비스
  │   ├── paper/          # 롤링페이퍼 서비스
  │   ├── post/           # 게시글 서비스
  │   ├── redis/          # Redis 캐시 서비스
  │   └── user/           # 사용자 서비스
  │
  └── util/               # 유틸리티 클래스
      └── NotificationUtil.java


개선 후 디렉토리 구조

  ├── controller/              # Primary Adapters (Web Layer)
  │   ├── admin/                  # 관리자 기능 (Query/Command)
  │   ├── auth/                   # 인증/인가 (Command/Query)
  │   ├── comment/                # 댓글 기능 (Query/Command)
  │   ├── notification/           # 알림 기능 (Query/Command/Subscription)
  │   ├── paper/                  # 롤링페이퍼 (Query/Command)
  │   ├── post/                   # 게시글 (Read/Manage/Search/Cache)
  │   └── user/                   # 사용자 (Query/Command/Integration)
  │
  ├── service/                 # Application Layer (Use Cases)
  │   ├── admin/
  │   │   └── resolver/           # 신고 처리 전략 패턴
  │   ├── auth/
  │   │   └── strategy/           # 소셜 로그인 전략 패턴
  │   ├── comment/                # CQRS 패턴 적용
  │   │   ├── read/              # 댓글 조회
  │   │   ├── write/             # 댓글 작성
  │   │   ├── update/            # 댓글 수정
  │   │   ├── delete/            # 댓글 삭제
  │   │   └── like/              # 댓글 좋아요
  │   ├── post/                   # CQRS 패턴 적용
  │   │   ├── read/              # 게시글 조회
  │   │   ├── command/           # 게시글 CUD
  │   │   └── search/            # 게시글 검색
  │   ├── paper/                  # CQRS 패턴 적용
  │   │   ├── read/              # 롤링페이퍼 조회
  │   │   ├── write/             # 메시지 작성
  │   │   └── delete/            # 메시지 삭제
  │   ├── notification/           # Facade + Strategy 패턴
  │   ├── user/                   # 사용자 관리
  │   └── redis/                  # 캐시 서비스
  │
  ├── repository/              # Secondary Ports & Adapters
  │   ├── comment/
  │   │   ├── read/              # ISP: 댓글 조회 전용
  │   │   └── user/              # ISP: 사용자별 댓글
  │   ├── notification/
  │   │   ├── read/              # ISP: 알림 조회 전용
  │   │   ├── update/            # ISP: 알림 수정 전용
  │   │   └── delete/            # ISP: 알림 삭제 전용
  │   ├── post/
  │   │   ├── read/              # ISP: 게시글 조회 전용
  │   │   ├── search/            # ISP: 게시글 검색 전용 (QueryDSL + Full-Text)
  │   │   ├── cache/             # ISP: 캐시 관리 전용
  │   │   ├── delete/            # ISP: 게시글 삭제 전용
  │   │   └── user/              # ISP: 사용자별 게시글
  │   ├── user/
  │   │   ├── read/              # ISP: 사용자 조회 전용
  │   │   └── validation/        # ISP: 사용자 검증 전용
  │   ├── paper/                 # 롤링페이퍼 저장소
  │   ├── admin/                 # 관리자 기능 저장소
  │   └── token/                 # 토큰 관리 저장소
  │
  ├── entity/                  # Domain Layer
  │   ├── comment/               # 댓글 도메인 (Closure Table 패턴)
  │   ├── post/                  # 게시글 도메인
  │   ├── message/               # 메시지 도메인 (암호화 적용)
  │   ├── notification/          # 알림 도메인
  │   ├── user/                  # 사용자 도메인
  │   └── report/                # 신고 도메인
  │
  ├── dto/                     # Data Transfer Objects
  │   ├── admin/                 # 관리자 DTO
  │   ├── auth/                  # 인증 DTO (Kakao API 포함)
  │   ├── comment/               # 댓글 DTO
  │   ├── notification/          # 알림 DTO (SSE, FCM)
  │   ├── paper/                 # 롤링페이퍼 DTO
  │   ├── post/                  # 게시글 DTO
  │   └── user/                  # 사용자 DTO
  │
  └── global/                  # Infrastructure & Cross-cutting
      ├── auth/                  # JWT, 인증 관리
      ├── config/                # QueryDSL, Redis, Async 설정
      ├── event/                 # 도메인 이벤트 정의
      ├── listener/              # 이벤트 리스너
      │   └── handler/           # 이벤트 핸들러 (전략 패턴)
      ├── exception/             # 예외 처리
      ├── filter/                # JWT, 로깅 필터
      └── security/              # 보안, 암호화

 
  - CQRS 패턴: service가 read/write/delete/update로 완전 분리
  - ISP 준수: repository 기능별로 세분화
  - 전략 패턴 적용: auth/strategy, admin/resolver
  - 이벤트 기반 아키텍처 적용: global/event, global/listener/handler