home / skills / hoangnguyen0403 / agent-skills-standard / transport
This skill helps you design and enforce NestJS microservices patterns with gRPC, RabbitMQ, and mono-repo contracts for scalable, contract-first architectures.
npx playbooks add skill hoangnguyen0403/agent-skills-standard --skill transportReview the files below or copy the command above to add this skill to your agents.
---
name: NestJS Microservices
description: gRPC, RabbitMQ standards and Monorepo contracts.
metadata:
labels: [nestjs, microservices, grpc, rabbitmq]
triggers:
files: ['main.ts', '**/*.controller.ts']
keywords: [Transport.GRPC, Transport.RMQ, MicroserviceOptions]
---
# Microservices & Transport Standards
## **Priority: P0 (FOUNDATIONAL)**
Microservices communication patterns and transport layer standards.
- **Synchronous (RPC)**: Use **gRPC** for low-latency, internal service-to-service calls.
- **Why**: 10x faster than REST/JSON, centralized `.proto` contracts.
- **Asynchronous (Events)**: Use **RabbitMQ** or **Kafka** for decoupling domains.
- **Pattern**: Fire-and-forget (`emit()`) for side effects (e.g., "UserCreated" -> "SendEmail").
## Monorepo Architecture
- **Contracts**:
- **Pattern**: Store all DTOs, `.proto` files, and Interfaces in a **Shared Library** (`libs/contracts`).
- **Rule**: Services never import code from other services. They only import from `contracts`.
- **Versioning**: Semantic versioning of messages is mandatory. Never change a field type; add a new field.
## Exception Handling
- **Propagation**: Standard `HttpException` is lost over Rpc/Tcp.
- **Standard**: Use `RpcException` and generic Filters.
```typescript
// Global RPC Filter
@Catch()
export class RpcExceptionFilter implements RpcExceptionFilter<RpcException> {
catch(exception: RpcException, host: ArgumentsHost): Observable<any> {
return throwError(() => exception.getError());
}
}
```
## Serialization
- **Message DTOs**: Use `class-validator` just like HTTP.
- **Config**: Apply `useGlobalPipes(new ValidationPipe({ transform: true }))` in the `MicroserviceOptions` setup, not just HTTP app setup.
This skill codifies NestJS microservice standards for gRPC, RabbitMQ, and monorepo contracts. It focuses on reliable transport choices, shared contract management, validation, and error propagation across RPC boundaries. Use it to align teams on fast internal RPC, event-driven decoupling, and safe schema evolution.
The skill prescribes gRPC for synchronous, low-latency service-to-service RPC and RabbitMQ/Kafka for asynchronous event flows. It enforces a shared contracts library for DTOs, .proto files, and interfaces so services never import each other directly. It also defines global RPC exception filters and validation plumbing to preserve errors and payload integrity across transports.
Why use gRPC instead of REST/JSON internally?
gRPC offers much lower latency and stronger typing via .proto contracts, improving performance and interoperability for internal calls.
How should I evolve message schemas?
Follow semantic versioning: never change field types in-place. Add new fields with default behavior and increment contract versions so consumers can remain compatible.