This project is a monorepo containing a REST API gateway with RPC back-end microservices, all written using the NestJS Framework and TypeScript. It is designed to demonstrate a microservices architecture using RabbitMQ for inter-service communication and PostgreSQL for data persistence.
The REST API acts as a gateway/proxy for the different microservices it exposes. The controllers of the REST API make calls to the RPC servers/microservices in the back-end. The RPC microservices handle the requests to connect to databases or any other service needed to serve the requests.
- Microservice Architecture: Each service is independently deployable and scalable.
- Subdomain Decomposition: Services are decomposed based on business subdomains.
- Externalized Configuration: Configuration is externalized to support different environments.
- Remote Procedure Invocation (RPI): Services communicate via RPC using RabbitMQ.
- API Gateway: A single entry point for all client requests, routing them to the appropriate microservice.
- Database per Service: Each microservice has its own database to ensure loose coupling.
NestJS + Express acts as the API Layer for the architecture. It listens for client requests and calls the appropriate back-end microservice to fulfill them.
RabbitMQ is the message broker chosen for the microservices communication. Remote Procedure Calls (RPC) are used as the communication style between the client (REST API) and the server (RPC microservices). Services communicate between themselves too.
PostgreSQL is used as the database, and TypeORM is used as the Object-Relational Mapper (ORM).
Deployment is containerized using Docker. A Docker Compose file, along with Dockerfiles for each project, are provided to run the entire setup on any machine. For production, it's recommended to use Kubernetes for deploying such a microservices architecture. Istio is used for service discovery, distributed tracing, and other observability requirements.
- Docker - latest
- Docker Compose - latest
-
Clone the repository:
git clone git@github.com:sappChak/nest-auth-rpc.git cd nest-auth-rpc
-
Build and start the services using Docker Compose:
docker compose up --build
-
Once the services are up, the API Gateway will be listening on http://localhost:8080.
-
To test the API, head to the Swagger UI running at http://localhost:8080/api/docs.
/nest-auth-rpc
├── docker-entrypoint-initdb.d
│ ├── token
│ └── user
├── apps
│ ├── gateway
│ │ ├── src
│ │ │ ├── controllers
│ │ │ ├── modules
│ │ │ └── main.ts
│ │ ├── test
│ │ ├── Dockerfile
│ │ └── README.md
│ ├── user
│ │ ├── src
│ │ │ ├── controllers
│ │ │ ├── services
│ │ │ ├── modules
│ │ │ └── main.ts
│ │ ├── test
│ │ ├── Dockerfile
│ │ └── README.md
│ ├── token
│ │ ├── src
│ │ │ ├── controllers
│ │ │ ├── services
│ │ │ ├── modules
│ │ │ └── main.ts
│ │ ├── test
│ │ ├── Dockerfile
│ │ └── README.md
├── libs
│ ├── shared
│ │ ├── src
│ │ │ ├── config
│ │ │ ├── constants
│ │ │ ├── guards
│ │ │ ├── interceptors
│ │ │ ├── rmq
│ │ │ └── types
│ │ └── README.md
├── docker-compose.yml
└── README.md