SKILL.md
Vendix Backend Middleware
Source of Truth
apps/backend/src/common/middleware/domain-resolver.middleware.tsapps/backend/src/common/interceptors/request-context.interceptor.tsapps/backend/src/common/context/request-context.service.tsapps/backend/src/app.module.ts
Domain Resolver Reality
DomainResolverMiddleware is not a generic all-route tenancy resolver. It currently runs only for ecommerce-style requests and exits early unless req.originalUrl contains /ecommerce/.
It resolves store context in this order:
x-store-idheader orstore_idquery param.- Hostname resolution via
PublicDomainsService.resolveDomain(hostname). - Cached hostname lookup through Nest
cache-manager.
The middleware writes:
req['domain_context'] = { store_id, organization_id? }
It does not write req.storeid / req.organizationid / req.domain_type directly.
Request Context Reality
RequestContextService is AsyncLocalStorage-based, not request-scoped DI over REQUEST.
RequestContextInterceptormerges auth user data andreq['domain_context'].- It propagates
x-request-idinto the request context. - It calls
RequestContextService.asyncLocalStorage.run(contextObj, ...). - Consumers read static helpers like
getStoreId(),getUserId(),getRequestId(),isSuperAdmin().
Rules
- Do not document or implement new middleware assuming route-param tenancy.
- Do not inject a request-scoped
RequestContextService; use the real ALS/static API. - If you need tenant context in backend logic, prefer the interceptor-populated request context and scoped Prisma services.
- If you need hostname-based public store resolution outside ecommerce routes, verify the route path and current middleware coverage before expanding behavior.
Related Skills
vendix-multi-tenant-contextvendix-prisma-scopesvendix-backend-domain