Skip to main content

@fitnexa/shared Package

The @fitnexa/shared package is the shared kernel for the FitNexa platform. It provides types, configuration, API clients, server bootstrap, and middleware used by fitnexa-mobile, fitnexa-backend services, and admin apps. It has no dependency on mobile or backend; both depend on it.

πŸ“¦ Subpath Exports​

Consumers should use subpath imports so that only the needed code is pulled in (and to avoid pulling Node-only code into the mobile bundle).

ExportUse caseContents
@fitnexa/shared/typesAll appsDTOs, interfaces (User, Gym, CheckIn, etc.).
@fitnexa/shared/configMobile, AdminEnvironment only: getEnvironment(), getApiUrls(), in-memory config. Safe for browser/React Native.
@fitnexa/shared/apiMobile, AdminPlatform-agnostic ApiClient and helpers.
@fitnexa/shared/lib/utilsAllShared utilities (e.g. clsx, tailwind-merge).
@fitnexa/shared/loggerAllEnvironment-aware logger (console in browser, Winston in Node).
@fitnexa/shared/errorsBackend, MobileAppError and error types.
@fitnexa/shared/serverBackend onlyNode-only: ConfigManager, createBaseService, bootstrap, Express middleware (auth, correlation, error handler). Do not use in mobile or browser.
@fitnexa/shared/middlewareBackendExpress middleware (error handling, correlation, performance).
@fitnexa/shared/servicesOptionalShared service interfaces and implementations (e.g. authService).
@fitnexa/shared/swaggerBackendSwagger/OpenAPI utilities.

πŸ–₯️ Backend usage​

All backend services (Gateway, Identity, Gym, Content, Nutrition, Squad, Wizard, Messaging, Logging) use:

  • @fitnexa/shared/server for ConfigManager, createBaseService, and server bootstrap.
  • @fitnexa/shared/types for DTOs and request/response types.
  • @fitnexa/shared/middleware and @fitnexa/shared/errors for consistent API behavior.

Each service’s tsconfig.json uses a path mapping so that @fitnexa/shared/server resolves to the built shared package, e.g.:

"paths": {
"@fitnexa/shared/server": ["../../../fitnexa-shared/dist/server/index.js"]
}

Important: Build the shared package (npm run build in fitnexa-shared) before building or running any backend service.

πŸ“± Mobile usage​

The mobile app uses only:

  • @fitnexa/shared/types
  • @fitnexa/shared/config (environment only; does not import config-manager)
  • @fitnexa/shared/api (for base client; the app uses its own api.ts with auth and refresh)
  • @fitnexa/shared/lib/utils
  • @fitnexa/shared/errors (if needed)

It must not import @fitnexa/shared/server or the default barrel @fitnexa/shared in a way that pulls in Node/Express.

πŸ”€ Dependency direction​

  • fitnexa-shared β†’ no dependency on mobile or backend.
  • fitnexa-mobile β†’ depends on shared (types, config, api, lib/utils).
  • fitnexa-backend β†’ depends on shared (server, types, middleware, errors).

See Architecture Review for more detail.


Backend Architecture Β· Architecture Review Β· System Overview