refactor: separate authentication and authorization into distinct modules#122
Merged
Conversation
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.
Related Issue
Closes #120
Summary of Changes
Separated authentication (identity verification) from authorization (access control) into distinct modules following DDD principles:
Part 1: RBAC Submodule Structure
Created
src/auth/rbac/submodule with clear separation:models.py- RBAC models (Role, Permission, UserRole, RolePermission)repository.py- Database queries (PermissionRepository)service.py- Business logic (PermissionService, pure - no FastAPI deps)dependencies.py- FastAPI dependency factories__init__.py- Public API re-exportsUpdated
src/auth/models.py- Removed RBAC models, kept User/OAuthAccount onlyDeleted
src/auth/rbac.py- Old 356-line monolithic fileUpdated test imports in 4 test files
Part 2: Eliminated Circular Import
src/auth/dependencies.py- Extractedcurrent_user,current_superuser,fastapi_userssrc/auth/__init__.py- Clean imports, no deferred importssrc/auth/rbac/dependencies.py- Import fromsrc.auth.dependenciesinstead ofsrc.authArchitecture improvements:
from src.auth import require_permissionsstill works)File changes:
src/auth/dependencies.py,src/auth/rbac/(4 files)src/auth/rbac.pysrc/auth/__init__.py,src/auth/models.py, 4 test filesBreaking Changes
N/A - Backward compatible. All existing imports continue to work via re-exports in
src/auth/__init__.py.Checklist
🤖 Generated with Claude Code