This project consists of three microservices that interact with each other to handle an OTP (One Time Password) generation and notification system. The three services are:
- OTP Service (
otp-svc
) - User Service (
user-svc
) - Notification Service (
notify-svc
)
This service is responsible for generating and serving OTPs, as well as providing the status of the OTP process.
POST /otp
:- Purpose: Generates an OTP and logs the request body received.
- Response: Returns a JSON object containing the message "OTP generated" and the request body.
{ "message": "OTP generated", "explanation": "OTP is generated and sent to user", "requestBody": { ... } }
GET /otp
:- Purpose: Retrieves a hardcoded OTP for simplicity.
- Response: Returns a JSON object with the OTP and its validity status.
{ "otp": "123456", "valid": true }
GET /otp-status
:- Purpose: Provides the status of the OTP process.
- Response: Returns the status of OTP delivery.
{ "status": "OTP sent" }
This service acts as the OTP provider. Other services request an OTP from here or check the OTP status.
This service interacts with the OTP service to request and retrieve OTPs, as well as with the Notification service to check the notification status.
POST /request-otp
:- Purpose: Sends a request to the OTP service to generate an OTP.
- Interaction: Makes a
POST
request tootp-svc
's/otp
endpoint with the body received from the client. - Response: Returns a confirmation that the OTP request was sent, along with the response from
otp-svc
.
{ "message": "OTP requested", "otpResponse": { ... } }
GET /get-otp
:- Purpose: Retrieves the generated OTP from
otp-svc
. - Interaction: Makes a
GET
request tootp-svc
's/otp
endpoint. - Response: Returns the retrieved OTP and its status.
{ "message": "OTP retrieved", "otp": { "otp": "123456", "valid": true } }
- Purpose: Retrieves the generated OTP from
GET /notification-status
:- Purpose: Checks the status of the notification from the
notify-svc
. - Interaction: Makes a
GET
request tonotify-svc
's/notification-status
endpoint. - Response: Returns the notification status from
notify-svc
.
{ "message": "Notification status retrieved", "notifyStatus": { "status": "Notification service is running" } }
- Purpose: Checks the status of the notification from the
This service communicates with the OTP service to request and retrieve OTPs, and with the Notification service to check the status of notifications.
This service is responsible for sending notifications about the OTP status.
GET /notify
:- Purpose: Requests the OTP status from the
otp-svc
and sends a notification. - Interaction: Makes a
GET
request tootp-svc
's/otp-status
endpoint to retrieve the OTP status. - Response: Returns the OTP status received from
otp-svc
.
{ "message": "Notification sent", "otpStatus": { "status": "OTP sent" } }
- Purpose: Requests the OTP status from the
GET /notification-status
:- Purpose: Provides the status of the Notification service.
- Response: Returns a message indicating that the Notification service is running.
{ "status": "Notification service is running" }
This service requests OTP status from the otp-svc
and notifies the user about the OTP status. It also provides a status check for the notification system.
- The User Service (
user-svc
) receives a request to generate an OTP via/request-otp
and forwards this request to the OTP Service (otp-svc
). - The OTP Service (
otp-svc
) processes the request, generates an OTP, and returns a response. - The User Service (
user-svc
) can retrieve the OTP from the OTP Service (otp-svc
) via the/get-otp
endpoint. - The User Service can also check the status of the Notification Service by calling
/notification-status
on the Notification Service (notify-svc
). - The Notification Service (
notify-svc
) interacts with the OTP Service (otp-svc
) to retrieve the OTP status via/notify
and sends a notification.
- Start the OTP Service on port
3001
. - Start the Notification Service on port
3002
. - Start the User Service on port
3000
.
Each service runs independently but interacts with each other to complete the OTP and notification workflow.
You can record test cases and mocks for these services using the keploy
command. To record test cases and mocks, follow these steps:
- Install Keploy on your machine if you haven't already.
- Run the
keploy record
command to record interactions of the otp service go to otp-svc and write:keploy record -c "node index.js"
- Send the requests of it from the curls file in VirtualCPR folder
- Test cases will be recorded and be put inside otp-svc
- Do the same for notify-svc and user-svc
If you don't want to record new test cases and mocks, there are already existing recorded test cases and mocks available in the repository, which can be used directly without re-recording.
- Run the
keploy contract
command to generate OpenAPI Schemas for each service of the three:keploy contract generate
- Run the
keploy contract test
command to run consumer driven contract testing:keploy contract test --driven "consumer"