Backend Documentation

Errors and Observability

Operational behavior for failures, diagnostics, and runtime visibility.

Global Error Handler

`app.js` includes centralized error middleware that logs URL, method, IP, and user agent metadata before returning response payloads.

404 Handler

Non-matched routes return `Resource not found` with status code `404` via terminal middleware.

Health Endpoint

`GET /api/health` reports environment, uptime, memory usage, and Mongo connection state to support readiness checks.

Graceful Shutdown

`hooks/performance.js` handles controlled server shutdown to reduce dropped connections and abrupt termination behavior.