Skip to content

Backend Users RBAC Dashboard

Ankit Upadhyay edited this page Jul 24, 2026 · 2 revisions

Backend: Users, RBAC, Dashboard

User accounts, the organization-membership join that powers role-based access control, and dashboard aggregation. Part of Backend Overview; the authorization model is also covered in Multi-Tenancy and RBAC.

What it owns

Web and mobile users, the UserOrganization mapping (which user has which role in which org, plus per-user permission grants/revocations and an effective-permission cache), the role/permission vocabulary, workspace context, and dashboard aggregation. Web session and MFA live here too (SuperTokens).

Routers

user.router.ts, user-profile.router.ts, user-organization.router.ts, authUserMobile.router.ts, workspace.router.ts, dashboard.router.ts, auth.router.ts (SuperTokens /v1/auth/me + /v1/auth/mfa/*).

Controllers

web/user.controller.ts, web/user-profile.controller.ts, web/user-organization.controller.ts, app/authUserMobile.controller.ts, web/workspace.controller.ts, web/dashboard.controller.ts, web/mfa.controller.ts.

Services

user.service.ts, user-profile.service.ts, user-organization.service.ts, authUserMobile.service.ts (legacy mobile Cognito verification lives here), workspace.prisma.service.ts, dashboard.service.ts.

Models & the RBAC vocabulary

Models: user-profile.ts, user-organization.ts, and role-permission.ts — the RBAC source of truth (user account entities live solely in the Prisma schema since PR #1819):

  • RoleCode: OWNER, ADMIN, SUPERVISOR, VETERINARIAN, TECHNICIAN, ASSISTANT, RECEPTIONIST.
  • Permission strings follow domain:action:scope — e.g. appointments:view:any, appointments:edit:own, billing:edit:limited, inventory:edit:any, labs:view:any, subscription:edit:any, audit:view:any, analytics:view:clinical.
  • ROLE_PERMISSIONS is the baseline table each role inherits.

Enforcement

middlewares/rbac.ts is the enforcement layer: withOrgPermissions() resolves the caller's UserOrganization mapping (org id from params / x-org-id header / query / body, injection-safe) and computes effectivePermissions = baseline + extra − revoked; requirePermission(perm | perm[]) enforces (OR semantics). Entity-scoped variants derive the org from a resource id. See Multi-Tenancy and RBAC.

Notable

  • MFA is real today: mfa.controller.ts + SuperTokens back /v1/auth/mfa/*, part of the auth-hardening direction (Plans: Authentication).
  • The dashboard service aggregates cross-subsystem metrics for the PMS home; the frontend dashboard renders them.

Related

Product & Domain
Architecture
Applications
Design & Accessibility
Engineering Handbook
Decisions (ADRs)
Design Docs & Plans
Roadmap
Operations
Meta

Canonical code & docs: main repo · Auto-generated companion: DeepWiki

Clone this wiki locally