Skip to content

[Feature]: Core/Security - Implement Role-Based Access Control (RBAC) & Service Layer Abstraction #1863

Description

@Diwakar-odds

Feature/Project Proposal

Refactor the application into a decoupled 3-tier architecture (Router -> Controller -> Service) and implement granular Role-Based Access Control (RBAC).

Problem Statement

PrepPilot currently has monolithic controllers handling both business logic and HTTP request formatting. Furthermore, there is no granular Role-Based Access Control (RBAC) architecture to safely manage administrative actions (e.g., curating question banks, managing sheets), posing a security risk as the platform scales.

Proposed Solution

  1. Extract core business logic from controllers into dedicated services/ (e.g., questionService.js), making logic testable and reusable.
  2. Update models/User.js to support an array of roles (enum: ['user', 'moderator', 'admin']).
  3. Develop a generic rbacMiddleware.js that intercepts requests, checks the JWT payload for role permissions, and dynamically blocks unauthorized access to specific routes.
  4. Apply RBAC to all sensitive endpoints in questionRoutes and resumeRoutes.

Alternatives Considered

We could just add an isAdmin boolean to the User model, but a dedicated Role-Based approach allows for granular scaling like adding moderators, content-editors, etc., without altering the DB schema repeatedly.

Benefits

Massively improves code maintainability and testability, while preventing privilege escalation attacks and securing administrative functionalities.

Priority

High

Additional Context

N/A

Checklist

  • I have searched existing issues and discussions before creating this request.
  • I am willing to work on this feature if it is approved.

Metadata

Metadata

Assignees

Labels

claimedThis issue has been claimed by a contributor

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions