Refactor Django REST Framework codebase to Clean Architecture#126
Closed
Refactor Django REST Framework codebase to Clean Architecture#126
Conversation
Co-authored-by: bduke-dev <7875574+bduke-dev@users.noreply.github.com>
Co-authored-by: bduke-dev <7875574+bduke-dev@users.noreply.github.com>
Co-authored-by: bduke-dev <7875574+bduke-dev@users.noreply.github.com>
Co-authored-by: bduke-dev <7875574+bduke-dev@users.noreply.github.com>
… constants Co-authored-by: bduke-dev <7875574+bduke-dev@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Refactor code to comply with clean architecture
Refactor Django REST Framework codebase to Clean Architecture
Nov 7, 2025
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.
Closes: Issue requesting clean architecture compliance
Description
Implements Clean Architecture for Django REST Framework, decoupling business logic from framework dependencies. User module serves as complete reference implementation for remaining 11 apps.
Architecture:
Changes:
Core Architecture
core/interfaces/- Repository contracts with type-safe signatures (IRepository,IUserRepository)core/use_cases/- Framework-agnostic business logic (7 user use cases: CRUD + authorization)core/dto/- Data transfer objects decoupling layerscore/di_container.py- Dependency injection for loose couplinginfrastructure/repositories/- Django ORM implementations isolated from business logicUser Module (Reference Implementation)
user/views_clean.py- Thin HTTP handlers delegating to use cases__iexact), extracted constants (ADMIN_GROUP_NAME)TYPE_CHECKINGto avoid circular importsDocumentation (75KB)
CLEAN_ARCHITECTURE.md- Layer descriptions, migration strategyCLEAN_ARCHITECTURE_TEMPLATE.py- Copy-paste templates for rapid developmentCLEAN_ARCHITECTURE_SECURITY.py- Authentication/authorization patternsMIGRATION_GUIDE.md- 8-step process with before/after examplesCLEAN_ARCHITECTURE_SUMMARY.md- Executive overviewExample - Before:
Example - After:
Tradeoffs
views.pyremains functional alongside newviews_clean.pyAlternatives
Minor enhancements noted for follow-up:
linksproperty inGetUserUseCaseOriginal prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.