Skip to main content

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.

Data models

SPS School Backend uses Mongoose to define schemas for MongoDB. There are seven collections, each documented below with its fields, constraints, and an example document.

Relationships overview

The diagram below shows how collections reference each other via ObjectId fields.

Models

Stores credentials and role information for every person who can log in to the system. Each email address must be unique.

Fields

body.name
string
Full name of the user.
body.email
string
required
Email address. Must be unique across all users. Used as the login identifier.
body.password
string
required
Bcrypt-hashed password. Never returned in API responses.
body.role
string
One of seven allowed values: SUPER_ADMIN, ACADEMIC_ADMIN, STUDENT_ADMIN, FINANCE_ADMIN, OPERATIONS_ADMIN, TEACHER, STUDENT. Enforced by a Mongoose enum constraint. See Roles for details.

Schema source

models/User.js
const userSchema = new mongoose.Schema({
  name: String,
  email: { type: String, unique: true },
  password: String,
  role: {
    type: String,
    enum: [
      "SUPER_ADMIN",
      "ACADEMIC_ADMIN",
      "STUDENT_ADMIN",
      "FINANCE_ADMIN",
      "OPERATIONS_ADMIN",
      "TEACHER",
      "STUDENT"
    ]
  }
});

Example document

MongoDB document
{
  "_id": "64f1a2b3c4d5e6f7a8b9c0d1",
  "name": "Ananya Verma",
  "email": "ananya@school.edu",
  "password": "$2b$10$...",
  "role": "TEACHER",
  "__v": 0
}
The password field stores the bcrypt hash. Never expose this field in API responses.
Represents a student enrolled at the school. Distinct from the User model — a student record holds academic identity (class, section, roll number) rather than login credentials.

Fields

body.name
string
Full name of the student.
body.email
string
Email address for the student. Not required to be unique at the schema level.
body.class
string
Class or grade the student belongs to (e.g., "10A", "Grade 5").
body.section
string
Section within the class (e.g., "A", "B").
body.rollNumber
number
Numeric roll number assigned to the student within their class and section.

Schema source

models/Student.js
const studentSchema = new mongoose.Schema({
  name: String,
  email: String,
  class: String,
  section: String,
  rollNumber: Number
});

Example document

MongoDB document
{
  "_id": "64f2b3c4d5e6f7a8b9c0d2e3",
  "name": "Rohan Mehta",
  "email": "rohan.mehta@school.edu",
  "class": "10A",
  "section": "B",
  "rollNumber": 14,
  "__v": 0
}
Student._id is the primary foreign key referenced by Attendance, Submission, Application, and Fee documents.
Records a single attendance event for one student on one date.

Fields

body.studentId
ObjectId
required
Reference to the Student._id this record belongs to.
body.date
Date
required
The calendar date of the attendance event.
body.status
string
required
Attendance status for the day. Typical values are "PRESENT" and "ABSENT", but the schema does not enforce an enum.

Schema source

models/Attendance.js
const attendanceSchema = new mongoose.Schema({
  studentId: mongoose.Schema.Types.ObjectId,
  date: Date,
  status: String
});

Example document

MongoDB document
{
  "_id": "64f3c4d5e6f7a8b9c0d3e4f5",
  "studentId": "64f2b3c4d5e6f7a8b9c0d2e3",
  "date": "2024-03-15T00:00:00.000Z",
  "status": "PRESENT",
  "__v": 0
}

Relationships

FieldReferencesDescription
studentIdStudent._idThe student this record is for
To query all attendance records for a student, filter by studentId. To check attendance for a class on a specific date, join with the Student collection on class and section.
Represents a task or assessment created by a teacher for a class.

Fields

body.classId
number
required
Numeric identifier of the class the assignment is for.
body.title
string
required
Title or name of the assignment.
body.dueDate
Date
Deadline by which students must submit their work.
body.teacherId
ObjectId
required
Reference to the User._id of the teacher who created the assignment.

Schema source

models/Assignment.js
const assignmentSchema = new mongoose.Schema({
  classId: Number,
  title: String,
  dueDate: Date,
  teacherId: mongoose.Schema.Types.ObjectId
});

Example document

MongoDB document
{
  "_id": "64f4d5e6f7a8b9c0d4e5f6a7",
  "classId": 10,
  "title": "Chapter 5 — Algebra Problem Set",
  "dueDate": "2024-03-22T23:59:59.000Z",
  "teacherId": "64f1a2b3c4d5e6f7a8b9c0d1",
  "__v": 0
}

Relationships

FieldReferencesDescription
teacherIdUser._idThe teacher who created this assignment
Assignment._id is referenced by Submission.assignmentId to link student submissions back to the original task.
Records a student’s submitted work for a specific assignment.

Fields

body.assignmentId
ObjectId
required
Reference to the Assignment._id this submission is for.
body.studentId
ObjectId
required
Reference to the Student._id of the student who submitted.
body.fileUrl
string
URL pointing to the uploaded submission file (e.g., a cloud storage URL).
body.submittedAt
Date
Timestamp of when the submission was received.

Schema source

models/Submission.js
const submissionSchema = new mongoose.Schema({
  assignmentId: mongoose.Schema.Types.ObjectId,
  studentId: mongoose.Schema.Types.ObjectId,
  fileUrl: String,
  submittedAt: Date
});

Example document

MongoDB document
{
  "_id": "64f5e6f7a8b9c0d5e6f7a8b9",
  "assignmentId": "64f4d5e6f7a8b9c0d4e5f6a7",
  "studentId": "64f2b3c4d5e6f7a8b9c0d2e3",
  "fileUrl": "https://storage.example.com/submissions/rohan-chapter5.pdf",
  "submittedAt": "2024-03-21T14:30:00.000Z",
  "__v": 0
}

Relationships

FieldReferencesDescription
assignmentIdAssignment._idThe assignment being submitted
studentIdStudent._idThe student who submitted
Represents a formal request sent from a student to a teacher — for example, a leave request, an extension, or any other workflow requiring teacher approval.

Fields

body.studentId
ObjectId
required
Reference to the Student._id of the applicant.
body.teacherId
ObjectId
required
Reference to the User._id of the teacher the application is addressed to.
body.type
string
Category of the application (e.g., "LEAVE", "EXTENSION", "OTHER").
body.message
string
The body of the application — the student’s written request.
body.status
string
default:"PENDING"
Current state of the application. Defaults to "PENDING". Updated by the teacher to "APPROVED" or "REJECTED".

Schema source

models/Application.js
const applicationSchema = new mongoose.Schema({
  studentId: mongoose.Schema.Types.ObjectId,
  teacherId: mongoose.Schema.Types.ObjectId,
  type: String,
  message: String,
  status: { type: String, default: "PENDING" }
});

Example document

MongoDB document
{
  "_id": "64f6f7a8b9c0d6e7f8a9b0c1",
  "studentId": "64f2b3c4d5e6f7a8b9c0d2e3",
  "teacherId": "64f1a2b3c4d5e6f7a8b9c0d1",
  "type": "LEAVE",
  "message": "I will be unable to attend school on March 25 due to a family function.",
  "status": "PENDING",
  "__v": 0
}

Relationships

FieldReferencesDescription
studentIdStudent._idThe student making the request
teacherIdUser._idThe teacher who reviews and acts on the request
status defaults to "PENDING" when a new application is created. The teacher updates it to "APPROVED" or "REJECTED" via PUT /api/application/:id.
Represents a fee record assigned to a student, tracking the amount owed and its payment status.

Fields

body.studentId
ObjectId
required
Reference to the Student._id this fee is charged to.
body.amount
number
required
The fee amount in the school’s base currency unit.
body.status
string
Payment status. Typical values are "PAID" and "UNPAID", but the schema does not enforce an enum.

Schema source

models/Fee.js
const feeSchema = new mongoose.Schema({
  studentId: mongoose.Schema.Types.ObjectId,
  amount: Number,
  status: String
});

Example document

MongoDB document
{
  "_id": "64f7a8b9c0d7e8f9a0b1c2d3",
  "studentId": "64f2b3c4d5e6f7a8b9c0d2e3",
  "amount": 12500,
  "status": "UNPAID",
  "__v": 0
}

Relationships

FieldReferencesDescription
studentIdStudent._idThe student who owes this fee
To list all unpaid fees, query the Fee collection with { status: "UNPAID" }. Combine with a Student lookup to display student names.

Field constraints summary

The table below consolidates all schema-level constraints across every model.
ModelFieldConstraint
Useremailunique: true
Userroleenum — must be one of the seven defined role strings
Applicationstatusdefault: "PENDING"
All other fields use Mongoose’s loose defaults — they are optional unless your application-level validation enforces them. Consider adding required: true to critical foreign-key fields like studentId and teacherId in production.

Build docs developers (and LLMs) love