2.8 KiB
CartChain
Proof of concept for an e-commerce API implementing blockchain technology by using a simple private chain.
How it works?
The aim of this API is to manage a shopping cart of an ecommerce website. So, through it, the client will be able to request and create, update or delete any item in the current cart.
Every action of the API will generate a new Block on the Blockchain in order to create a history and persist the information, so we can retrieve it later, but also keeps a history of which items have the user added to the cart.
Workflow
The workflow of this API is as follows:
- Create
- Create request is received
- Check if the
idfor a Cart is not already used- If it has been used we return error
- If it has not been used, we create the cart with the given item and generates a new Block to add to the Blockchain
- Add the new Block to the Blockchain with the current information of this Cart
- Update
- Update request is received
- Check if the
idfor a Cart exists- If not exists return error
- If exist retrieve it
- Update the items in the cart and generate a new Block with the information
- Add the new Block to the Blockchain
- Delete
- Delete request is received
- Check if the
idfor a Cart exists- If not exists return error
- If exist retrieve it
- Remove cart information and create a new Block
- Add the new Block to the Blockchain
Technical Considerations
Stack
Architecture
This app is implemented using hexagonal architecture (ports & adapters) and DDD approach.
The architecture helps to have a decoupled code and being easy to modify or extend it. Following diagram hints how this is achieved:
More info at Hexagonal Architecture
Getting Started
Within the Makefile you can handle the entire flow to get everything up & running:
- Install
makeon your computer, if you do not already have it. - Start the application:
make up - Run the application tests:
make test
Go to localhost:8080/swagger-ui/index.html to see the API description.
As you can see on the Makefile script and the docker-compose file, the whole API is containerized with docker and the API is using the internal DNS to connect with the PostgreSQL instance.
