Shared Infrastructure

June 14, 2026 · View on GitHub

Anti-duplication index. Before creating a new module, service, util class, or base component, search this document and the feature catalogs (features-backend.md, features-frontend.md).

Do Not Build (Already Exists)

If you need…Use this insteadDo NOT create…
Background / scheduled jobsTasksModule + TaskTypeEnum + task implementationBull queue, Redis queue, separate cron module
Distributed lockingMutexService.execWithMutex()Custom lock collection or in-memory mutex
Failure isolation for external callsCircuitBreakersService.executeWithCircuitBreaker()Ad-hoc retry/circuit logic
MongoDB transactionsDbTransactionsService.exec()Manual session management
String/date/number/crypto helpersUtilsModule servicesDuplicate util classes
Pagination / list queriesShapeableQuery + BaseService.get()Custom paging helpers or raw find()
CRUD service baseBaseService<T>New generic repository layer
Model base fieldsBaseEntityDuplicate timestamp/createdBy schemas
Model → DTO mappingBaseMapper + entity mappersInline mapping in controllers
HTTP API client (frontend)BaseApiService + queryToParams()New HTTP wrapper
Admin list pageBaseListComponent<T>Custom table/paging component
Admin create/edit pageBaseEditComponent<T>Custom form loading boilerplate
Auth session (frontend)AuthSignal, authInterceptor, guardsNew token storage / interceptor
Shared DTOs/enums@app/contractsDuplicate types in frontend or backend
Operational alertsAlertsServiceSeparate notification/logging module
Domain HTTP errorsCustom exceptions in shared/exceptions/Raw HttpException or generic errors
External HTTP client baseBaseApiService (backend)New Axios wrapper (note: currently unused; prefer extending it)

Backend — Base Classes

ClassPathUse for
BaseEntitybackend/src/shared/base/base-entity.tsAll Mongoose models (_id, timestamps, createdBy)
BaseService<T>backend/src/shared/base/base-service.tsCRUD helpers, pagination, existence checks, bulk ops
BaseMapperbackend/src/shared/base/base-mapper.tsObjectId/string conversion, paged mapping
BaseApiServicebackend/src/shared/base/base-api.service.tsExternal HTTP clients (Axios error logging, rate-limit alerts)

Backend — Contracts

PiecePathUse for
ShapeableQuerybackend/libs/contracts/src/queries/shapeable-query.tsBase for all list/filter queries (page, limit, sortBy, include, …)
PagedListDto<T>backend/libs/contracts/src/dto/paged-list.dto.tsStandard list response shape
ErrorCodebackend/libs/contracts/src/codes/error-codes.tsShared error constants (frontend + backend)
Enumsbackend/libs/contracts/src/enums/Never redefine roles/types locally

Backend — Resilience & Concurrency

ServicePathKey method
MutexServicebackend/src/utils/services/mutex.service.tsexecWithMutex()
CircuitBreakersServicebackend/src/utils/services/circuit-breakers.service.tsexecuteWithCircuitBreaker(), reset()
DbTransactionsServicebackend/src/utils/services/db-transactions.service.tsexec(fn)

Backend — Utility Services (UtilsModule)

ServicePathRole
CryptographyHelpersServicebackend/src/utils/services/cryptography-helpers.service.tsAES encrypt/decrypt, HMAC, RSA sign/verify
RandomServicebackend/src/utils/services/random.service.tsCrypto-safe random int/float/string
StringUtilsServicebackend/src/utils/services/string-utils.service.tsEmoji strip, URL encode, hex
DateUtilsServicebackend/src/utils/services/date-utils.service.tsStart/end of day, date overlap
NumberUtilsServicebackend/src/utils/services/number-utils.service.tsRound, clamp
EnumUtilsServicebackend/src/utils/services/enum-utils.service.tsEnum conversion helpers

Backend — Auth & Security

ComponentPathRole
AuthServicebackend/src/auth/services/auth.service.tsLogin, JWT, refresh tokens
JwtGuard, RolesGuardbackend/src/auth/guards/Route protection
@Roles()backend/src/auth/decorators/roles.decorator.tsRBAC metadata
@LoggedInUser()backend/src/shared/decorators/logged-in-user.decorator.tsInject req.user
Custom exceptionsbackend/src/shared/exceptions/app-*.tsDomain HTTP errors

Backend — Background Tasks

ComponentPathRole
TasksRuntimeServicebackend/src/tasks/services/tasks-runtime.service.tsPolls MongoDB tasks, registers cron/timeout jobs
TasksServicebackend/src/tasks/services/tasks.service.tsTask CRUD + running flags
TaskLogsServicebackend/src/tasks/services/task-logs.service.tsExecution log persistence
TaskImplementationsbackend/src/tasks/implementations/task-implementations.tsRegistry: TaskTypeEnum → runner
TasksDefinitionbackend/src/tasks/definitions.tsSeed definitions for default tasks

To add new background work: add TaskTypeEnum value, create implementation, register in TaskImplementations, optionally seed in definitions.ts.

Backend — Notifications

ServicePathRole
AlertsServicebackend/src/notifications/services/alerts.service.tsOperational error/rate-limit notifications
ContactRequestServicebackend/src/notifications/services/contact-request.service.tsContact form inbox

Frontend — Base Classes

ClassPathUse for
BaseComponentfrontend/projects/common-ui/base/base.component.tsAll components: auth signal, error extraction, mobile detection
BaseServicefrontend/projects/common-ui/base/base.service.tsNon-HTTP services: subscription cleanup
BaseApiServicefrontend/projects/common-ui/base/base-api.service.tsHTTP services: HttpClient, queryToParams()
BaseListComponent<T>frontend/projects/common-ui/base/base-list.component.tsAdmin list pages: paging, filters, MatTable
BaseEditComponent<T>frontend/projects/common-ui/base/base-edit.component.tsAdmin create/edit/detail pages
BasePickerComponent<T>frontend/projects/common-ui/base/base-picker.component.tsEntity picker controls (no concrete pickers yet)
BaseInputComponentfrontend/projects/common-ui/base/base-input.component.tsReusable form input (no concrete inputs yet)
BaseButtonComponentfrontend/projects/common-ui/base/base-button.component.tsReusable button (no concrete buttons yet)

Frontend — Auth

PiecePathRole
AuthSignalfrontend/projects/common-ui/auth/auth.signal.tsSignal + localStorage session state
authInterceptorfrontend/projects/common-ui/auth/http-auth.interceptor.tsBearer token, auto-refresh on 401
isLoggedIn guardfrontend/projects/common-ui/auth/is-logged-in.guard.tsRedirect unauthenticated users
hasRole guardfrontend/projects/common-ui/auth/has-role.guard.tsCheck route.data.roles

Frontend — Pipes

PipePathPurpose
StatusEnumPipecommon-ui/pipes/status-enum.pipe.tsEnum strings → title case
TimeAgoPipecommon-ui/pipes/time-ago.pipe.tsRelative time
ShortNumberPipecommon-ui/pipes/short-number.pipe.tsAbbreviated numbers (K, M)
PrettyJsonPipecommon-ui/pipes/pretty-json.pipe.tsJSON formatting
SafeUrlPipecommon-ui/pipes/safe-url.pipe.tsSanitized URLs
TxHashPipecommon-ui/pipes/tx-hash.pipe.tsTransaction hash display (CryptoNetworkEnum)
CryptoNetworkPipecommon-ui/pipes/crypto-network.pipe.tsCrypto network labels (CryptoNetworkEnum)

Frontend — Utils

UtilityPathPurpose
StringUtilscommon-ui/utils/string-utils.tsrandomString, hex, title case, kebab/camel
DateUtilscommon-ui/utils/date-utils.tsDate helpers
NumberUtilscommon-ui/utils/number-utils.tsNumber helpers

Frontend — Dialog System (built, unused)

DialogService, DialogComponent, DialogRef in common-ui/dialog/ — use this before building a new modal system.

Adding a New Reusable Piece

When you introduce infrastructure others should reuse, append a row to the relevant table above and note which feature doc references it.

| `MyHelperService` | `backend/src/utils/services/my-helper.service.ts` | One-line role |

Last updated

2026-06-15