Skip to content

Server Common

server-common is the server runtime foundation shared by all server entry points (API, hook, job). It contains the bootstrap logic, configuration loading, dependency wiring, and shared infrastructure helpers. It defines how the server starts and executes, not what the application does.

On This Page


Purpose

  • Provide the server runtime foundation for all server entry points (API, hook, job)
  • Hold bootstrap logic, configuration loading, dependency wiring, shared infrastructure helpers, static fonts, and static data files
  • Define how the server starts, initializes, and executes - not what the application does
  • All server modules may depend on server-common, but server-common must never depend on domain or business logic

Design Principles

PrincipleDetail
No business or domain logicBelongs in server-service
No entity-specific workflowsBelongs in server-service
Infrastructure-firstConcerned with HOW the server runs
Execution-context-awareSame code works in Docker and Lambda
Deterministic and predictable initializationNo surprises on cold start
Explicit dependency loading and injectionEverything goes through Lib
One-time initialization where possibleHeavy work happens once, not per request
Reusable across APIs, hooks, jobs, workersSingle foundation for every entry point
Safe in multiple execution environmentsDocker, Lambda, cron, workers

File Organization

Directory: src/server/common/

File names are role-based, not feature-based. There is no user.js here - users live in model/, controller/, and service/.


Standard Files

FileRoleDetail
handler.jsRuntime Entry HandlerFirst executable entry point (e.g., Lambda handler). Standalone - no shared dependencies. Executed before the project loader
config.jsConfiguration FileStatic configuration defaults and constants. Default environment values. No process.env reads
loader.jsLoader / BootstrapLoads configuration (static + environment overrides), initializes shared dependencies (helpers, SDKs, clients), exposes the shared Lib and Config containers. Full detail in server-loader.md
functions.jsShared Execution HelpersStandardizes execution patterns across APIs and services. Wraps request initialization and response formatting. Holds reusable constants, enums, and shared definitions. Example: successResponse(data), errorResponse(error)
auth.jsAuth ModuleValidates API authentication (API keys, secrets, cookies). Used by externally exposed endpoints (APIs, hooks). Decides API scope: public, protected, admin
data/Static Data FilesStatic JSON data files used by the application
font/Static Font FilesFont files used by the application

Boundary Rules

server-common must NOT

  • Contain business or domain logic
  • Reference entities (user, order, message, ...)
  • Implement API endpoints
  • Implement cron or job logic directly
  • Call into server-service, server-controller, or server-interfaces

Allowed dependencies

  • core-helper-modules
  • server-helper-modules
  • External SDKs and libraries

Disallowed dependencies

  • Client code
  • Client helper modules

Mental Model

A simple test for whether a piece of code belongs in server-common:

QuestionLives in
"How does the server start and safely execute?"server-common
"What does the application do?"server-service
"How is this exposed?"server-interfaces

If the answer touches the domain (users, orders, surveys, ...), it does not belong in server-common.


Further Reading

Released under the MIT License.