This monorepo contains a simple example of a microservices architecture using NestJS.
The project consists of three main parts:
- Gateway: An API Gateway that acts as a single entry point for all client requests.
- Auth Service: A microservice responsible for user authentication and authorization.
- Product Service: A microservice responsible for managing products.
-
Install dependencies for each service:
cd gateway && npm install cd ../services/auth && npm install cd ../../services/product && npm install cd ../../
-
Run the
proto:allscript in thegatewayservice to generate the protobuf files:cd gateway && npm run proto:all && cd ..
-
Run the services using Docker Compose:
docker-compose up -d
The Gateway service is responsible for:
- Exposing a public API to the client.
- Forwarding requests to the appropriate microservice.
- Handling authentication and authorization.
The Auth service is responsible for:
- User registration.
- User login.
- Token validation.
The Product service is responsible for:
- Creating products.
- Retrieving products.
- Updating products.
- Deleting products.
gateway/src/auth/auth.controller.tsgateway/src/health-check/health-check.controller.tsgateway/src/product/product.controller.ts
services/auth/src/auth/auth.controller.ts
services/product/src/product/product.controller.ts
+-----------+ +----------------+ +----------------+
| | | | | |
| Client +----->+ Gateway +----->+ Auth Service |
| | | | | |
+-----------+ +-------+--------+ +-------+--------+
| |
| v
| +----------------+
| | |
| | Database |
| | |
| +-------+--------+
| ^
v |
+----------------+ |
| | |
| Product Service+---------------+
| |
+----------------+
We welcome contributions to this project! If you'd like to add your own service using a different library, framework, or language, please follow these steps:
- Fork the repository.
- Create a new directory for your service under the
servicesdirectory. - Add your service's configuration to the
docker-compose.ymlfile. - Develop your service.
- Submit a pull request.
This project is heavily reliant on Docker for service orchestration. It is not configured to be run altogether directly from multiple terminals or a tool like tmux. Please ensure you have Docker and Docker Compose installed and running before proceeding.