코드만 보고 시스템 구조를 파악 할 수 있다면?
case 1)
buckpal
├── domain
│ ├── Account
│ ├── Activity
│ ├── AccountRepository
│ └── AccountService
├── persistence
│ └── AccountRepositoryImpl
└── web
└── AccountController
- 기능별 구분이 없다
사용자(User) Controller, Repository 등 다양한 기능/클래스들이 추가되는 경우
domain, persistence, web 경로에 포함된다
- 어떤 비즈니스 로직 / 기능을 제공하는지 파악하기 어렵다
AccountService -> 어떤 기능을 제공하는지 알 수 있나?
- 어떤 시스템 구조를 띄는지 파악이 어렵다
case 2)
가능별 구분
buckpal
└── account
├── Account
├── SendMoneyController
├── AccountRepository
├── AccountRepositoryImpl
└── SendMoneyService
- SendMoneyService -> 송금기능을 제공하는 서비스라는 것을 알 수 있다
- 도메인, 영속성계층 등 구분이 없어 첫번째 예시의 단점을 가진다
case 3)
시스템 구조에 따라 구분
buckpal
├── adapter
│ ├── in
│ │ └── web
│ │ └── SendMoneyController
│ └── out
│ └── persistence
│ ├── AccountPersistenceAdapter
│ └── SpringDataAccountRepository
├── application
│ ├── domain
│ │ ├── model
│ │ │ └── Account
│ │ └── service
│ │ └── SendMoneyService
│ └── port
│ ├── in
│ │ └── SendMoneyUseCase
│ └── out
│ └── UpdateAccountStatePort
└── common
- 최상위에 adapter, application
- adapter에는 해당 어플리케이션의 진입점과 출구점이 포함된다(in, out)
- 다른 adapter 교체에 용이하다 ex)SpringData 외에 다른 데이터 접근 기술로의 교체
- application 하위에 위치하는 port를 주입받아 외부로부터의 요청을 받거나 보낸다(외부에서 구현제 알 지 못함)
- domain에는 각 비즈니스 로직의 구현체가 포함된다
- 외부에서는 port의 인터페이스만 알고 있어 유지보수에 용이하다
- architecture/code gap 줄여준다
+) spring i/o 2024에서 architecture/code gap 관련 내용이 있어 함께 남긴다
논리적인 시스템 구조를 코드로 표현하도록 지원하는 프로젝트
다음은 spring modulith 예시
○: public, -: private
□ Example
└─ □ src/main/java
├─ □ example
│ └─ ○ Application.java
│
├─ □ example.inventory
│ ├─ ○ InventoryManagement.java
│ └─ - InventoryInternal.java
│
├─ □ example.order
│ └─ ○ OrderManagement.java
└─ □ example.order.internal <- public 클래스이나 order 패키지 에서만 사용가능(inventory 사용불가)
└─ ○ OrderInternal.java