README
NestJS Multitenant Microservice Project Tutorial
DARMIST Lab
Description
This project is a comprehensive tutorial on building a scalable and efficient backend application using NestJS. It demonstrates the implementation of a microservice architecture with multi-tenancy, leveraging Redis for caching, Mongoose for database interactions, and a custom logger. The application features robust security with JWT Authentication and Role-Based Access Control (RBAC). It includes full CRUD operations for products, with detailed fields such as productID, title, description, images, price, category, status, createdBy, and createdAt. The API is fully documented using Swagger/OpenAPI. This tutorial is designed to be easy to follow, even for beginners, with step-by-step instructions and output verification at each stage.
Example Project Steps:
- Setting Up the Project
- Set up microservices (api-gateway, auth-service, user-service, tenant-service, product-service).
- Implement Multi-Tenancy
- Implement JWT Authentication
- Implement Role-Based Access Control (RBAC)
- Implement CRUD for Products
- Integrate Redis for Caching This is prepared in very easy way, even for who have no experience with NodeJS. So, it fully guide you in developing the application without skipping any part. Also, at each step, we have shown the output so that you can understand that you are on the right track and everything is working correctly.
Git Instructions
User can pull project from git clone git @bitbucket.org:darmist/nestjs-tutorial.git
Fetch everything git fetch --all
Load all the branches git branch -a
Load each step code from each branch by switching git checkout step1-setup-and-run
Available branches are:
step1-setup-and-runstep2-environmentstep3-microservicestep4-tenant-crudstep5-redis-cachingstep6-multi-tenancystep7-signup-and-emailstep8.1-login-with-otpstep-8.2-account-lock-unlockstep8.3-login-devices-logout-refresh-tokenstep8.4-rbac-and-session-controlstep9-product-crudstep10-swaggermaster[Full and Final Version]
Project setup
$ npm install
Run all microservices with the script
Make it executable:
$ chmod +x tools/run-all.sh
Run the script:
$ ./tools/run-all.sh
Compile and run the project
# development
$ npm run start
# watch mode
$ npm run start:dev
# production mode
$ npm run start:prod
Run tests
# unit tests
$ npm run test
# e2e tests
$ npm run test:e2e
# test coverage
$ npm run test:cov
Deployment
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 @nestjs/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.
Stay in touch
- Author - Rana Depto
- Email - mail@ranadepto.com
License
Nest is MIT licensed.