Skip to content
This repository was archived by the owner on Oct 24, 2025. It is now read-only.

feat: Implement Role-Based Access Control (RBAC) with Clean Architecture - #9

Merged
DanielvG-IT merged 21 commits into
mainfrom
RBAC-AUTH
Oct 19, 2025
Merged

feat: Implement Role-Based Access Control (RBAC) with Clean Architecture#9
DanielvG-IT merged 21 commits into
mainfrom
RBAC-AUTH

Conversation

@DanielvG-IT

Copy link
Copy Markdown
Contributor

This pull request introduces a major architectural refactor to the backend application, implementing Clean Architecture and Domain-Driven Design principles for role-based user management. The changes split user-related business logic into dedicated services for students and teachers, refactor the service interfaces, and add comprehensive documentation of the new architecture. This lays the groundwork for maintainable, scalable, and testable code, while improving type safety and separation of concerns.

Architecture Documentation

  • Added a detailed ARCHITECTURE.md file explaining the Clean Architecture layers, role-based domain modeling, project structure, authentication/authorization flow, API endpoints, testing strategy, and key design patterns.

Service Layer Refactor

  • Split user-related business logic into three dedicated services: UserService (generic CRUD), StudentService (student favorites logic), and TeacherService (teacher electives logic). Added implementations for StudentService and TeacherService.

Service Interface Changes

  • Removed student-specific and teacher-specific methods from IUserService and moved them into new interfaces: IStudentService and ITeacherService. This enforces single responsibility and improves type safety.

Authentication Improvements

  • JWT payloads now include the user's role, supporting role-based authorization in controllers and guards.

Codebase Cleanup

  • Removed unnecessary imports and dependencies from user.service.ts to reflect the new separation of concerns.

Let me know if you’d like to walk through any part of this refactor in detail, or if you have questions about how the new architecture affects your work!

…s and ports; update DI tokens and app module
…ove favorites from user controller; wire controllers into InterfacesModule
…ser services; add isElectiveInUse check in repository
- Create discriminated union types for UserDTO (StudentUserDTO, TeacherUserDTO, AdminUserDTO)
- Add UserRole type definition for consistent role typing
- Update user controller to use UserDTO import and new types
- Add missing decorators (Post, Put, Patch, Delete) to controller
- Allow Partial<T> in update methods for both ElectiveRepository and UserRepository
- Rename getModulesGiven to getElectivesGiven in ITeacherService port
- Remove outdated comments from teacher interface
- Align repository interfaces with service requirements
- Update ElectiveService.updateElective to accept Partial<Elective>
- Update UserService.updateElective to accept Partial<User>
- Rename TeacherService.getModulesGiven to getElectivesGiven
- Add enrollment validation logic in UserService.deleteUser (TODO)
- Improve service method signatures for flexibility
- Improve type safety in MongooseElectiveRepository by removing unnecessary 'as unknown' casts
- Update MongooseUserRepository.update signature to accept Partial<User>
- Add missing HTTP method decorators (Post, Put, Patch, Delete) to ElectiveController
- Rename TeacherController method from getModulesGiven to getElectivesGiven
- Update route from /me/modules to /me/electives in TeacherController
- Add type annotation for Elective import in ElectiveController
- Add AdminDashboard component with role-based access control
… files and consolidating favorite handling in user controller
@DanielvG-IT
DanielvG-IT marked this pull request as ready for review October 19, 2025 11:24
@DanielvG-IT DanielvG-IT added the enhancement New feature or request label Oct 19, 2025
@DanielvG-IT DanielvG-IT self-assigned this Oct 19, 2025
@DanielvG-IT
DanielvG-IT merged commit c67d875 into main Oct 19, 2025
4 checks passed
@DanielvG-IT
DanielvG-IT deleted the RBAC-AUTH branch October 19, 2025 11:26
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant