Conversation
…y DTOs, fix repository Co-authored-by: Alonsovn <70250204+Alonsovn@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor user management module for Clean Architecture and domain purity
Refactor user management module: Remove Pydantic from domain layer and simplify architecture
Sep 10, 2025
Alonsovn
approved these changes
Sep 10, 2025
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR refactors the user management module to remove Pydantic dependencies from the domain layer, eliminating external framework dependencies while maintaining functionality. The refactor simplifies the codebase by removing builder patterns and fixes critical repository bugs.
- Converts
UserEntityfrom PydanticBaseModelto puredataclassfor domain layer purity - Replaces complex builder patterns with direct construction using factory methods
- Fixes repository conversion bugs including non-existent field references and Pydantic-specific method usage
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| user_repository_impl.py | Updates repository methods to work with dataclass and fixes field reference bug |
| user_entity.py | Converts from Pydantic BaseModel to pure dataclass with factory method |
| user_dto_mapper.py | Simplifies DTO mappings by removing builder patterns |
| user_entity_builder.py | Removed as part of builder pattern elimination |
| user_dto_builder.py | Removed as part of builder pattern elimination |
Comments suppressed due to low confidence (1)
src/app/features/user_management/domain/entities/user_entity.py:110
- Duplicate code detected. The properties and methods from lines 85-110 are identical to those defined earlier in lines 58-83. This duplication should be removed to maintain code clarity.
@property
def fullname(self) -> str:
return f"{self.first_name} {self.last_name}"
@property
def is_active(self) -> bool:
return self.user_status == UserStatus.ACTIVE
def update_personal_info(
self,
first_name: Optional[str] = None,
last_name: Optional[str] = None,
):
"""Update user's personal information"""
if first_name:
self.first_name = first_name
if last_name:
self.last_name = last_name
self.updated_at = get_current_datetime()
def change_status(self, new_status: UserStatus):
"""Change user status"""
if self.user_status != new_status:
self.user_status = new_status
self.updated_at = get_current_datetime()
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR refactors the user management module to enforce Clean Architecture principles by removing Pydantic dependencies from the domain layer, simplifying DTO mappings, and fixing critical repository bugs.
Problem
The existing implementation violated Clean Architecture principles in several ways:
UserEntitywas built on Pydantic'sBaseModel, creating unwanted dependencies on application/infrastructure layersphone_numberfield and improper use ofmodel_validateSolution
🏗️ Domain Layer Purification
Converted
UserEntityfrom PydanticBaseModelto a puredataclass:📋 Simplified DTO Mappings
Eliminated builder patterns in favor of direct construction:
💾 Repository Bug Fixes
Fixed critical issues in the infrastructure layer:
Benefits
phone_numberreference error andmodel_validatedependenciesTesting
Comprehensive validation confirms:
update_personal_info,change_status, properties)The refactor maintains backward compatibility while significantly improving code quality and architectural adherence.
This pull request was created as a result of the following prompt from Copilot chat.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.