Problem Statement
The current codebase has layer boundary violations that compromise the clean architecture:
- Router layer directly calls Repository layer, bypassing Service layer
- Business logic mixed in Router layer instead of being encapsulated in Service layer
- Global singletons creating tight coupling and testing difficulties
Examples of Violations
// router/member.go:96 - Direct repo call
memberId, err := repo.GetMemberIdByLogtoId(user.Id)
// router/member.go:105-117 - Business logic in router
logto_roles, err := service.LogtoServiceApp.FetchUserRole(user.Id)
mappedRole := service.MemberServiceApp.MapLogtoUserRole(logto_roles)
Proposed Solution
Implement a 4-phase plan to enforce proper layer boundaries:
Phase 1: Analysis & Interface Design (Week 1)
Phase 2: Refactor Router Layer (Week 2-3)
Phase 3: Service Layer Enhancement (Week 3-4)
Phase 4: Architectural Safeguards (Week 4-5)
Benefits
- Improved Testability: Each layer can be unit tested independently
- Better Maintainability: Clear separation of concerns
- Reduced Coupling: Dependency injection eliminates global state
- Consistent Patterns: Standardized approach across all handlers
Implementation Strategy
- Service-by-Service Migration: Refactor one service at a time
- Backward Compatibility: Maintain existing functionality during transition
- Comprehensive Testing: Ensure no regression during refactoring
Success Criteria
Priority: High
Effort: ~4-5 weeks
Impact: Significant improvement in code maintainability and testability
Problem Statement
The current codebase has layer boundary violations that compromise the clean architecture:
Examples of Violations
Proposed Solution
Implement a 4-phase plan to enforce proper layer boundaries:
Phase 1: Analysis & Interface Design (Week 1)
Phase 2: Refactor Router Layer (Week 2-3)
Phase 3: Service Layer Enhancement (Week 3-4)
Phase 4: Architectural Safeguards (Week 4-5)
Benefits
Implementation Strategy
Success Criteria
Priority: High
Effort: ~4-5 weeks
Impact: Significant improvement in code maintainability and testability