ArchiPy's layer-first architecture, vocabulary and unit of work, carried into NestJS by extending the framework's own primitives instead of replacing them.
This repository is the library. It is an npm workspaces monorepo.
| Package | Role |
|---|---|
@archinest/core |
Config, entity bases, error taxonomy, exception filter, @Atomic() contract, BaseDto. No ORM dependency. |
@archinest/postgres-prisma |
PrismaService, PostgresAdapter, PostgresModule and the AtomicRunner implementation, built on @nestjs-cls/transactional. |
@archinest/postgres-typeorm |
The TypeORM alternative to @archinest/postgres-prisma: TypeOrmModule, TypeOrmAdapter, TypeOrmAtomicRunner, entity bases, error mapping and migration helpers. See packages/postgres-typeorm/README.md. |
@archinest/redis |
RedisAdapter on ioredis, RedisMock, cache decorators, distributed locks and rate limiting. See packages/redis/README.md. |
@archinest/observability |
OpenTelemetry traces, metrics and logs over OTLP, a structured logger with trace correlation, @Traced() and health endpoints. See packages/observability/README.md. |
@archinest/keycloak |
Keycloak adapter and admin API, JWT verification, auth guards, @Roles() and @CurrentUser(), and JWT, password and TOTP utilities. See packages/keycloak/README.md. |
@archinest/lint-config |
oxlint preset carrying the architecture policies, plus fixtures that prove the rules still fire. |
ArchiNest does not cover all of ArchiPy yet. docs/archipy-parity-checklist.md lists what is still missing, package by package, with the ArchiPy module and feature each item should follow.
ArchiNest buys enforceable architecture and consistency with ArchiPy services at the cost of meaningfully more structure than idiomatic NestJS. The official Nest and Prisma recipe, with Prisma types used directly in a service, is simpler and correct for a small application.
This structure earns its place when there are several domains, more than one developer, or teams moving between ArchiPy and NestJS codebases. It is the wrong choice for a single-domain service.
Node 22 or newer. NestJS 12, TypeScript 6, Prisma 7.10.x. See NOTES.md for the exact versions that were verified.
import { Atomic, AlreadyExistsError, DeletableEntity, buildConfig, BaseConfig } from '@archinest/core';
import { PostgresAdapter, PostgresModule } from '@archinest/postgres-prisma';Configuration is a class with sections. Environment variables use SECTION__FIELD.
class AppConfig extends BaseConfig {
override customize(): void {
this.HTTP.PROJECT_NAME = 'orders';
}
}
const config = buildConfig(AppConfig);APP__ENVIRONMENT=production
HTTP__SERVE_PORT=8080
POSTGRES__HOST=db.internal
Errors carry a stable code and an HTTP status. A global filter turns them into a stable body.
class UserAlreadyExistsError extends AlreadyExistsError {
constructor(details?: Record<string, unknown>) {
super(details, { code: 'USER_ALREADY_EXISTS' });
}
}providers: [{ provide: APP_FILTER, useClass: DomainExceptionFilter }]The unit of work lives on logics. Nested calls reuse the open transaction.
@Injectable()
export class UserLogic {
constructor(private readonly users: UserRepository) {}
@Atomic()
async createUser(input: CreateUserInputDto): Promise<CreateUserOutputDto> {
if (await this.users.existsByEmail(input.email)) {
throw new UserAlreadyExistsError({ email: input.email });
}
return this.users.create(CreateUserCommandDto.from(input));
}
}Repositories reach the ambient client through PostgresAdapter.
@Injectable()
export class UserPostgresAdapter {
constructor(private readonly postgres: PostgresAdapter<PrismaClient>) {}
insert(email: string) {
return this.postgres.client.user.create({ data: { email } });
}
}Wiring the module. The application owns the generated Prisma client and its driver adapter, so the library never imports a generated client.
PostgresModule.forRootAsync({
inject: [AppConfig],
useFactory: (config: AppConfig) => ({
client: new PrismaClient({
adapter: new PrismaPg({ connectionString: buildPostgresUrl(config.POSTGRES) }),
}),
}),
})PostgresModule is global and registers ClsModule with the transactional plugin, so AtomicRunner is injectable everywhere. Do not register a second ClsModule.forRoot with its own transactional plugin for the same connection.
npx archinest-lint-config
writes a .oxlintrc.json that extends the preset. oxlint 1.93 does not inherit settings through extends, so the command copies the boundaries element definitions into your config. Alternatively point oxlint straight at the preset:
oxlint -c node_modules/@archinest/lint-config/oxlintrc.base.json src
The preset needs oxlint, eslint-plugin-boundaries, eslint-plugin-import-x and eslint-import-resolver-typescript installed, all pinned exactly.
npm install
npm run build
npm run lint
npm test
Integration tests start their own containers through testcontainers, so they need Docker. Run npm run test:integration (add a path such as packages/redis/test to run one package). Without Docker they are skipped locally and fail when CI=true. Set ARCHINEST_TEST_DATABASE_URL to use an existing Postgres instead of a container.
docker run -d --rm -p 54329:5432 -e POSTGRES_PASSWORD=pw -e POSTGRES_DB=archinest_test postgres:17-alpine
ARCHINEST_TEST_DATABASE_URL=postgresql://postgres:pw@localhost:54329/archinest_test npm run test:integration
The TypeORM suite and the compiled ESM migration check run in the same command.
npm run verify runs build, lint, typecheck and tests in order.
The Gherkin acceptance features in features/ run with npm run test:features (one Cucumber process per feature, in parallel), npm run test:features:seq (one process) and npm run test:coverage. They start their own containers through testcontainers, so they need Docker. npm run pull-test-images pre-pulls the images. See features/README.md.
Source files carry no comments. Naming and structure carry the meaning, and ARCHITECTURE.md carries the rationale. npm run lint enforces this.
examples/starter is a complete NestJS service built on these packages: users and orders on Prisma or TypeORM, Keycloak authentication, a Redis cache, tracing, metrics and health probes, with the architecture rules enforced by lint. Build the library at the repository root first, then follow examples/starter/README.md.