Deployment and hosting
NUSMods runs the web experience and timetable export as separate hosted services. Vercel builds and serves these product paths, while self-managed hosts support the data and network services that sit outside the web and export request path; Export and operations gives the wider service model.
Hosting model
The hosting model separates user-facing delivery from data production. This keeps the website and export service stateless while allowing the data pipeline and public API to run on infrastructure with its own update cycle.
Hosted product services
The website and export application use separate Vercel projects. The website serves the main browser application and its serverless API handlers. The export project serves the file endpoints that create PNG and PDF timetable downloads. Each project can produce a preview from a branch or pull request, while the configured production branch produces the live service.
The two projects have different runtime needs. The website mainly delivers static browser assets and short API calls. The export project starts a browser render for each file request, so its image and PDF functions have a 15-second execution limit.
References: DEPLOYMENT.md• L7-27 website/vercel.json• L1-9 export/vercel.json• L1-20
Self-managed service boundary
The data pipeline is outside the Vercel projects. Scrapers acquire academic data, a static web server publishes generated JSON through api.nusmods.com, and search infrastructure supports product queries. A data refresh therefore changes the public data source without changing a browser session or an export service record.
The infrastructure files also describe a self-managed network edge. A machine-level proxy provides HTTPS and sends traffic to services on the host, while an instance-level proxy maps website, export, and public API paths to their service targets.
References: DEPLOYMENT.md• L37-47 DEPLOYMENT.md• L78-113 infra/…/README.md• L1-2 infra/…/docker-compose.yml• L2-25
Deployment configuration
Deployment configuration turns each workspace into the runtime artifact expected by its host. The website produces browser assets and serverless handlers. The export workspace produces a Node service that also needs the timetable-only browser page and module data at run time.
Website deployment artifact
The website build creates the main browser application under dist and a separate timetable-only page under dist-timetable. The latter is the page that the export service opens to reproduce a read-only timetable. The production build also selects content for the deployment environment, such as preview or production static files.
Vercel installs from the locked workspace, runs the website build, includes the files needed by website functions, and applies cache rules to hashed assets. Its /api rewrite keeps the public data API behind the website's stable path, while browser routes remain part of the hosted application shell.
References: website/package.json• L7-16 website/…/webpack.parts.js• L12-28 website/…/webpack.config.prod.js• L24-87 website/vercel.json• L1-55
Export deployment artifact
The export deployment combines a short-lived Node service with a browser page supplied by the website build. At startup, the service checks its academic-year and module-data settings, starts Chromium, loads either a configured page URL or a built page file, and then listens for export requests.
Hosted export functions use the same render path as the local service. The deployment must therefore provide a valid page source, matching academic data, a usable Chromium runtime, and error-reporting configuration when operational error feedback is required. The service package exposes the build, start, development, and validation commands used by these environments.
References: export/package.json• L5-18 export/…/config.ts• L1-20 export/…/index.ts• L9-66 export/vercel.json• L1-20
Build and release gates
Continuous integration checks the website and export workspaces before a hosted release can be trusted. The website job runs code and style checks, type checks, tests, integration tests, and a production build. The export job runs linting, type checks, and its production build.
Vercel build filtering controls when hosted builds run. Production branches and commits marked with [build] are allowed through, while some maintainer branch and pull request builds are skipped to reduce unnecessary deployments. This gate affects delivery rather than application behavior.
References: .circleci/config.yml• L76-133 vercel_ignore_build.sh• L1-41 website/package.json• L16-25 export/package.json• L9-18
Service routing
Routing gives users stable public paths while allowing the services behind them to move between hosted and self-managed environments. The key contract is the boundary between the main website, export requests, and public academic data.
Hosted request paths
The hosted website keeps public data under /api and forwards that path to api.nusmods.com. Its API responses include cross-origin headers for browser clients. The export project exposes /api/export/image and /api/export/pdf as file-producing functions, then returns a local 404 page for paths that are not part of the export surface.
The website creates export links for the separate export service rather than sending export work through the website's own API. This preserves a clear boundary between the browser application and the browser-rendering workload; Timetable export service describes the request and rendering contract.
References: website/vercel.json• L10-55 export/vercel.json• L4-20 export/…/image.ts• L8-44 export/…/pdf.ts• L6-17
Self-managed request paths
The self-managed instance proxy sends ordinary traffic to the website service, removes /export before forwarding export traffic, and removes /api before forwarding public data requests. This lets the public URL stay stable even when the target service expects a shorter path.
At the machine edge, Traefik accepts HTTP and HTTPS traffic, redirects HTTP to HTTPS, and routes API traffic to the public API host. Docker attaches the proxy to a shared network and exposes the public ports. Cloudflare credentials and certificate storage are host concerns, not application settings.
This diagram shows the two hosting boundaries and the paths that connect them.
flowchart LR
User[Browser] --> Web[Vercel website]
Web --> Data[Public API data host]
User --> Export[Vercel export functions]
Edge[Self-managed HTTPS edge] --> Instance[Website and export services]
Instance --> Data
References: infra/…/Caddyfile• L1-28 infra/…/traefik.toml• L1-48 infra/…/docker-compose.yml• L2-20
Operational entrypoints
Operators use workspace commands for local checks, CI commands for release validation, and service-manager commands for the self-managed data host. These entrypoints test the same cross-service assumptions that production depends on without making the website and export service share a process.
Website verification
A production-like website check builds the browser assets and serves dist as static files. The normal development entrypoint runs the full browser application with a local optimiser path. A separate development entrypoint serves the timetable-only page on port 8081 for export work.
Use the website workspace when checking changes to the application shell or the page consumed by export. If the timetable-only artifact changes, also check a PNG and a PDF through the export service because the export runtime depends on that artifact.
References: DEPLOYMENT.md• L19-35 website/package.json• L7-15 website/…/webpack.config.timetable-only.js• L10-51
Export service runtime
The export service starts with pnpm build and pnpm start in a built environment. Local development uses the website's main and timetable-only development servers together with pnpm dev in the export workspace. The PAGE setting selects the page source. ACADEMIC_YEAR identifies the module data set. MODULE_DATA selects local module data when the deployment provides it.
The process does not accept requests until Chromium has started and the page source is ready. A failed browser start stops the service, which makes browser and page availability startup checks rather than hidden request-time problems.
References: export/package.json• L9-18 export/…/config.ts• L1-20 export/…/index.ts• L39-66 export/README.md• L9-30
Data host operations
The self-managed data host uses Node 22, pnpm, PM2, and Nginx as its main operational tools. PM2 keeps the scraper running. Nginx serves the generated JSON directory. After a repository update, the operator rebuilds the scraper, restarts its PM2 process, and runs the scraper health check.
These commands operate the data boundary rather than the browser applications. Validate public API access after a data update because a healthy scraper process does not by itself prove that the generated files are reachable by the website or export service.
References: DEPLOYMENT.md• L41-68 DEPLOYMENT.md• L78-129
Change checklist
When these files or sections are changed, remember to consider these:
- Keep the website's
dist-timetableartifact, its public path, and the export service'sPAGEsetting aligned. - Keep the export function duration aligned with Chromium startup, module-data loading, and file capture time.
- Keep the website
/apirewrite and self-managed proxy prefix removal aligned with the public API URL. - Keep the export endpoint paths aligned between the website's download links, Vercel routes, and any instance proxy.
- Keep the export academic-year and module-data settings aligned with the data set served by
api.nusmods.com. - Keep build filtering aligned with the branches and pull request types that must receive preview or production validation.
- Keep HTTPS certificate storage, Cloudflare access, and Docker network exposure outside application configuration when changing the machine edge.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
The export page artifact is not built or PAGE points to the wrong source | The export process cannot load the timetable page and image or PDF requests fail | Build the website timetable-only artifact and verify the export page source together |
| Export rendering takes longer than the Vercel function limit | The user receives no completed file | Keep browser startup and capture within the configured 15-second limit |
ACADEMIC_YEAR does not match the available module data | The export service stops at startup or cannot prepare a timetable | Set a valid academic year and check the matching data source |
| A proxy keeps or removes the wrong path prefix | Website, export, or public API requests reach an invalid route | Test the public path through each proxy layer after routing changes |
| The Vercel ignore rule skips a required build | A branch or pull request has no updated preview | Use a production branch, [build], or an allowed pull request source when validation is needed |
| The scraper runs but Nginx serves stale or inaccessible files | The website and export service use stale or missing academic data | Check generated files, permissions, Nginx access, and public API responses |
Key files
| File | Why to read it |
|---|---|
| DEPLOYMENT.md | Describes the split between hosted product services and self-managed data operations. |
| website/vercel.json | Defines website build behavior, function files, API rewrites, and cache headers. |
| export/vercel.json | Defines export build behavior, fallback routing, and browser-render function limits. |
| vercel_ignore_build.sh | Defines which branches, commits, and pull requests can trigger hosted builds. |
| website/package.json | Lists the website build and local verification entrypoints. |
| website/…/webpack.config.timetable-only.js | Defines the separate browser artifact consumed by export rendering. |
| export/package.json | Lists the export service build, start, development, and validation entrypoints. |
| export/…/config.ts | Defines the deployment settings that connect export rendering to its page and data. |
| export/…/index.ts | Shows the export process startup checks and listening boundary. |
infra/instance/Caddyfile | Defines self-managed routing between website, export, and public API paths. |
| infra/…/docker-compose.yml | Defines the machine proxy container, public ports, credentials, and shared network. |
| infra/…/traefik.toml | Defines the machine-level HTTPS entrypoint and public API route. |
| .circleci/config.yml | Shows the CI checks and build gates for website and export workspaces. |