Backend - MagistrMartin/Documentation GitHub Wiki

Architecture

The backend is based on microservices architecture. The API consists of several standalone programs (services) that serve a specific purpose. Every service is a standalone program with its database and can communicate with other services via REST requests. All the services register themselves to the discovery server with a unique name and address. The discovery server stores all the services and their addresses and automatically checks if they are running. All the services are hidden behind a common gateway used to communicate with the internet (front-end). The request from the internet is in the form https://<gatewayAddress>/<serviceName>/<restOfPath>?<args>. The gateway uses the serviceName and asks the discovery server for the service address. The request is then forwarded to the particular service (without the service name in the URL), and the response is forwarded back to the requestor.

Backend architecture scheme

Services

The API documentation containing the list of all services and all endpoints is available under the following link:

https://api.magistrmartin.cz/swagger-ui.html

Catalog service

This service is responsible for managing all products and categories, prices and discounts, and integration with third-party applications that work with product information, such as Pharmos, Pharmdata, Lekis and Heureka.

Orders service

This service is responsible for managing all kinds of orders and physical shops' infrastructure. This service also integrates third-party applications that work with orders, like GoPay, Packeta, and Lekis.

Images service

This service is responsible for storing and loading all kinds of files. It also contains functions for resizing and adjusting of images.

Structure service

This service manages some parts of the eshop website, like static pages, header and footer content, etc.

Statistics service

This service is responsible for storing and processing all data used for statistics and analysis, like sales history and sales prediction.

Notification service

This service sends emails using a company SMTP server.

Profiles service

This service manages the profiles of registered users.

Authentication and user management

User registration and login are done using a third-party service Auth0. Additional profile information is stored and managed using the profile service and paired via the userId provided by Auth0 for each user.

Technologies

All the backend services, the discovery server, and the gateway are written in Java 8 using the Spring framework with JPA to work with the database. The packages are managed with Maven. MySQL is used for the database.

How to run

After every commit/merge to the master branch, every service is automatically published to the server and used in the production.

To start the service locally, you need to have installed and set up Java 8 and Maven. Then, you can run the service simply with the command

mvn spring-boot:run

Run with VS Code

To run and debug, it is recommended to use an Extension Pack for Java. The Java and Maven must still be installed and set up correctly, including setting the JAVA_HOME variable. The detailed tutorial to set up java for VS code can be found here. You might also like Spring boot extension pack. After installing and setting up these extensions, you can run and debug all the services locally simply by pressing F5 and setting up breakpoints.

⚠️ All the services are connected to the production database, even if started locally.

⚠️ **GitHub.com Fallback** ⚠️