Documentation Index
Fetch the complete documentation index at: https://mintlify.com/praveenarya123/sps-backend/llms.txt
Use this file to discover all available pages before exploring further.
Roles
Every user account in SPS School Backend carries a single role that determines what they are allowed to do. The role is stored on theUser document, embedded in the JWT at login, and checked by route middleware before each protected request is processed.
The role is embedded in the JWT payload at login time. After a token is issued, the role cannot change without the user logging in again to receive a new token.
The seven roles
SUPER_ADMIN
Full system access. Intended for top-level administrators who need unrestricted access to all resources and configurations across the platform.
ACADEMIC_ADMIN
Manages academic operations such as classes, sections, and academic records. Coordinates between teachers and students at the institutional level.
STUDENT_ADMIN
Handles student enrollment and record management. Creates and updates student profiles, manages roll numbers, class assignments, and sections.
FINANCE_ADMIN
Manages fee records and financial operations. Creates fee entries and reviews payment statuses for students.
OPERATIONS_ADMIN
Oversees day-to-day operational administration including attendance workflows and application processing at the administrative level.
TEACHER
Creates and manages assignments for their classes. Reviews and approves or rejects student applications directed to them.
STUDENT
Submits assignments and sends applications to teachers. Views their own attendance and fee records.
How roles are assigned
A role is set at registration time in the request body. Therole field is stored directly on the User document.
Client sends registration request
The
POST /api/auth/register endpoint accepts a role field in the JSON body.request body
Role is persisted on the User document
Mongoose validates the value against the enum before saving. If the value is not one of the seven valid roles, the document is rejected.
models/User.js
How role checking works
Protected routes apply two middleware functions in sequence: an auth middleware that verifies the JWT and attachesreq.user, followed by a role middleware that compares req.user.role to the required value.
middleware/roleMiddleware.js
TEACHER role is registered like this:
routes/teacher.js
What happens when the role doesn’t match
If the authenticated user’s role does not match the required role, the middleware short-circuits the request and returns a403 response immediately. The route handler is never called.
403 response
The middleware performs an exact string equality check. A
SUPER_ADMIN is not automatically granted access to routes guarded by other roles. Each role must be explicitly authorized per route.Role-to-endpoint mapping
The table below shows the intended role for each endpoint group. Routes marked open (auth only) require a valid JWT but have no role guard in the current implementation.| Endpoint | Method | Required role | Notes |
|---|---|---|---|
/api/auth/register | POST | None | Public — no auth required |
/api/auth/login | POST | None | Public — no auth required |
/api/student/add | POST | None (currently open) | Intended for STUDENT_ADMIN |
/api/student/list | GET | None (currently open) | Intended for STUDENT_ADMIN, ACADEMIC_ADMIN |
/api/teacher/assignment | POST | TEACHER | Role guard enforced in source |
/api/attendance/mark | POST | None (currently open) | Intended for TEACHER, OPERATIONS_ADMIN |
/api/attendance/student/:id | GET | None (currently open) | Intended for TEACHER, STUDENT |
/api/assignment/submit | POST | None (currently open) | Intended for STUDENT |
/api/application/send | POST | None (currently open) | Intended for STUDENT |
/api/application/approve/:id | PUT | None (currently open) | Intended for TEACHER |
/api/finance/create | POST | None (currently open) | Intended for FINANCE_ADMIN |
/api/finance/list | GET | None (currently open) | Intended for FINANCE_ADMIN |