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 / web-application-runtime

Web application runtime

The NUSMods web application is a browser client that helps students view course data, build timetables, plan study choices, and use related campus tools. Its runtime loads a static HTML shell, starts shared client state, restores saved user data, and maps browser URLs to feature views.

Browser entrypoints

The website has separate browser entrypoints for the full application, a timetable-only export page, and an early browser compatibility warning. The build selects the entrypoint that matches the page being served, while the full application uses the shared runtime described below.

Main website entrypoint

The main website starts the store and its persistence service before it mounts React into the #app element. It also connects browser online and offline events, prepares modal accessibility, and enables optional service-worker and analytics behavior based on the deployment environment. website/…/main.tsx• L9-46

The HTML template provides the mount point and basic document metadata. It also prepares the module-list request and venue data for the browser, then loads the generated runtime and application scripts. website/src/index.ejs#L1-L45

References: website/…/main.tsx• L9-46 website/…/index.ejs• L1-45

Timetable export entrypoint

The timetable-only page is a small browser client for rendering imported timetable data. It uses the same store setup and timetable display, but it does not mount the full navigation shell. A page-level setData function lets the export service provide modules and timetable settings before the read-only view is rendered. website/…/main.tsx• L25-62

This entrypoint uses an in-memory route context so shared timetable components can run without the normal browser URL flow. Its separate HTML page keeps export rendering independent from the main application page. website/…/TimetableOnly.tsx• L17-49

References: website/…/main.tsx• L25-62 website/…/TimetableOnly.tsx• L17-49 website/…/index.html• L1-12

Compatibility entrypoint

The compatibility entrypoint runs outside React so that users can receive a warning even when the main client cannot start. It checks the supported browser range and local storage access, then adds a dismissible warning to the document when the browser may not work well. website/…/main.ts• L1-10 website/…/main.ts• L22-73

The browser support decision comes from the project browser list and includes special handling for mobile operating systems. This keeps the warning aligned with the browsers targeted by the application rather than with one fixed user-agent list. website/…/browser.ts• L45-90

References: website/…/main.ts• L1-10 website/…/main.ts• L22-73 website/…/browser.ts• L45-90

Application shell

The application shell is the shared frame around route-specific features. It gives every page the same brand area, navigation, search, content region, feedback controls, notifications, and footer while keeping the selected route responsible for its main content.

React runtime boundary

The main React tree places error handling around the application, Redux access around all views, persistence rehydration before normal use, and browser routing around the shell. Rehydration means that saved settings and user work are restored before the main interface is released. website/…/App.tsx• L22-45

The shell also records the restored theme and beta setting before the interface becomes active. These values support analytics context without making route components responsible for startup reporting. website/…/App.tsx• L22-30

References: website/…/App.tsx• L5-15 website/…/App.tsx• L22-45

Shared interface frame

AppShell supplies the fixed brand bar, global search, week label, feature navigation, route content, feedback modal, notifications, footer, and keyboard shortcuts. It applies the selected theme and device-specific body classes at the shell boundary so feature views share one visual context. website/…/AppShell.tsx• L107-182

The shell isolates failures in optional shared controls with local error boundaries. A failure in search, feedback, notifications, or the footer therefore does not have to remove the rest of the application from the screen. website/…/AppShell.tsx• L139-181

References: website/…/AppShell.tsx• L107-182 website/…/AppShell.scss• L8-67

Route surface

The route surface maps user-facing paths to feature areas such as timetable, courses, venues, today, planner, optimisation, settings, and static information pages. The root path leads to the timetable, legacy module paths remain usable, and known old links redirect to their current destinations. website/…/Routes.tsx• L24-62

Route helpers keep links consistent for semester-specific timetables, shared timetable URLs, course pages, archive pages, and venues. Semester names are translated into stable path parts so URLs remain readable while the application can recover the matching internal semester. website/…/paths.ts• L8-20 website/…/paths.ts• L24-64

The feature navigation reflects this route surface and can preload larger feature areas when a user focuses or points to selected links. This reduces the delay between navigation intent and the next view. website/…/Navtabs.tsx• L30-95

References: website/…/Routes.tsx• L24-62 website/…/paths.ts• L8-20 website/…/paths.ts• L24-68 website/…/Navtabs.tsx• L30-95

Venue data surface

Venue data connects course schedules to readable room names and map locations. The browser can obtain the location map from the shared hosted data source and falls back to the bundled copy when that source is unavailable. website/…/github.ts• L36-59

The venue map is shared by venue search, venue detail views, timetable event maps, and the contribution view that reports unmapped rooms. Components wait for this data before rendering the parts that need it, and a failed load exposes retry behavior. website/…/withVenueLocations.tsx• L24-72 website/…/VenuesContainer.tsx• L310-337

The bundled venue map is also the source for known room names, floors, and coordinates. Recent data updates add newly verified rooms and correct an existing room location, which keeps search and map views aligned with the academic venue list. website/…/venues.json• L5823-5885

References: website/…/github.ts• L36-59 website/…/withVenueLocations.tsx• L24-72 website/…/VenuesContainer.tsx• L310-337 website/…/UnmappedVenues.tsx• L28-74 website/…/venues.json• L5823-5885

Startup data readiness

The shell treats the academic module list as a readiness gate for feature content. On mount it loads the module list, then loads the detailed data needed by modules already present in saved timetables and checks those timetable choices. Until the module list is ready, the user sees a loading state; if the list cannot load, the shell shows an API error with a retry path. website/…/AppShell.tsx• L41-105 website/…/AppShell.tsx• L115-163

The current runtime configuration selects academic year 2026/2027 and semester 1. It also defines the archive years and feature links that let the shell and route views present current, historical, and special-term data consistently. website/…/app-config.json• L1-38

The initial module and venue data come from the academic-data API boundary. Search uses the loaded module and venue lists to connect a shared header control to course and campus pages. website/…/GlobalSearchContainer.tsx• L19-73 website/…/nusmods.js• L8-20

The startup sequence is shown below. It separates document loading from client setup and makes data readiness the point at which route content becomes useful.

flowchart TD
    A[Browser loads HTML] --> B[Compatibility warning may run]
    B --> C[Main entrypoint creates store]
    C --> D[Saved state rehydrates]
    D --> E[React mounts router and shell]
    E --> F[Module and venue data load]
    F --> G[Feature route content becomes ready]

References: website/…/AppShell.tsx• L41-105 website/…/AppShell.tsx• L115-163 website/…/GlobalSearchContainer.tsx• L19-73 website/…/nusmods.js• L8-20 website/…/app-config.json• L1-38

Shared client architecture

The shared client architecture gives route views one source of client state and one path for data requests. It separates state that should survive a reload from short-lived browser state, while middleware connects requests, error reporting, and open browser tabs.

Store boundary

The store combines feature state for modules, venues, timetables, planning, settings, theme, requests, application status, and undo history. Actions change that state, selectors provide views with focused read access, and middleware handles work that crosses the state boundary. website/…/state.ts• L13-22 website/…/index.ts• L10-53

The store is configured once by the browser entrypoint. Its middleware supports asynchronous actions, request lifecycles, error reporting, and state exchange between open tabs. Development builds add action logging without changing the production runtime contract. website/…/configure-store.ts• L24-53

For the state shape, saved data, request status, settings, themes, and undo behavior, see Client state and persistence.

References: website/…/state.ts• L13-22 website/…/index.ts• L10-61 website/…/configure-store.ts• L24-53

Data request boundary

Feature actions describe data needs and send them through a common request middleware. The middleware turns one request action into request, success, or failure state and returns the response to asynchronous callers. This lets feature views use a consistent loading and error model without owning transport rules. website/…/requests-middleware.ts• L15-41 website/…/requests-middleware.ts• L60-117

The NUSMods API client builds academic-year and semester data URLs for module lists, module details, venues, and prerequisite-related data. The runtime configuration supplies the academic-data API base and the current academic year used as the default request context. website/…/nusmods.js• L23-86 website/…/app-config.json• L4-8

Other client API modules use the same action and request boundary for services such as optimisation, transport, weather, GitHub, and export.

For serverless endpoints, authentication boundaries, and external service integrations, see Serverless and external APIs.

References: website/…/requests-middleware.ts• L15-41 website/…/requests-middleware.ts• L60-117 website/…/nusmods.js• L23-86 website/…/app-config.json• L4-11

Browser lifecycle services

Startup services connect the client to browser conditions that can change while a page stays open. Online and offline events update application state, while the service worker can notify the user when a newer application shell is waiting to take control. website/…/subscribeOnlineEvents.ts• L1-11 website/…/service-worker-manager.ts• L40-84

The service worker is enabled only for secure hosted environments or an explicit debug mode. When a new worker waits, the application asks the user to refresh rather than silently replacing the running page. This protects an open session from an unexpected shell change. website/…/main.tsx• L35-46 website/…/service-worker-manager.ts• L7-12

References: website/…/subscribeOnlineEvents.ts• L1-11 website/…/service-worker-manager.ts• L40-84 website/…/main.tsx• L35-46

Build and delivery boundary

The standard web build produces the main page from entry/main, uses history fallback for client-side routes, and serves hashed assets from the site root. Production HTML controls the order of preloaded, inlined, and deferred assets, while static files provide the manifest, icons, robots rules, and service worker. website/…/webpack.config.common.js• L5-38 website/…/webpack.config.prod.js• L24-87

The website package exposes separate development modes for the normal application, the timetable export page, and a local optimiser service. Its production build prepares shared venue data before bundling, so the build and the optimiser test service use the same venue source. website/package.json• L7-15

The separate timetable-only build changes the entrypoint and public path. This allows export pages to be delivered as an independent artifact while reusing the timetable display and shared client setup. website/…/webpack.config.timetable-only.js• L10-51

References: website/…/webpack.config.common.js• L5-38 website/…/webpack.config.prod.js• L24-120 website/…/webpack.config.timetable-only.js• L10-51 website/…/webpack.parts.js• L12-28 website/package.json• L7-15

Change checklist

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

  • When adding or changing a browser entrypoint, update its HTML mount point and decide whether it needs store setup, persistence, routing, styles, service-worker handling, or analytics.
  • When changing a route, update both the route match and the URL helpers. Keep the sitemap and legacy redirects aligned with the public path set.
  • When changing startup data requirements, preserve the shell’s loading and retry behavior. Check the HTML preload or prefetch links if the first request URL changes.
  • When changing the shared state shape, review store configuration, persistence rehydration, cross-tab state exchange, and any export page that reads the store.
  • When changing theme or body-level classes, check both the main shell and the timetable-only page because they apply appearance at different boundaries.
  • When changing module detail sections, keep the side-menu anchors, page-scoped scroll behavior, archive or offered-state messaging, and route-level loading aligned.
  • When changing service-worker registration or static delivery paths, keep the hosted script path, secure-environment rule, and refresh prompt behavior consistent.
  • When changing app-config.json, check that the current academic year has matching academic-calendar and API data. Review archive, special-term, exam, and external-service links that use the same values.
  • When changing the venue map, update both the bundled browser data and the optimiser copy. Check that venue search, maps, and contribution progress use the same venue identifiers and location fields.
  • When changing the website package scripts, keep the optimiser endpoint used by development aligned with the local test service. Preserve the venue-data preparation step before production builds.

Important failure modes

TriggerConsequenceGuard
The generated HTML has no #app element.The main entrypoint throws before React can show the application.Keep the mount id in website/src/index.ejs aligned with website/…/main.tsx.
The module-list request fails during shell startup.Route content stays behind the loading gate and the user sees the course-data API error.Preserve the retry path in AppShell and keep the module-list API available.
A client route is added without history fallback or a matching public deployment rule.Direct navigation or a browser refresh can return a host-level 404 even when in-app links work.Keep client routing and historyApiFallback or its hosting equivalent aligned.
A new service worker waits while an old page is open.The user continues to run the old shell until the refresh flow completes.Keep the waiting-worker prompt and controller-change reload together.
A route path changes without updating URL helpers or the sitemap.Shared links, navigation targets, or search results can point to stale paths.Treat Routes.tsx, paths.ts, and the sitemap as one public URL contract.
The browser cannot use local storage.Saved client data and the “do not show this warning again” choice cannot use normal browser storage.Use the storage fallback and keep compatibility warnings usable without persistence.
A venue location is added or corrected in only one data copy.Venue search, maps, contribution progress, or optimiser output can disagree about the same room.Keep website/…/venues.json and the optimiser venue copy synchronized through the venue preparation step.
A venue has no location entry or coordinate.The room can remain searchable but cannot appear on a map or count as mapped in contribution progress.Keep venue identifiers and required location fields aligned with the venue list.
The configured current academic year has no matching calendar or API data.Startup requests, timetable defaults, or planner views can fail for the active term.Keep app-config.json, academic-calendar data, and the academic-data API in step.
The optimiser URL or venue-data preparation script changes in only one runtime mode.Local optimiser development or the production build can use the wrong endpoint or stale venue data.Keep the package scripts aligned with the optimiser service and shared venue source.

Key files

FileWhy to read it
website/…/main.tsxPrimary browser startup sequence for the full application.
website/…/App.tsxShared React boundaries for state, persistence, routing, and error handling.
website/…/AppShell.tsxCommon interface frame and the module-data readiness gate.
website/…/Routes.tsxPublic browser route surface and legacy redirects.
website/…/paths.tsURL construction for semester, course, archive, venue, and share links.
website/…/configure-store.tsStore creation and middleware or persistence startup.
website/…/requests-middleware.tsShared request lifecycle boundary used by feature actions.
website/…/Navtabs.tsxMain navigation and feature preload behavior.
website/src/index.ejsMain document shell, asset loading, and browser mount point.
website/…/app-config.jsonActive academic context and shared service or feature links used by the browser runtime.
website/…/main.tsPre-React compatibility and storage warning path.
website/…/main.tsxIndependent timetable export browser entrypoint.
website/…/github.tsShared venue-location loading and fallback behavior.
website/…/venues.jsonBundled venue names, floors, and map coordinates used by browser features.
website/package.jsonDevelopment, build, export, and optimiser runtime commands.
website/…/webpack.config.prod.jsProduction page and asset delivery model.
website/…/webpack.config.timetable-only.jsSeparate build for the timetable-only artifact.