Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore: πŸ”§ Divide Domain Modules For Multiple Infrastructure #206

Merged
merged 179 commits into from
Nov 26, 2024

Conversation

psychology50
Copy link
Member

μž‘μ—… 이유

Inital Architecture

We originally chose an architecture resembling the image below:

  • Data Sources: Could be MySQL, Redis, or others depending on the entity.
  • Structure: We divided packages based on data sources:
C:.
β”œβ”€β”€β”€common
β”‚   └───redis
β”‚       └───session
└───domains
    └───user

Problems Encountered

  1. Domain Logic Placement: Cross-entity business logic was forced into the lowest-level modules, leading to tightly coupled, entity-specific services.
  2. Domain Purity: Domains should be agnostic to the data source, focusing solely on business rules.
  3. Test Complexity: Both Redis and JPA setups were required for DAO testing.

Suggested Advanced Architecture

A more scalable approach includes the following improvements:

  • Single Responsibility: Each domain module manages only one infrastructure type.
  • Centralized Domain Logic: All domain business logic resides in the domain service module, promoting:
    • Low Coupling: Clear separation of concerns.
    • High Cohesion: Logical grouping of related functionality.

This architecture ensures scalability and simplifies testing while maintaining clean boundaries between domains and infrastructures.


μž‘μ—… 사항

  1. Module Restructuring

    • Created domain-service module for core business logic
    • Separated domain-rds and domain-redis modules
  2. Service Layer Changes

    • Implemented storage-specific logic in respective modules
    • Updated naming convention: *RdbService and *RedisService
  3. Testing Improvements

    • Converted integration tests to unit tests
    • Removed unnecessary test case
    • Added proper mocking strategies

Current Limitations and Migration Strategy

  1. Pragmatic Approach to Domain Logic

    • Ideal State: Lower-level modules should only depend on domain-service
    • Current Reality: Domain logic remains distributed across modules
    • Reason: Avoiding large-scale refactoring of existing business logic
  2. Gradual Migration Strategy
    Phase 1 (Current)

    • Establish new module structure
    • Keep existing domain logic in place
    • Minimize immediate changes to running systems

    Phase 2 (Future)

    • Gradually move domain logic to domain-service
    • Update dependencies one service at a time
    • Maintain backward compatibility
  3. Trade-offs Made

    • Accepting temporary architectural compromise
    • Prioritizing system stability over immediate perfect structure
    • Allowing for smoother transition period
  4. Guidelines for New Features

  • Core domain logic should be placed in domain-service
  • However, non-core logic (e.g., simple CRUD, caching) remains in lower-level services
  • Examples:
    Core Domain Logic (domain-service):
    - Complex business rules involving multiple entities
    - Critical validation rules
    - Coordinating multiple services
    
    Non-core Logic (infrastructure services):
    - Simple CRUD operations
    - Basic data validation
    - Cache management
    - Infrastructure-specific operations
  • Existing logic can be migrated opportunistically
  • Document clear patterns for both approaches

리뷰어가 μ€‘μ μ μœΌλ‘œ 확인해야 ν•˜λŠ” λΆ€λΆ„

  1. Dependency Direction

    • domain-service depends on infrastructure modules (domain-rds, domain-redis)
    • This intentional choice enables:
      • Direct Entity usage in domain logic
      • Gathering validation logic
      • Practical development workflow

    Trade-offs Considered:

    • Pros:
      • Avoid duplicate validation/creation rules
      • Maintain single source of truth for Entity structure
      • Reduce complexity in data transformation
    • Cons:
      • Domain logic has knowledge of persistence details
      • Tighter coupling with specific implementations
      • Less flexibility in storage implementations
  2. Service Naming and Structure

    • Verify consistent naming: *RdbService and *RedisService for infrastructure
    • Check proper integration in domain-service
    • Check if any business logic leaked into infrastructure layers
  3. Test Coverage

    • Verify if all important scenarios are covered
    • Check if mocking strategies are appropriate
    • Ensure test readability and maintainability

λ°œκ²¬ν•œ 이슈

  1. Some services still have tight coupling with Entity structures

    • Consider introducing DTOs for complete separation
    • Currently accepted for practical reasons
  2. Configuration Management

    • Need to standardize configuration across modules
    • Consider creating shared configuration module
  3. Transaction Management

    • Current implementation handles transactions per-repository
    • May need distributed transaction solution in future
  4. Migration Strategy

    • Gradual migration approach for existing features
    • Need to document migration guidelines

@psychology50 psychology50 added architecture κΈ΄κΈ‰ν•˜μ§€ μ•Šκ³ , μ€‘μš”λ„κ°€ 높은 이슈 refactoring λ¦¬νŒ©ν† λ§ μž‘μ—… labels Nov 26, 2024
@psychology50 psychology50 self-assigned this Nov 26, 2024
@psychology50 psychology50 merged commit 197dd5f into dev Nov 26, 2024
1 check passed
@psychology50 psychology50 deleted the fix/refactor-domain branch November 26, 2024 09:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
architecture κΈ΄κΈ‰ν•˜μ§€ μ•Šκ³ , μ€‘μš”λ„κ°€ 높은 이슈 refactoring λ¦¬νŒ©ν† λ§ μž‘μ—…
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant