Shared libraries
nxt-backend uses three shared libraries to keep cross-app concerns consistent while preserving app-level ownership of business behavior.
Libraries
libs/core: shared NestJS domain/infrastructure modules used by all apps.- Core database access (
CoreTypeOrmModule,CorePgModule,GlobalSupabaseModule). - Shared clients for CALIN, Victron, Solcast, Make, SendGrid.
- Shared entities/services for accounts, grids, meters, payouts, routers, and related domain records.
- Core database access (
libs/helpers: framework-agnostic TypeScript helper functions plus a small NestJS pipe set.- Includes shared array/number/query/time/promise helpers and provider-specific utility wrappers.
query-helperssupports loading raw SQL files at runtime from app query folders.
libs/timeseries: named TypeORM data source and entity layer for TimescaleDB.- Exposes
TimeseriesTypeOrmModulewithtimescaleconnection. - Defines snapshot entities (meter/grid/mppt/router/DCU/order/exchange/business snapshots).
- Contains dedicated Timescale migration tooling (
libs/timeseries/migration,ormconfig.ts).
- Exposes
Boundary rules
- Shared libraries should contain cross-app capabilities, not single-app business logic.
- Domain behavior owned by one app stays in that app unless there is proven reuse.
- Library changes should include impact checks for all known consumers.
Usage guidance by component
- API and workflow services (
tiamat,talos,loch,yeti) import from@corefor shared modules/services/entities. - Utility-only behavior should come from
@helpers; avoid embedding framework/service state in helper modules. - Any app writing/reading Timescale entities should use
@timeseriesfor consistent schema mapping.
Change management
- Prefer additive changes to avoid breaking multiple apps.
- Track coupling risks when shared interfaces are changed.
- For risky shared changes, verify at minimum:
- app build/serve across affected services,
- core module bootstrapping,
- cross-app data/entity compatibility.
Source of truth
libs/core/README.mdlibs/helpers/README.mdlibs/timeseries/README.md