A progressive Node.js framework for building efficient and scalable server-side applications.
$ git clone https://github.com/gitmariosalazar/microservices.git
$ cd microservices/backend/gateway
$ npm install
$ cd microservices/backend/products-ms
$ npm install
$ cd microservices/backend/authentication-ms
$ npm install
$ cd microservices/backend/sales-ms
$ npm install
$ cd microservices/backend/returns-ms
$ npm install
- Run the following command:
$ cd microservices/backend/authentication-ms # Change the folder name for others microservices
$ npm run prisma:generate
$ cd microservices/backend/gateway # Change the folder name for others
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run build
$ npm run start:prod
- View Endpoints: http://localhost:5000/api
- Create database
mysql -u root -p
create database microservices
- Restore database
$ mysql -u root -p <database name> < "<Path>\microservices\backup\microservices.sql"
๐products-ms/
โโโ๐src/
โ โโโ๐errors/ # Configuraciones para manejar errores
โ โโโ๐modules/
โ โ โโโ๐products/ # Mรณdulo de productos
โ โ โ โโโ๐application/
โ โ โ โโโ๐domain/
โ โ โ โโโ๐infrastructure/
โ โ โโโ๐users/ # Agregar estructura similar al mรณdulo de productos
โ โ โโโ๐application/...
โ โ โโโ๐domain/...
โ โ โโโ๐infrastructure/..
โ โโโ๐settings/
โ โ โโโ๐envs.ts
โ โ โโโ๐index.ts
โ โโโ๐shared/
โ โ โโโ๐database/
โ โ โ โโโ๐mysql.service.ts
โ โ โ โโโ๐postgres.service.ts
โ โ โ โโโ๐add-others.ts
โ โ โโโ๐prisma/
โ โ โ โโโ๐migrations/
โ โ โ โโโ๐prisma.service.ts
โ โ โ โโโ โฒ schema.prisma
โ โ โโโ๐typeorm/
โ โ โโโ๐typeorm.database.ts
โ โโโโ๐app.module.ts
โ โโโโ๐main.ts
โ โโโโ๐test/
โโโโ.env
This folder contains global error-handling utilities to manage application errors effectively.
Modules represent the core business domains (e.g., products
, users
) and are structured into three layers:
Handles business logic, use cases, and mappers. It interacts with the domain layer and infrastructure.
- Mappers: Converts entities and models between layers (e.g.,
product.mapper.ts
). - Service: Implements use cases (
product-use-case.service.ts
). - Use Case: Defines interfaces for services.
Defines business rules and core concepts:
- Contracts: Interfaces to define repository behaviors.
- DTOs: Data Transfer Objects for request/response handling.
- Models: Business models encapsulating core logic.
Handles database operations, external services, and frameworks:
- Adapters: Bridges domain and infrastructure.
- Controller: Exposes endpoints to interact with application logic.
- Entities: Defines database schemas.
- Repositories: Implements persistence logic for databases (e.g., MySQL, PostgreSQL, Prisma).
Contains environment configuration files and settings for different environments (envs.ts
).
Reusable utilities and services:
- Database: Provides database connection services (e.g.,
mysql.service.ts
,prisma.service.ts
). - Prisma/TypeORM: Configurations for ORM tools.
app.module.ts
: Entry point for module registration.main.ts
: Bootstrap file for application initialization.
This document explains the purpose of each environment variable used in the application. These variables ensure proper configuration and connection to external services and databases.
-
PORT
: Specifies the port each microservice on which the application will run. -
SECRET_KEY
: A secret key used for token generation and application security. (authentication microservice) -
PERCENTAGE_INCREMENT
: Represents a percentage value for specific application logic. (products microservice) -
PROVIDER_DATABASE
: Specifies the provider to prisma. -
DATABASE_URL
: Connection string for Prisma, supporting PostgreSQL, MySQL, SQLite, SQL Server, MongoDB, or CockroachDB. It is used by Prisma to interact with the database. Refer to the Prisma documentation for more details:
PORT=5000
AUTH_MICROSERVICE_HOST=localhost
AUTH_MICROSERVICE_PORT=3001
AUTH_SERVICE=AUTH_SERVICE
PRODUCTS_MICROSERVICE_HOST=localhost
PRODUCTS_MICROSERVICE_PORT=3002
PRODUCTS_SERVICE=PRODUCTS_SERVICE
SALES_MICROSERVICE_HOST=localhost
SALES_MICROSERVICE_PORT=3003
SALES_SERVICE=SALES_SERVICE
RETURNS_MICROSERVICE_HOST=localhost
RETURNS_MICROSERVICE_PORT=3004
RETURNS_SERVICE=RETURNS_SERVICE
Description of Variables
-
PORT
: Port on which the client gateway will run. -
MICROSERVICE_HOST
: Host (usually localhost during development) where each microservice is running. -
MICROSERVICE_PORT
: Port assigned to each corresponding microservice. -
SERVICE
: Identifier used by the gateway to route and communicate with each microservice.
These variables configure the client gateway to communicate with the Authentication, Products, Sales, and Returns microservices. Make sure the host and port match the actual running services.
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
When you're ready to deploy your NestJS application to production, there are some key steps you can take to ensure it runs as efficiently as possible. Check out the deployment documentation for more information.
If you are looking for a cloud-based platform to deploy your NestJS application, check out Mau, our official platform for deploying NestJS applications on AWS. Mau makes deployment straightforward and fast, requiring just a few simple steps:
$ npm install -g mau
$ mau deploy
With Mau, you can deploy your application in just a few clicks, allowing you to focus on building features rather than managing infrastructure.
- Author - Mario Salazar
- Website - https://mssalazar.com
- WhatsApp - Send message
Nest is MIT licensed.