Skip to content

API Import Aliases

This workflow defines the canonical import style for apps/api.

Scope

  • Aliases are internal to apps/api only.
  • Other monorepo apps/packages must not import API internals through @api/*.

Supported Aliases

  • @api/core/* -> apps/api/src/core/*
  • @api/shared/* -> apps/api/src/shared/*
  • @api/modules/* -> apps/api/src/modules/*
  • @api/* -> apps/api/src/*

Usage Rules

  • Prefer aliases for cross-boundary imports:
    • module -> core
    • module -> shared
    • module -> another module
  • Keep short local relatives for nearby files inside the same module subtree.
  • Do not introduce deep ../../../../ chains when an alias can represent intent.

Examples

ts
import { PublicRoute } from '@api/core/decorators/public-route.decorator';
import { AppConfigService } from '@api/shared/infrastructure/envs/app-config.service';
import { UserRegisteredEvent } from '@api/modules/identity/domain/events/user-registered.event';

Runtime and Tooling Notes

  • Build: apps/api runs nest build and then tsc-alias so production JS in dist resolves aliases with plain Node.
  • Jest: moduleNameMapper maps @api/* to <rootDir>/* (with rootDir: "src").
  • TypeORM CLI migrations: path resolution works through ts-node + tsconfig-paths/register.