Service Layer medium complexity Shared Component mobile
1
Dependencies
6
Dependents
1
Entities
0
Integrations

Description

BLoC/Riverpod-based state manager that holds the current active role and exposes role change events to the widget tree. Acts as the single source of truth for role-dependent UI rendering throughout the app.

Feature: Role-Based Access Control

role-state-manager

Summaries

The Role State Manager is the central authority that governs what every user sees and can do throughout their entire session in the application. As a shared component used across all features, it ensures that when a user switches between roles — for example, from student to peer mentor — the entire interface instantly adapts without requiring a logout or page reload. This seamless context-switching is a direct competitive differentiator that improves user satisfaction, reduces task-switching friction, and enables power users with multiple responsibilities to operate efficiently within a single session, increasing overall platform engagement and reducing churn from users frustrated by rigid, single-role experiences.

As a shared component, Role State Manager is a foundational dependency for every feature that renders role-conditional UI, making it one of the highest-priority deliverables in the project. Its BLoC or Riverpod implementation must be finalized and stable before any feature team can build role-gated screens or navigation. The component requires thorough testing across role switch scenarios, logout/reset flows, and concurrent state emissions to prevent UI flickering or stale role rendering. Any breaking interface change — especially to getRoleStream() or switchRole() — will require coordinated updates across all consuming widgets.

Allocate dedicated QA cycles for multi-role user journeys and ensure all widget-level integration tests mock this provider consistently.

Role State Manager is implemented as a BLoC or Riverpod state provider, acting as the single source of truth for the active user role across the entire widget tree. It exposes getCurrentRole() for synchronous access, switchRole() to trigger role transitions with corresponding state emissions, getRoleStream() as a reactive stream for widgets using StreamBuilder or ref.watch(), isRoleActive() for conditional rendering logic, and resetRoleState() called on logout to prevent stale role data persisting across sessions. The component depends on role-repository for any persistence layer reads during role switches. Consumers should always subscribe via getRoleStream() rather than polling getCurrentRole() to ensure reactive rebuilds.

State emissions must be debounced if rapid role switching is possible to avoid redundant widget rebuilds.

Responsibilities

  • Store and expose the currently active user role
  • Emit state updates when the role is switched
  • Provide role-reactive streams consumed by conditional UI builders
  • Reset role state on logout

Interfaces

getCurrentRole()
switchRole(Role newRole)
getRoleStream()
resetRoleState()
isRoleActive(Role role)

Related Data Entities (1)

Data entities managed by this component

API Contract

View full contract →
REST /api/v1/role-sessions 5 endpoints
GET /api/v1/role-sessions List active role sessions
GET /api/v1/role-sessions/:sessionId Get current role state for a session
POST /api/v1/role-sessions Initialize a role session for a user
PUT /api/v1/role-sessions/:sessionId Switch active role within an existing session
DELETE /api/v1/role-sessions/:sessionId Reset and terminate a role session