University of Peradeniya crestSCS Documentation
University of Peradeniya crestSCS Documentation
Department website

Start here

Repository handbookRepository overviewDevelopment

System design

ArchitectureAuthentication and authorizationPublic dataAPI contractsSchemas
UI system

Applications

Department Web applicationPeople applicationProjects applicationPortal application

Services

API serviceGitHub App serviceMailer service
Service internals
API internalsAPI request lifecycleAPI identity and stateAPI public-data mutations

Shared packages

Schemas packageUI packageTypeScript configuration packageESLint configuration package

Development workflow

Testing and verificationDependency managementDocumentation authoringUI quality assurance

Operations

Continuous integrationEnvironment variablesOperationsSecurityTroubleshooting

Reference

Route referenceGlossary
Service internalsAPI service

Source map, responsibilities, dependencies, and verification boundaries for the browser-facing API Worker.

API internals

services/api is the only backend that the Portal browser calls directly. It combines Better Auth, D1-backed application state, authorization, public-data reads, and orchestration of the two internal services. It does not write the public-data repositories or send SMTP messages itself.

Source map

AreaSourceResponsibility
Worker entrysrc/index.tsbinds the execution context, applies edge guards, then selects Better Auth or application routing
Authenticationsrc/auth/auth.tsBetter Auth providers, OTP, passkeys, sessions, account linking, rate limits, and auth hooks
Edge policysrc/middleware and src/httpCORS, session resolution, stable errors, and unexpected-error containment
Routingsrc/routes/index.tsmethod and exact/prefix path dispatch
Use casessrc/servicesauthorization, validation, public-data interpretation, and downstream orchestration
D1 accesssrc/repositoriespermissions, auth-account lookup, and proxy settings
Internal clientssrc/clientsbounded calls to GitHub App; mail delivery is wrapped in src/services/mailer.service.ts
Contracts@scs/schemasshared request, response, operation, person, project, and academic schemas
D1 schemamigrationsappend-only Better Auth and application-state migrations

Runtime boundaries

The Worker receives bindings through Env in src/types/env.ts. AUTH_DB is its only database. Public records are read from DATA_PUBLIC_BASE_URL; changes are submitted to GitHub App. A configured Cloudflare GITHUB_APP service binding is preferred, while GITHUB_APP_API_URL remains the HTTP transport boundary. OTP delivery goes to Mailer with MAILER_API_KEY.

Detailed guides:

  • Request lifecycle explains dispatch, CORS, response behavior, pagination, and downstream failure mapping.
  • Identity and state explains Better Auth, permission resolution, D1 ownership, and administrative invariants.
  • Public-data mutations explains profile, project, course, and offering workflows, including durable operations.

Use Service API for the concise maintainer entry point, Authentication for system-wide identity policy, and Schema reference for domain fields.

Verification map

test/characterization pins HTTP behavior and compatibility at the Worker boundary. test/unit covers auth configuration, session cookies, pagination, the GitHub App client, Mailer request construction, and public-project helpers. The workspace gate is:

bun --filter '@scs/api' lint
bun --filter '@scs/api' typecheck
bun --filter '@scs/api' typecheck:test
bun --filter '@scs/api' test
bun --filter '@scs/api' knip
bun --filter '@scs/api' build

Service internals

Code-derived guides to the API, GitHub App automation, and Mailer runtimes and their boundaries.

API request lifecycle

How the API Worker receives, dispatches, validates, and responds to browser and internal-service requests.

On this page

API internalsSource mapRuntime boundariesVerification map