Microservices system with the aim of practicing and exploring technologies and architectures such as React, Typescript, Nodejs, Nestjs, Docker, Kubernetes, Apache Kafka, Github actions etc.
This microservice system allows multiple users to trade monsters. It has the following functionalities:
- User creation
- User authentication via JWT
- Users can buy monster eggs of different levels which correspond to various ranks of monsters
- Eggs hatch approximately one minute after they are purchased
- Users have 200 credits initially and every hour they receive 10 credits
- Users can view their hatched monsters and their transactions
- Written in nodejs using the Nestjs framework
- Service in charge of managing monsters and eggs
- Fill the database with monsters with available images obtained through the API http://www.dnd5eapi.co/
- Create a catalog of eggs based on the available levels of monsters
- Due to the fact that most of the fields only want to be saved without any specific structure, MongoDB was chosen as the database since it is of the document type
- It has a cache layer (Redis) for reading endpoints (monster queries, egg catalog)
- Written in nodejs using the Nestjs framework
- Service in charge of managing users and transactions
- Creation and authentication of users via JWT
- Create and complete transactions asynchronously
- Listen for Kafka's topics:
- finalize-transaction: complete a pending transaction
- inject-credits: Inject credits defined in the kafka message to all users
- Because in this service it is desired to handle ACID transactions by the algorithm of completing a credit transaction, PostgresDB was chosen as the database
- Cron job written in nodejs
- It has two main processes
- Process pending transactions: requests the Users Service for pending transactions with more than 1 minute of creation and publishes messages to the finalize-transaction topic. This process runs every 30 seconds
- Inject credits: Publish the amount of 10 credits to the kafka topic inject-credits. This process runs every hour
- User interface written in React with typescript'
- Signup / Signin
- Authentication handling with JWT
- Dashboard to navigate between the different sections
- Monsters: See the monsters hatched
- Eggs: See the catalog of eggs and buy them
- Transactions: View transaction history
Clone the repo:
git clone https://github.com/davidcdorbecker/dnd-monsters.git
Use Docker Compose to start the microservies application:
docker compose up --build
Fill the monsters db (one-time operation):
curl --location --request POST 'localhost:8001/monsters/refresh'
A web page is now available:
http://localhost:3000
User sing up
The user starts with 200 credits and no monsters
The user can consult the egg catalog in the eggs section and buy some
For example, when trying to buy a level 2 egg that corresponds to a monster in the range of levels 8 to 12, a confirmation dialog appears.
By accepting the dialogue the credits decrease to 168 since the level 2 egg cost 32
In the transactions section the user can see the pending transaction
In the container logs we can see the asynchronous communication of cron with kafka and kafka with the user microservice
After a minute the user can see the transaction finished
and the monster born
- Mount the application on Kubernetes
- Write more unit tests
- Improve CI / CD
- Write the documentation of the APIs with swagger