This project is a microservices-based application built using NestJS, designed to handle various functionalities such as authentication, reservations, payments, and notifications. The services communicate with each other asynchronously using RabbitMQ, and the data is stored in an SQL database. Each microservice is containerized using Docker, and Docker Compose is used to manage and run the entire application. Additionally, there is a common library used across the services for shared models and authentication logic, including JWT-based authentication with Passport.
- Architecture
- Microservices
- Common Library
- Technologies Used
- Getting Started
- Environment Variables
- Database
- Communication
- Authentication
- Contributing
- License
The application follows a microservices architecture, where each service is responsible for a specific domain or functionality. The microservices communicate with each other via RabbitMQ, enabling loose coupling and scalability. The following diagram illustrates the architecture:
+------------------+ +-------------------+ +-------------------+
| | | | | |
| Auth Service |<------>| Reservations |<------>| Payments Service |
| | | Service | | |
+------------------+ +-------------------+ +-------------------+
^ ^ ^
| | |
v v v
+------------------+ +-------------------+ +-------------------+
| | | | | |
| Notifications |<------>| RabbitMQ Broker |<------>| Common Library |
| Service | | | | |
+------------------+ +-------------------+ +-------------------+
- Purpose: Manages user authentication and authorization.
- Features:
- User registration and login
- JWT-based authentication
- Token validation and user session management
- Technologies: NestJS, Passport, JWT, SQL
- Purpose: Handles reservation-related functionalities.
- Features:
- Create, update, and delete reservations
- Fetch reservation details
- Integration with Auth Service for user authorization
- Technologies: NestJS, SQL
- Purpose: Manages payment processing and related transactions.
- Features:
- Process payments
- Transaction management
- Integration with Reservations and Notifications Services
- Technologies: NestJS, SQL
- Purpose: Sends notifications to users based on various events.
- Features:
- Email and SMS notifications
- Event-driven notifications based on RabbitMQ messages
- Technologies: NestJS, RabbitMQ
- Purpose: Provides shared functionalities across the microservices.
- Features:
- Common models and DTOs
- Authentication logic (JWT-based with Passport)
- Utility functions and constants
- Technologies: TypeScript, NestJS
- Backend: NestJS
- Message Broker: RabbitMQ
- Database: SQL (e.g., PostgreSQL, MySQL)
- Authentication: Passport, JWT
- Containerization: Docker, Docker Compose
- Language: TypeScript
- Node.js (v14 or later)
- Docker
- Docker Compose
- RabbitMQ (or installed as a Docker container)
-
Clone the repository:
git clone https://github.com/your-username/your-repo.git cd your-repo
-
Install dependencies for each microservice:
cd auth-service npm install cd ../reservations-service npm install cd ../payments-service npm install cd ../notifications-service npm install
grpc
master
rabiqmq
typeorm
-
Build and run the application using Docker Compose:
docker-compose up --build
-
The services should be up and running. You can verify by accessing the respective service endpoints (e.g.,
http://localhost:3000
for Auth Service).
Each microservice requires specific environment variables to be set. Refer to the .env.example
file in each service directory for the required variables. These typically include:
DATABASE_URL
RABBITMQ_URL
JWT_SECRET
PORT
The application uses an SQL database to store data. Each microservice has its own database schema. Migrations and seed scripts can be used to manage database changes.
To run database migrations, use the following command inside each microservice directory:
npm run migration:run
The microservices communicate with each other using RabbitMQ as a message broker. Each service publishes and subscribes to specific queues/topics based on the event-driven architecture.
Authentication is handled by the Auth Service using JWT tokens. The tokens are validated by the other services to ensure that only authenticated users can access the endpoints.
- Generate Token: The Auth Service generates a JWT upon successful login.
- Validate Token: Other services use the common library to validate the token and extract user information.
Contributions are welcome! Please follow the contributing guidelines to submit your changes.
This project is licensed under the MIT License - see the LICENSE file for details.