Introducing a new way to review your PRs.

Read the announcement

nusmodifications / nusmods

🏫 Official course planning platform for National University of Singapore.

View on GitHub

20 documents · Updated Nov 6, 2026

docs / module-prerequisite-explorer

Module prerequisite explorer

The module prerequisite explorer helps students understand the requirements around a module and, in a separate Course Planning Exercise (CPEx) flow, record ranked course preferences for NUS planning. The prerequisite view is public module data. The CPEx preference flow uses a signed-in NUS account and sends the saved preference record through the website API to NUS-backed storage.

This page is a child of Campus tools. For nearby student workflows, see Venue and transport tools and Timetable optimisation.

Product boundary

The repository uses MPE for the CPEx data and request flow, while the module page provides the prerequisite tree. These are related through module data but serve different needs: one explains academic requirements and the other collects a planning preference.

Prerequisite understanding

The prerequisite view places a selected module beside the requirements needed to take it. It can also show modules that the selected module helps unlock. The view combines the readable prerequisite text with a structured tree so that a student can check both the source statement and its visual meaning.

References: website/…/ModulePageContent.tsx• L146-185 website/…/ModulePageContent.tsx• L274-283 website/…/ModuleTree.tsx• L187-241

Course planning preference

The CPEx view asks a student to choose and rank up to seven courses for AY2026/2027 Semester 2. Each choice has a degree-use type and the submission includes the number of intended module credits. The result is for demand and resource planning. It does not check timetable clashes or requisites and does not guarantee a place in CourseReg.

References: website/…/MpeContainer.tsx• L119-146 website/…/constants.ts• L1-3 website/…/mpe.ts• L3-15

Prerequisite views

The module page is the main entry point for prerequisite exploration. A module may have no structured tree when its requirements cannot be represented in that form, so the readable prerequisite text remains the wider source of context.

Tree relationships

The tree represents requirements as a nested set of choices and conditions. It can express all-of and one-of paths, a minimum number of courses, grade thresholds, course-code patterns, cohort limits, and programme-type limits. The selected module is the root. Reverse links show which modules list it as a requirement.

The display treats a missing or retired course as inactive rather than removing it from the relationship. This keeps the reported requirement visible while showing that the course is no longer active in the current module data.

References: website/…/ModuleTree.tsx• L34-106 website/…/ModuleTree.tsx• L131-183 website/…/ModuleTree.tsx• L218-241 website/…/modules.ts• L238-271

The following diagram shows how a module page turns requirement data into a student-facing view.

flowchart LR
    A[Module data] --> B[Readable prerequisite text]
    A --> C[Structured prerequisite tree]
    C --> D[Requirement and unlock branches]
    B --> E[Module page]
    D --> E
    E --> F[Linked module pages]

Tree limits

The tree is a visual aid and may not be accurate. Students are directed to compare it with the prerequisite text and report problems when the two do not agree.

References: website/…/ModuleTree.tsx• L245-266 website/…/ModulePageContent.tsx• L150-165

CPEx preference flow

The CPEx flow is available at /cpex. Its page first shows the purpose and current schedule of the exercise. It then chooses either a sign-in prompt or the preference form based on the local login state. The page can also show that the exercise is closed when the feature is disabled or its configured period has ended.

Preference editing

The form loads the available CPEx course list and the student’s saved submission together. It limits the list to courses offered in the target semester and allows up to seven courses. A student can add or remove courses, set each course’s degree-use type, change the intended credit total, and reorder the ranking.

Course search adapts to the screen size. On a wide screen it opens below the search field. On a smaller screen it opens in a full-screen modal. The search marks courses that are already in the preference list and prevents a second add, while still allowing the student to remove an existing choice. It also explains when no course matches and points to the CPEx FAQ.

The form saves each change as a whole submission. A single-item queue keeps requests in order while replacing stale pending edits with the latest state. This supports quick changes without treating each intermediate drag or selection as a separate long-term preference.

References: website/…/MpeFormContainer.tsx• L13-65 website/…/ModuleForm.tsx• L35-127 website/…/ModulesSelect.tsx• L110-212 website/…/ModulesSelect.tsx• L218-265 website/…/UpdateSubmissionQueue.ts• L27-53 website/…/constants.ts• L1-3

Preference types

Each selected course has one of four planning labels. These labels describe how the student expects to use the course. They are not prerequisite checks.

CodePlanning label
01Essential Major
02Essential Second Major
03Elective
04Unrestricted Elective

References: website/…/mpe.ts• L25-42 website/…/ModuleTypeMenu.tsx• L15-29

API and serverless boundary

The browser uses a small API client for two kinds of data: a public list of CPEx courses and protected student submissions. The public list comes from the NUSMods data service. Submission requests use the website’s /api/nus boundary instead of calling the storage service from the browser. This boundary is part of the wider serverless and external APIs pattern.

Client requests

The client retrieves the CPEx course list from the cpexModules.json data endpoint. It reads and updates the signed-in student’s submission through /mpe/submissions. It also asks /auth/sso for a sign-in URL and returns to the current page after authentication.

The client adds the saved token to protected requests. A 401 response clears that token and becomes a session-expired error, which lets the CPEx page ask the student to sign in again.

References: website/…/nusmods.js• L8-20 website/…/nusmods.js• L80-86 website/…/mpe.ts• L10-43 website/…/mpe.ts• L58-77

Protected submission route

The submission route accepts GET, POST, and PUT after feature and login checks. It identifies the student from the authenticated NUS account name. A missing stored record becomes an empty submission, while a saved record is returned without its internal account identifier.

For writes, the server checks the account identifier, intended credits, course codes, and planning labels. It then stores only the fields needed by the CPEx service and assigns ranks from the preference order. The serverless integration sends this normalized record to the configured VFS storage service with service credentials held on the server.

References: website/…/submissions.ts• L16-51 website/…/mpe.ts• L8-55 website/…/mpe.ts• L64-104

The following sequence shows the protected path from a form change to saved CPEx data.

sequenceDiagram
    participant Student
    participant Browser as CPEx browser view
    participant API as /api/nus/mpe/submissions
    participant Auth as NUS sign-in
    participant Store as VFS storage

    Student->>Browser: Sign in or edit preferences
    Browser->>Auth: Request SSO URL when needed
    Auth-->>Browser: Return token through callback
    Browser->>API: GET or PUT with Authorization token
    API->>Auth: Verify SAML token
    Auth-->>API: Account identity
    API->>Store: Read or write account submission
    Store-->>API: Submission result
    API-->>Browser: Current saved state

Authenticated access

Authentication uses NUS SAML single sign-on. The browser stores the returned token locally and removes the token from the callback URL before continuing. The server verifies the token and attaches the NUS account identity to the request. The submission route uses that identity as the storage key, so a client cannot choose another student’s record through the request body.

The CPEx feature flag protects both sides of the flow. When the feature is off, the page shows its schedule state and the submission route returns 404 instead of exposing the protected operation.

References: website/…/mpe.ts• L45-56 website/…/nus-auth.ts• L20-32 website/…/nus-auth.ts• L85-122 website/…/nus-auth.ts• L125-156 website/…/mpe.ts• L106-116 website/…/submissions.ts• L47-53

Change checklist

When these files or sections are changed, remember to consider these:

  • A change to the prerequisite tree shape must stay aligned across the module data contract, tree labels, branch rules, and the readable prerequisite text shown above the tree.
  • A change to the CPEx academic year, semester, or seven-course limit must align the shared constants, page schedule, course-list source, and semester filter used for selectable courses.
  • A change to the submission shape must align the browser state, route validation, rank creation, and the record format expected by VFS storage.
  • A change to login token handling must preserve callback URL cleanup, the Authorization header, SAML verification, and session-expiry handling in the page.
  • A change to the CPEx feature flag must preserve the same access decision in both the page and the submission route.

Important failure modes

TriggerConsequenceGuard
A module has no usable structured prerequisite treeThe visual tree is absent or incomplete even when readable prerequisite text exists.Check the prerequisite text on the module page.
A tree names a retired moduleThe node remains visible but is shown as inactive.Use the linked module data to confirm the course status.
The NUS session expires during a read or saveThe token is cleared and the CPEx page asks the student to sign in again.Complete sign-in again before retrying.
The CPEx feature is disabledThe page shows schedule status and the protected route returns 404.Enable the feature for the target environment and exercise period.
A student makes several edits before a save finishesPending intermediate edits can be replaced by the latest submission.Treat the displayed saved status as the boundary for a confirmed change.
A submission fails server validationThe write is rejected and the browser offers a retry instead of recording invalid preference data.Send valid course codes, planning labels, and non-negative intended credits.

Key files

FileWhy to read it
website/…/ModulePageContent.tsxShows where readable prerequisite information and the tree fit in the module page.
website/…/ModuleTree.tsxDefines the user-facing meaning of prerequisite and unlock relationships.
website/…/MpeContainer.tsxDefines the CPEx page boundary, schedule state, and sign-in choice.
website/…/constants.tsDefines the active CPEx academic cycle and the course selection limit.
website/…/ModuleForm.tsxShows the student actions that form a ranked CPEx submission.
website/…/ModulesSelect.tsxShows the responsive course search and the rules for adding or removing choices.
website/…/ModulesSelect.test.tsxShows the user-facing guarantees for course search, duplicate prevention, and responsive display.
website/…/mpe.tsDefines the browser boundary for public course data, authentication, and submissions.
website/…/submissions.tsDefines the protected HTTP operations for CPEx submissions.
website/…/mpe.tsDefines server-side validation, normalization, feature gating, and storage access.
website/…/nus-auth.tsDefines the NUS SAML authentication boundary and user identity used by the route.
website/…/mpe.tsDefines the shared meaning of a CPEx course, preference, and submission.