Skip to Content
Engineering11 Documentation 🔥
BackendServer API PackagesMicroservices Controller

Microservices Controller API

NestJS base controller factory for implementing CRUD microservices with message-based patterns.

What It Does

The Microservices Controller API provides a factory function that generates fully-functional CRUD controllers for NestJS microservices. It serves as the counterpart to the MicroserviceClient, abstracting away boilerplate code for exposing business logic through message-based communication with built-in validation, error handling, and distributed coordination.

Key Capabilities

CapabilityDescription
Factory-Generated ControllersCreate complete CRUD controllers with one function call
Message Pattern RoutingAutomatic routing for 7 CRUD operations
Input ValidationBuilt-in class-validator integration with custom error formatting
Distributed Task ClaimingRedis-based locking prevents duplicate processing
Error HandlingStandardized RPC exception filtering and logging
Repository IntegrationWorks with Firestore collections and subcollections
Type SafetyFull TypeScript support with generic types
Automatic TimestampsResponse timestamps for created/modified fields

Configuration

Message Patterns

  • Follows MicroservicePaths convention
  • Collection-scoped routing
  • CRUD operation mapping

Validation

  • Enabled by default
  • class-validator integration
  • Custom error formatting

Task Claiming

  • Redis-based locking
  • 30-second timeout
  • Automatic coordination

Exports

Factory Functions

  • MicroserviceController() - Controller factory

Models

  • Request classes (GetRequest, CreateRequest, etc.)
  • Response interfaces (from microservices-client)

Interceptors

  • ClaimTaskInterceptor - Task claiming

Pipes

  • MicroserviceValidationPipe - Validation pipe

Filters

  • E11RpcExceptionFilter - Error handling

Constants

  • API_NAME - ‘microservices’
  • MICROSERVICE_ERRORS - Error types

Common Use Cases

  • CRUD microservices: Implement full CRUD with one line of code
  • Multi-instance deployments: Safe distributed processing with task claiming
  • Message-based architecture: Expose business logic via message patterns
  • Type-safe services: Compile-time validation across service boundaries
  • Validated operations: Automatic request validation with clear errors
  • Hierarchical resources: Parent-child resource relationships

What Customers Don’t Have to Build

  • CRUD controller boilerplate
  • Message pattern decorators
  • Input validation pipes
  • Error handling filters
  • Distributed task claiming with Redis
  • Repository integration logic
  • Request/response type definitions
  • Timestamp metadata handling
  • RPC exception conversion
  • Validation error formatting
  • Observable response wrapping
  • Collection and subcollection support
Last updated on