Documentation Index
Fetch the complete documentation index at: https://mintlify.com/Distribuidos-Org/ms-alumnos/llms.txt
Use this file to discover all available pages before exploring further.
ms-alumnos is a NestJS microservice that manages university student records in a distributed system. It is bootstrapped with NestFactory.createMicroservice — meaning it exposes no HTTP server whatsoever. All communication is handled exclusively over NATS using the @nestjs/microservices package with Transport.NATS. Incoming messages are dispatched to handlers in AlumnosController, which delegates business logic to AlumnosService, which in turn persists data to a PostgreSQL database via TypeORM.
Modules
The application is composed of three NestJS modules, each with a distinct responsibility:| Module | Responsibility |
|---|---|
AppModule | Root module — bootstraps ConfigModule (global env validation) and TypeOrmModule (PostgreSQL connection), then imports feature modules. |
AlumnosModule | Feature module — wires together AlumnosController, AlumnosService, and the Alumno TypeORM entity repository. Handles all student CRUD operations. |
SeedModule | Utility module — provides a data-seeding mechanism for populating the database with initial or test records. |
Request flow
A complete round-trip from API gateway to database and back follows these steps:HTTP request arrives at the API gateway
An external client sends an HTTP request (e.g.
POST /alumnos) to the client-gateway service. The gateway validates and transforms the request into a NATS message payload.Gateway publishes a NATS request
The gateway calls
client.send({ cmd: 'create_alumno' }, payload) over NATS using request-reply semantics. The message is routed to any available ms-alumnos instance subscribed to that subject.AlumnosController receives the message
The
@MessagePattern({ cmd: 'create_alumno' }) handler in AlumnosController is invoked. NestJS deserialises the payload into a typed DTO and runs ValidationPipe to enforce constraints before the handler body executes.AlumnosService executes business logic
The controller delegates to
AlumnosService, which uses the injected TypeORM Repository<Alumno> to create, query, update, or delete records. Any domain error (e.g. record not found) is thrown as an RpcException.TypeORM persists to PostgreSQL
TypeORM translates the repository call into a SQL statement and executes it against the PostgreSQL database. The result (entity or error) is returned to the service.
Response travels back over NATS
The return value from the controller handler is serialised and sent back to the gateway on the NATS reply subject. If an
RpcException was thrown, MicroserviceExceptionFilter catches it and sends a structured error response instead.Integration with client-gateway
ms-alumnos is designed to be consumed by the client-gateway service. The gateway is the only entry point for external clients — it translates inbound HTTP requests into NATS send() calls and maps NATS responses (or errors) back into HTTP responses. ms-alumnos itself never listens on a TCP port and is not directly reachable from outside the NATS cluster.- ms-alumnos owns data validation (DTOs +
ValidationPipe), persistence, and business rules. - client-gateway owns HTTP routing, authentication middleware, and HTTP-level error formatting.
Startup
The application entry point atsrc/main.ts bootstraps the microservice, registers global middleware, and starts listening on NATS:
ValidationPipe — Applied to every incoming message payload before the handler is called. The options whitelist: true strips any properties not declared in the DTO, and forbidNonWhitelisted: true causes the pipe to throw a BadRequestException if any unknown property is present. This keeps message payloads strictly typed end-to-end.
MicroserviceExceptionFilter — A catch-all exception filter that intercepts all unhandled exceptions, normalises them into RpcException objects (preserving HTTP status codes where applicable), and returns them as structured error payloads over NATS. See Error Handling for details.
Explore further
NATS Messaging
Message patterns, request-reply semantics, multi-server configuration, and how to connect from another service.
Database
PostgreSQL schema, TypeORM entity definition, password hashing, and Docker Compose setup.