This repository contains a simple implementation of microservices using gRPC with Nest.js, structured as a monorepo and orchestrated with Docker Compose.
This project follows the monorepo structure provided by Nest.js, for more information, refer to the official documentation.
The project consists of two services:
ms-payments
andms-products
located in theapps
directory.
- Type: REST API and gRPC Client
- Functionality: The
ms-products
service provides a/products/buy/:id
route that interacts with thems-payments
service and returns the response.
- Type: gRPC Server
- Functionality: This service exposes a
payOrder
method that handles basic validations and returns a success response.
sequenceDiagram
autonumber
actor Client
participant ms-products
participant ms-payments
Client->>+ms-products: POST /products/buy/:id
ms-products->>+ms-payments: gRPC payOrder(order)
ms-payments-->>-ms-products: gRPC success response
ms-products-->>-Client: success response
The
api
directory contains a.rest
file with sample requests that can be executed using the REST Client extension for Visual Studio Code.
Before running the project, ensure you have the following dependencies installed on your machine:
To start the project, execute the following commands:
$ npm install && docker compose up -d
To generate TypeScript types from the .proto
file proto/payment.proto
, the nestjs-proto-gen-ts
package was utilized. To replicate this, run the following command from the project's root directory:
$ npx tsproto --path ./proto