Code Monkey home page Code Monkey logo

viaplay's Introduction

Viaplay Backend Documentation

The building blocks and folder structure

The main entry point is server.js and this file handles our server and also using any routes or adapters. Then we have docker-compose.yml and Dockerfile to run our servers in a containerized environment in order to be easily managable, maintainable, ready to integrate with already existing microservice architecture, and easily deploayble. Last but not least we run the app in a container to prevent "it's working on my machine!" ๐Ÿคทโ€โ™‚๏ธ.

  • Domain Logic: This folder contains our logic, be it anything. It only calls our ports to intract with outside world like 3rd party APIs, other services, databases and anything that is external.
  • Ports: This is an anti-corruption layer (ACL), a pattern between domain logic (model) and any other bounded context (code) that wants to intract with our domain model (logic). This pattern prevents any intrusion twards the domain model (logic).
  • Adapters: This is a pattern for intracting from other services, repository layers, or anything external with the domain model (logic) and from the domain model (logic) with other services and in general outside world.

Root file consists of the test file, server file, dockerfile and docker compose yml file.

  • Adapters
    • handleViaplayRequstAdapter.js : this file will be called inside our API function and will receive a link and will have an axios call in then pass the axios data to the Port to be passed to the DomainLogic.
    • tmdbAxiosAdapter.js : as the name shows this will handle the ouside call to the third party API which is from TMDb to retrive the trailers youtube vide results with other assiciated data.
  • Ports
    • handleViaplayRequstPort.js : this is the port that will call the domain logic in order to invoke it and retrive the data that it send back.
    • tmdbAxiosPort.js : this will invoke the tmdbAxiosAdapter.js module to send the axios API call.
  • DomainLogic: in this test there's only one file included and it will be invoked via our endpoint and invoke the axios call to the TMDb API to retrive the youtube related information, clean the received data from the module and create an array of youtube links. Then it'll send it back to the handleViaplayRequstPort.js and then to handleViaplayRequstAdapter.js in order to send back the response to the router function.
  • Route: in this test we only have one router, and it'll call the handleViaplayRequstAdapter.js to send the link and also recieve the response back.

Run the application

Since the application is dockerized you can use docker-compose up -d --build for the first time to build it and then run it and after that you can only use docker-compose up -d to run it again (incase you've stoped it!). You need to hava a .env file to provide your TMDB_API_KEY.

Architectrual Design

The Architectural design of the test is visualized and you can find them in pdf and image file type in root of the application! The backend architecture is based on Hexagonal Architecture, a microservice and DDD based architecture.

This archtectural style allows us to break down the code to three parts:

  • Adapters: in order to communicate with and from outside the world from the domain logic
  • Ports: an anti-corruption layer that allows the adapters to talk to the domain logic or vice versa.
  • Domain logic: which is the main logic and the business capability that we have to provide as a service.

This architecture allows us to change code so rapidly and refactor or even remove/add code so rapidly. Also provides a better testing experience and more organized and modular code, hence we will have a better maintainability.

This architecture style will cover the business logic from being directly changed or invoked and create interface layers (function layer in this particular example since we don't have typed language) and create boundries.

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.