Giter VIP home page Giter VIP logo

dnd-monsters's Introduction

Monsters trading microservices system

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.

System Description

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

System architecture

Monster Service

  • 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)

User Service

  • 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 Service

  • 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

Monsters UI

  • 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

High level diagram

Instructions for running locally

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

Demo

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

Next steps

  • Mount the application on Kubernetes
  • Write more unit tests
  • Improve CI / CD
  • Write the documentation of the APIs with swagger

dnd-monsters's People

Contributors

davidcdorbecker avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.