Skip to content

Conversation

@9keyyyy
Copy link
Member

@9keyyyy 9keyyyy commented Dec 20, 2025

📍 작업 배경 #

  • issue : #

four_pillars 모듈 구조 개선

✨ 주요 개선 사항

  • 책임 분리: 계산 로직, 데이터 로딩, 분석 로직을 별도 클래스로 분리
  • 구조 단순화: 불필요한 추상화 제거, FourPillarsCalculator 하나로 통합
  • 선택적 기능: description_generator를 선택적으로 주입하여 설명 생성 기능 제공
  • 코드 가독성 향상: 각 클래스가 명확한 단일 책임을 가짐

📁 새로운 구조

four_pillars/
├── domain/                        # 도메인 로직
│   ├── constants.py              # 상수 (천간, 지지, 기준년도)
│   ├── entities/
│   │   ├── enums.py              # FiveElements, TenGods
│   │   └── schemas.py            # PillarInfo, FourPillar, FourPillarDetail
│   └── services/
│       ├── calculator.py         # FourPillarsCalculator (메인 클래스)
│       ├── data_loader.py         # 데이터 로딩 (간지, 절입)
│       └── analyzer.py           # 오행/십신 분석
└── infrastructure/
    └── description_generator.py  # HCX API 호출 (선택적)

🔄 변경된 파일

삭제된 파일

  • common/calculator.py (568줄 → 분리됨)
  • entities/enums.py (도메인으로 이동)
  • entities/schemas.py (도메인으로 이동)
  • application/ 폴더 (불필요한 추상화 제거)

생성된 파일

  • domain/constants.py - 상수 정의
  • domain/services/calculator.py - 메인 계산 클래스
  • domain/services/data_loader.py - 데이터 로딩
  • domain/services/analyzer.py - 오행/십신 분석
  • infrastructure/description_generator.py - HCX API 호출

수정된 파일

  • __init__.py - export 업데이트
  • users/application/service.py - 새로운 구조 사용

📝 사용 방법

기본 사용 (설명 없이)

from src.four_pillars import FourPillarsCalculator

calculator = FourPillarsCalculator()
result = await calculator.calculate_four_pillars_detailed(birth_date)
# result.description = ""

설명 포함 사용

from src.four_pillars import FourPillarsCalculator, FourPillarDescriptionGenerator

calculator = FourPillarsCalculator(
    description_generator=FourPillarDescriptionGenerator()
)
result = await calculator.calculate_four_pillars_detailed(birth_date)
# result.description = "생성된 설명..."

🎯 핵심 변경사항

이전 구조

  • FourPillarsCalculator (도메인)
  • FourPillarsService (애플리케이션, 단순 조합)
  • 함수명 중복으로 혼란

개선된 구조

  • FourPillarsCalculator 하나로 통합
  • description_generator를 선택적으로 주입
  • 구조 단순화, 사용법 명확화

💬 코멘트 #

@9keyyyy 9keyyyy requested a review from Copilot December 20, 2025 09:45
@9keyyyy 9keyyyy self-assigned this Dec 20, 2025
@9keyyyy 9keyyyy added the enhancement New feature or request label Dec 20, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the four_pillars module to improve code organization and maintainability by separating concerns into distinct layers. The monolithic 568-line FourPillarsCalculator class has been split into focused components following domain-driven design principles.

Key Changes

  • Responsibility separation: Split calculation, data loading, and analysis logic into dedicated classes (FourPillarsDataLoader, FiveElementsAnalyzer, TenGodsAnalyzer)
  • Simplified architecture: Removed unnecessary application layer abstraction, consolidating functionality into a single FourPillarsCalculator with optional description generation via dependency injection
  • Improved modularity: Moved entities and enums into a proper domain structure with clearer import paths

Reviewed changes

Copilot reviewed 14 out of 19 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
src/four_pillars/__init__.py Added module-level exports for cleaner imports
src/four_pillars/domain/constants.py Extracted constants (JIKKAN, JYUNISHI, BASE_YEAR) for better organization
src/four_pillars/domain/entities/enums.py Moved enums to domain layer with updated import path
src/four_pillars/domain/entities/schemas.py Moved schemas to domain layer, removed unused List import
src/four_pillars/domain/services/calculator.py New main calculator with optional description generator injection
src/four_pillars/domain/services/data_loader.py Extracted data loading logic (kanshi and setsuiri data)
src/four_pillars/domain/services/analyzer.py Extracted five elements and ten gods analysis logic
src/four_pillars/infrastructure/description_generator.py Isolated HCX API integration for description generation
src/four_pillars/common/calculator.py Deleted monolithic 568-line class, split into focused components
src/users/application/service.py Updated to use new import path and inject description generator
src/users/domain/interfaces.py Updated FourPillarDetail import path
src/users/infrastructure/repository.py Updated FourPillarDetail import path
src/users/api/schemas.py Updated FourPillarDetail import path
src/users/api/router.py Updated FourPillarDetail import path
src/lotto/api/schemas.py Updated FiveElements import path
Comments suppressed due to low confidence (1)

src/four_pillars/domain/services/data_loader.py:2

  • Import of 'Dict' is not used.
from typing import Dict, Tuple

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link

Copilot AI commented Dec 20, 2025

@9keyyyy I've opened a new pull request, #28, to work on those changes. Once the pull request is ready, I'll request review from you.

@9keyyyy 9keyyyy merged commit 84a7d22 into main Dec 20, 2025
@9keyyyy 9keyyyy deleted the refactor/four-pillars branch December 20, 2025 10:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants