# Core

### What it is responsible for

Core manages Nest's core functionality, low-level services, and utilities, while routing work through symbols such as `RouterExplorer`, `RouterExecutionContext`, and `RouterProxy`. Its named routing members, `Routes`, `RouteTree`, `RouteDefinition`, `RoutePathFactory`, and `RouteParamsFactory`, indicate responsibility for route definitions, paths, parameters, exploration, and execution context. `RouterExceptionFilters` and `ExceptionsFilter` place exception filter handling alongside that route work. The subsystem also owns request symbols including `REQUEST`, `REQUEST_CONTEXT_ID`, and `requestProvider`. For SSE, its documented transformer turns “messages” into W3C event stream content; the relevant path demands an Observable stream.

### What it refuses

Core rejects forbidden activation with `ForbiddenException` when `!canActivate`; undefined request mappings with `UnknownRequestMappingException` when `isUndefined(path)`; and missing continuation with `InternalServerErrorException` when `!next`. It rejects non Observable SSE results with: “You must return an Observable stream to use Server-Sent Events (SSE).” when `!isObservable(value)`. It rejects non array filters with `InvalidExceptionFilterException` when `!Array.isArray(filters)`, invalid class scopes with `InvalidClassScopeException` when `wrapperRef.scope === Scope.REQUEST || wrapperRef.scope === Scope.TRANSIENT || !wrapperRef…`, and absent instances with `UnknownElementException` when `!instance`.

### What it needs, and who needs it

Core has no dependencies in this repository. [Integration](subsystem-integration), `integration/inspector/src/common`, `sample/01-cats-app/src/common`, `sample/10-fastify/src/common`, [Auth](subsystem-sample-19-auth-jwt-src-auth), and `sample/36-hmr-esm/src/common` depend on it. Without Core, those named dependents lack the subsystem they declare as a dependency. The recorded work entry names are `moduleKey`, `moduleName`, `handler`, and `metatype`; `handler` appears three times in that record. The available evidence identifies no further repository need.

### Notable members

`RouterExplorer` is a routing member named with `PathsExplorer` and `RouterModule`; it marks route exploration. `RouterExecutionContext` is named with `RouterProxy` and `RouterProxyCallback`; it marks execution context, proxies, and callbacks. `RouterExceptionFilters` and `ExceptionsFilter` mark exception filter handling; `RouteParamsFactory` and `RoutePathFactory` mark parameter and path factory roles.

285 entities in `packages/core`. **6 other subsystems depend on it**, which makes it the most depended-upon part of this codebase.

## What it is made of

Its 285 entities sit in 158 files under `packages/core`: 106 classes, 45 functions, 41 interfaces, 29 doc comments and 64 more.
`messages.ts` holds 14 of them — more than any other file here.
`AbstractHttpAdapter` declares 50 methods, the widest surface here.

## Where work enters

It publishes 7 HTTP endpoints — 5 `GET` and 2 `ALL`. None of them declares a guard.

- `moduleKey` — `packages/core/middleware/container.ts`:27
- `moduleName` — `packages/core/middleware/container.ts`:68
- `handler` — `packages/core/middleware/middleware-module.ts`:94
- `metatype` — `packages/core/middleware/middleware-module.ts`:202
- `handler` — `packages/core/middleware/middleware-module.ts`:287
- `handler` — `packages/core/middleware/resolver.ts`:18

## How it refuses and fails

56 of its components record a refusal or a failure handler.
51 of them refuse work outright, under a condition written into the component itself.
Their `catch` blocks handle a failure that already happened in 17 places.
Of those 17, 8 log it and continue, 6 let it reach the caller and 3 turn it into a return value.

## Boundaries

**6 other subsystems depend on this one** — `Integration`, `Inspector`, `01 Cats App`, `10 Fastify`, `Auth`, `36 Hmr Esm`. Changing what it exposes changes them.

Those 6 hold 7 edges between them, unevenly: `Integration` reaches in across 2 edges, while 5 of them hold one each. What they reach is narrower than the folder: 3 of its 285 members carry every inbound edge — `Reflector` (5), `DiscoveryModule` (1) and `LazyModuleLoader` (1).

**It depends on no other subsystem in this repository** — it is a leaf.

## How this code is named

These conventions cover most of the codebase. Learning them is faster than reading an index —
each one lets you find any member of its family without looking it up.

| Pattern | Where | Count | Examples |
|---|---|---|---|
| `*.interface.ts` | across the repository | 19 | `edge.interface.ts`, `node.interface.ts`, `routes.interface.ts`, `extras.interface.ts` |
| `*.exception.ts` | `core/errors/exceptions/` | 17 | `runtime.exception.ts`, `invalid-class.exception.ts`, `invalid-module.exception.ts`, `unknown-export.exception.ts` |
| `*.hook.ts` | `packages/core/hooks/` | 5 | `on-module-init.hook.ts`, `on-app-shutdown.hook.ts`, `on-app-bootstrap.hook.ts`, `on-module-destroy.hook.ts` |
| `call*` | exported symbols | 5 | `callModuleInitHook`, `callAppShutdownHook`, `callModuleDestroyHook`, `callModuleBootstrapHook` |
