# Microservices

### What it is responsible for

Microservices manages the package-level entry surface for microservice-related work: `normalizedPattern`, `route`, and `ClientsModule` are identified as paths through which work enters. Its documented project context calls Nest a framework for building Node.js server-side applications. The subsystem also draws boundaries around client, consumer, and producer initialization and around a topic check. With no repository-local dependencies listed, its documented responsibility is bounded by these entries and rejection paths.

### What it refuses

The subsystem rejects these conditions:

- `InvalidGrpcServiceException` when `!clientRef`.
- `No consumer initialized. Please, call the "connect" method first.` when `!this._consumer`.
- `No producer initialized. Please, call the "connect" method first.` when `!this._producer`.
- `Not initialized. Please call the "connect" method first.` when `!this.client`.
- `InvalidKafkaClientTopicException` when `isUndefined(minimumPartition)`.
- `Not initialized. Please call the "connect" method first.` when `!this.mqttClient`.

### What it needs, and who needs it

Microservices has no dependencies listed within this repository. It is depended on by `Integration`, `integration/microservices/src/tcp-tls`, `sample/03-microservices/src/math`, and `sample/04-grpc/src/hero`. Without this subsystem, those named dependents lose their stated dependency on `packages/microservices`; the evidence does not identify a more specific failure. That limitation matters: the dependency listing establishes direction from those consumers toward this package but it does not explicitly state which calls, initialization sequence, or runtime result each consumer requires.

### Notable members

`ClientsModule` is a named entry point for work and a listed member. `normalizedPattern` is also a named entry point, marking a boundary at which work arrives. `route` completes the listed entry trio; the evidence names it as an entry point but does not state its transformation or dispatch behavior. No further behavior for these symbols is stated in the supplied evidence for this subsystem.

435 entities in `packages/microservices`. **4 other subsystems depend on it**, which makes it the 3rd most depended-upon part of this codebase.

## What it is made of

Its 435 entities sit in 120 files under `packages/microservices`: 99 interfaces, 98 type aliases, 97 classes, 53 constants and 88 more.
`kafka.interface.ts` holds 156 of them — more than any other file here.
`Server` declares 24 methods, the widest surface here.

## Where work enters

It publishes 2 `GET` endpoints. None of them declares a guard.

- `normalizedPattern` — `packages/microservices/server/server.ts`:150
- `route` — `packages/microservices/server/server.ts`:168
- `ClientsModule` — `packages/microservices/module/clients.module.ts`:17

## How it refuses and fails

33 of its components record a refusal or a failure handler.
31 of them refuse work outright, under a condition written into the component itself.
Their `catch` blocks handle a failure that already happened in 30 places.
Of those 30, 13 turn it into a return value, 11 log it and continue, 5 let it reach the caller and 1 discards it without recording anything.

## Boundaries

**4 other subsystems depend on this one** — `Integration`, `Tcp Tls`, `Math`, `Hero`. Changing what it exposes changes them.

Those 4 hold 8 edges between them, unevenly: `Integration` reaches in across 3 edges, while 2 of them hold one each. What they reach is narrower than the folder: 2 of its 435 members carry every inbound edge — `ClientProxy` (7) and `ClientGrpc` (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 | 20 | `kafka.interface.ts`, `redis.interface.ts`, `packet.interface.ts`, `rmq-url.interface.ts` |
| `*.exception.ts` | `packages/microservices/errors/` | 14 | `empty-response.exception.ts`, `invalid-message.exception.ts`, `net-socket-closed.exception.ts`, `invalid-json-format.exception.ts` |
| `*.context.ts` | `packages/microservices/ctx-host/` | 7 | `rmq.context.ts`, `tcp.context.ts`, `mqtt.context.ts`, `nats.context.ts` |
| `*.deserializer.ts` | `packages/microservices/deserializers/` | 7 | `identity.deserializer.ts`, `kafka-request.deserializer.ts`, `kafka-response.deserializer.ts`, `incoming-request.deserializer.ts` |
