ื“ืœื’ ืœืชื•ื›ืŸ ื”ืจืืฉื™

Request Lifecycle

Understand how an HTTP request flows through the Ever Gauzy API from entry to response.

Overviewโ€‹

Phase 1: Middlewareโ€‹

Express middleware processes the raw request:

MiddlewarePurpose
helmetSecurity headers
corsCORS handling
compressionResponse compression
body-parserJSON body parsing
cookie-parserCookie parsing

Phase 2: Guardsโ€‹

Guards determine if the request is authorized:

GuardOrderPurpose
TenantPermissionGuard1stExtract and validate tenant
PermissionGuard2ndCheck user permissions
RoleGuard3rdCheck user role (optional)
FeatureFlagGuard4thCheck feature availability

Phase 3: Interceptorsโ€‹

Interceptors transform request/response:

InterceptorPurpose
TransformInterceptorStandardize response format
TimeoutInterceptorRequest timeout handling
LazyLoadInterceptorLazy-load relations

Phase 4: Pipesโ€‹

Pipes validate and transform input:

PipePurpose
ValidationPipeDTO class-validator
UUIDValidationPipeUUID parameter validation
ParseJsonPipeJSON query param parsing

Phase 5: Controller โ†’ Service โ†’ Repositoryโ€‹

The actual business logic execution:

  1. Controller โ€” route handler, delegates to service
  2. Service โ€” business logic, tenant filtering
  3. Repository โ€” database operations (TypeORM/MikroORM)

Phase 6: Responseโ€‹

The response flows back through interceptors for transformation before being sent to the client.

Error Handlingโ€‹

Errors at any phase are caught by the global exception filter: