We want to offer a new feature to our customers showing similar products to the one they are currently seeing. To do this we agreed with our front-end applications to create a new REST API operation that will provide them the product detail of the similar products for a given one. Here is the contract we agreed.
We already have an endpoint that provides the product Ids similar for a given one. We also have another endpoint that returns the product detail by product Id. Here is the documentation of the existing APIs.
Create a Spring boot application that exposes the agreed REST API on port 5000.
Note that Test and Mocks components are given, you must only implement yourApp.
You can run the same test we will put through your application. You just need to have docker installed.
First of all, you may need to enable file sharing for the shared
folder on your docker dashboard -> settings -> resources -> file sharing.
Then you can start the mocks and other needed infrastructure with the following command.
docker-compose up -d simulado influxdb grafana
Check that mocks are working with a sample request to https://localhost:3001/product/1/similarids.
To execute the test run:
docker-compose run --rm k6 run scripts/test.js
Browse https://localhost:3000/d/Le2Ku9NMk/k6-performance-test to view the results.
The following topics will be considered:
- Code clarity and maintainability
- Performance
- Resilience
For the implementation of this feature, considerating that the real application would be complex, I select a Hexagonal architecture, using an approach Outside-in, starting to build the application for the controllers.
The folder structure is divided in features:
- products -> where I put the infrastructure, use cases and models.
- Infrastructure -> all logic that work with the external world.
- domain -> the core of feature, following the approach "doesn't ask, tell me".
- applicattion -> I have put in this folder the business logic.
- shared -> in this folder I put classes that are used in the three layers.
- shared -> I have created this folder with the idea that the real application would be complex, so in this folder I have put the classes that can be used by others modules.
- Execute the script in bash
sh init.sh
- It deletes target folder if it's exist, then run ./mvnw install and build, after this, it runs Docker image with docker-compose.
- Execute maven install, run and build Docker image
./mvnw install -Ppro
docker build -t "app-products" .
docker-compose up -d appproducts
- Execute maven install and spring-boot maven plugin:
sh init_pre.sh
or
./mvnw install -Ppre
./mvnw -pl org.backendDevTest:app-products spring-boot:run