Skip to content

[Refactor] IPAM 서비스 — Aggregate별 Vertical Slice 구조 리팩토링 #23

@fray-cloud

Description

@fray-cloud

배경

IPAM 서비스의 각 DDD 레이어(domain/application/infrastructure/interface) 내부에서 도메인 개념별 분리가 없어 거대한 단일 파일들이 존재합니다:

  • command_handlers.py (2341줄), read_model_repository.py (1113줄), query_handlers.py (687줄) 등

목표

Aggregate별 독립 폴더 + 내부 CQRS 레이어 (vertical slice) 구조로 리팩토링

목표 구조

services/ipam/src/ipam/
├─ main.py                    # FastAPI app
├─ routers.py                 # 중앙 라우터 registry
├─ graphql/
├─ prefix/
│   ├─ domain/    (aggregate, events, value_objects, repository interface)
│   ├─ command/   (commands.py, handlers.py)
│   ├─ query/     (queries.py, handlers.py, dto.py)
│   ├─ router/    (router.py, schemas.py)
│   └─ infra/     (models.py, repository.py, projector.py)
├─ ip_address/    # 동일 구조
├─ vrf/
├─ vlan/
├─ vlan_group/
├─ ip_range/
├─ rir/
├─ asn/
├─ fhrp_group/
├─ route_target/
├─ service_entity/
└─ shared/        # cross-cutting (saved_filter, search, import_export, services, config)

작업 체크리스트

Phase 1: Domain 이동

  • 11개 Aggregate 폴더 + shared 폴더 생성
  • domain 파일 이동 (events/value_objects/repository 분리)
  • 테스트 domain import 수정 + 검증

Phase 2: Application 이동

  • commands.py (573줄) → 각 {agg}/command/commands.py
  • command_handlers.py (2341줄) → 각 {agg}/command/handlers.py
  • queries.py + query_handlers.py → 각 {agg}/query/
  • dto.py, read_model.py 분리
  • SavedFilter/Search/ImportExport → shared/
  • 테스트 import 수정 + 검증

Phase 3: Infrastructure 이동

  • models.py (346줄) → 각 {agg}/infra/models.py
  • read_model_repository.py (1113줄) → 각 {agg}/infra/repository.py
  • event_projector.py (566줄) → 각 {agg}/infra/projector.py
  • database/config/cache → shared/

Phase 4: Interface 이동

  • 라우터 → 각 {agg}/router/router.py
  • schemas.py (648줄) → 각 {agg}/router/schemas.py
  • main.py + routers.py + graphql/ 최상위 이동
  • 기존 레이어 디렉토리 삭제
  • 통합 테스트 + 린트 전체 검증

설계 결정

  • Facade 없음 — import 직접 수정 후 기존 파일 삭제
  • 라우터 등록: 중앙 registry 파일 (routers.py)
  • App 진입점: ipam/ 최상위

Metadata

Metadata

Assignees

No one assigned

    Labels

    ipamIPAM Service

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions