Designing RBAC That Survives Real Users: Lessons from a University ERP
Role-based access control looks solved on paper: make a roles table, join it to permissions, check the user's role in middleware. Then a university throws four departments, one shared student record, and a registrar who fixes things at 2 AM at it, and the paper design quietly rots.
When I worked on the Al-Kawthar University e-portal, the requirement was simple to say and hard to ship: administrators, faculty, students, and staff all look at the same domain, and none of them may see what they shouldn't — including through URL manipulation, API calls, or a cached page.
One vocabulary, three layers
The core decision was to define capabilities once and share them everywhere. A single permissions module exported named capabilities; the Next.js UI hid elements by capability, the Express middleware authorized by capability, and PostgreSQL policies filtered by capability. Nobody wrote the check three times from memory.
// permissions.ts — the single source of truth
export const CAPABILITIES = {
student: { viewOwnRecord: 'student:record:self', payFees: 'student:fees:pay' },
faculty: { viewClassRoster: 'faculty:roster:class', enterMarks: 'faculty:marks:enter' },
admin: { manageAdmissions: 'admin:admissions:manage', viewReports: 'admin:reports:view' },
} as const;
// UI, middleware, and DB all consume the same names — drift becomes impossible.The UI is UX, the server is truth
Hiding a button is not authorization. Every capability check in the frontend was re-run server-side, including on list endpoints where an unauthorized ID simply returned nothing rather than an error that leaks existence. Registration — the most-abused public surface — got field-level validation, password rules, reCAPTCHA, and rate limiting, with server re-verification of every client-side assertion.
What actually broke (and what did not)
- Reports were the first casualty of duplicated truth: attendance and fee numbers diverged per module until we moved reporting onto shared PostgreSQL views. Numbers now reconcile by construction.
- Half-finished applications were the second: modelling onboarding as an explicit state machine (form → verification → document review → enrollment) made abandoned applications recoverable instead of garbage.
- What never caused an incident: the permission matrix itself. Agreeing it with each department before writing UI is the least glamorous, highest-leverage step in the project.
If your frontend and backend each have their own idea of what 'faculty' can do, you don't have RBAC — you have two bug reports that haven't met yet.
Six months after go-live, the permission model survived two department restructures without a schema migration. That is the bar: institutional software should outlive the org chart that inspired it.
Need this kind of thinking on your product?
I take on select freelance and contract work — Next.js, Node.js, and AI-powered products.