Skip to content

Book management system with a microservices architecture, developed using Spring Boot and Spring Cloud, featuring functionalities such as catalog management, shopping cart, authentication, reviews, notifications, and invoicing.

License

Notifications You must be signed in to change notification settings

darvybm/library-microservices

Repository files navigation

Book House - Microservices-based Online Bookstore

Book House Logo

Java Spring Boot Spring Cloud Microservices MongoDB MySQL Google Cloud MVC REST API Docker Docker Compose Eureka Server SendGrid

Book House is an online bookstore project designed to provide a comprehensive experience for both users and administrators. This application is built on a microservices architecture, enabling high scalability and flexibility. Book House is developed using technologies such as Java, Spring Boot, MongoDB, MySQL, Spring Cloud, and others, with implementation and deployment managed through Docker and Docker Compose.

The application consists of several key microservices that manage different areas of the system. CatalogueService handles the book catalog in a MongoDB database, while CartService manages shopping carts, orders, and invoices in MySQL. AuthService manages user authentication and operates on MongoDB as well. ReviewService deals with book reviews and ratings, and NotificationService handles transactional emails and invoice generation using JasperReports and SendGrid.

Some of the standout features of Book House include an intuitive user interface that allows customers to explore the book catalog, apply advanced filters, and make purchases effortlessly. Administrators can manage users and view purchase histories through a robust admin panel. Additionally, the app ensures a secure experience with JWT-based authentication and efficient notifications through automatically generated invoices and emails.

Table of Contents

Features

  • Distributed Microservices: The application is designed with a microservices architecture, including services like CatalogueService for the book catalog, CartService for carts and orders, AuthService for user authentication, ReviewService for reviews and ratings, and NotificationService for emails and invoice generation.

  • Hybrid Database: Utilizes MongoDB for non-relational data management and MySQL for relational data, ensuring efficient information handling tailored to each service's needs.

  • Intuitive User Interface: Provides a seamless experience with a modern interface that makes book navigation, advanced filtering, and purchases simple. Includes an admin panel for user management and monitoring purchases.

  • PayPal Integration: Enables users to securely complete payments via PayPal, simplifying the purchase process on the platform.

  • Load Balancing: Uses Docker and Docker Compose to create at least two instances of each service, ensuring high availability and efficient load balancing to handle traffic.

  • Auto-discovery Server: Implements Netflix Eureka as a discovery server, allowing microservices to dynamically register and discover each other.

  • Centralized Configuration Server: Utilizes Spring Cloud Config Server for centralized configuration, with configuration files stored in a GitHub repository, ensuring consistent management and updates across all microservices.

  • Spring Cloud Gateway: The API Gateway powered by Spring Cloud acts as the single entry point for clients, routing requests to the appropriate services and managing communication between different microservices.

  • Secure Authentication: Implements Spring Security with JWT to ensure secure authentication and authorization, protecting access to application features and ensuring only authorized users can perform certain actions.

  • Monitoring and Scalability: Utilizes Zipkin for transaction monitoring and Docker for deployment, ensuring the application is scalable and can efficiently handle traffic and transactions.

Application

Book House offers a series of views designed to provide a smooth and comprehensive user experience. Below are the detailed views available in the application:

Instances with Eureka Server

The application uses Netflix Eureka for service management. The Eureka Server dashboard allows you to visualize the status of all deployed service instances, facilitating the administration and monitoring of the microservices infrastructure.


Instances with Eureka Server

The architecture, as previously observed, is based on microservices with high availability. To ensure high availability, each microservice has at least two instances running. This guarantees that if one instance fails, another is available to handle the requests, thereby minimizing downtime. The number of instances is managed in Docker Compose using the "Deploy" parameter. Additionally, an API Gateway has been effectively implemented to route all access URLs to the microservices, facilitating communication between the system's components. In the test image, only one instance per service is visible because Docker is not being used at that time.


Login and Registration View

Users can access the application via a login and registration page. New users complete a registration form, while existing users enter their credentials in the login form.


Login Registration


Registration Email

After completing the registration, users receive a confirmation email. Below are the desktop and mobile versions of the email.


Email Mobile Email Desktop

Home View

The main page of the application presents an attractive design with book recommendations, new releases, and links to the main sections. Users can explore the featured content and access key areas of the store.


Home 1
Home 2
Home 3
Home 4
Home 5

We decided to create a comprehensive view for Book House with a highly intuitive and aesthetic interface. In this main view, users will have access to book recommendations, see the latest books added, and more. They will also have the option to explore the full catalog. If the user is logged in, they will be able to make purchases, view their purchase history, and access additional features. Furthermore, if the user is logged in and has admin privileges, they will have access to an admin panel with a dashboard providing information about the state of the bookstore.


Catalog View

Displays a list of books available in the library, with options for applying filters and sorting. Users can search for books by different criteria.


Catalog

It is essential that the book catalog allows filtering by author, title, and literary genre. Below is an example of these filters in action. The filters are sensitive in the sense that when searching for "Sleep," for example, it will find all books containing that word or consecutive letters in the title, and the same applies to the author, enriching the search and improving SEO. Additionally, books can have more than one genre, but only the main genre is displayed on the cover. Therefore, if you filter by a genre and see a book with a cover showing a different genre than the one you selected, it means that one of its secondary genres belongs to the selected category.


Filtering by Author (Sophie Swayn):

Filter by Author

Filtering by Title (Sleep):

Filter by Title


Filtering by Genre (Humor):

Filter by Genre

As observed, there are also some additional filters, including:

  • Sort from A to Z
  • Sort from Z to A
  • Sort from lowest price to highest price
  • Sort from highest price to lowest price

Book Detail View

Provides complete information about a book, including its description, author, genre, user reviews, and related books. Users can explore the details and opinions of other readers.


Book Detail
Additional Book Details

  • Review Restriction: A user who hasn't purchased the book cannot leave a review.

Review Restriction

Review List View

Displays all the reviews of a specific book. If the book has no reviews, a message is shown indicating that the book has not been rated yet.


Review List

The average rating value is calculated based on the list of reviews that the book in question has.


Shopping Cart View

Shows the items added to the cart, allowing users to review their selections before proceeding to checkout.


Shopping Cart

Checkout View (Payment Confirmation)

Allows users to enter payment details and complete the purchase. The system uses PayPal for secure payment processing.


Checkout

  • PayPal Payment Confirmation View: Displays the payment confirmation after completing the transaction.

Payment Confirmation Payment Confirmation PayPal Confirmation View

Order Confirmation Email


Order Confirmation Email

Invoice Design in Jasper Report Studio

The invoice is generated using Jasper Reports.


Invoice Design in Jasper Report Studio Generated PDF Invoice

After this, the .jrxml file was exported to the notification service, and a ReportService was created where the confirmed order data is sent and loaded into the invoice file. Finally, the report is exported as a PDF and attached to the email sent via the SendGrid service.


User Creation View

Allows administrators to create new users with different roles and permissions.


User Creation

Purchase History View

Shows a summary of all previous purchases made by the user.


Purchase History

My Purchases View

Allows users to view a list of all their purchases, with details for each transaction.


My Purchases

Admin Dashboard View

We created a dashboard that displays purchases made by day and by genre. We also included a purchase history and, additionally, added statistical cards showing the total number of orders, the number of genres, the number of books, and the number of users in the system.


Admin Dashboard

Monitoring with Zipkin

The application uses Zipkin for microservice monitoring. Although embedded versions of Zipkin are deprecated, it has been implemented as a Docker image, integrated with Docker Compose. This allows tracking and monitoring the performance of microservices, excluding the discovery server.


Monitoring with Zipkin Zipkin

Security and Authentication

The system has high performance in terms of security. Upon logging in, the user receives a token valid for one hour. This token is encrypted and stored in a cookie, which the client uses to make requests to the Gateway. The Gateway, in collaboration with the authentication service, validates the token and either grants or denies access to the route. Additionally, the user's role is checked to ensure it has the necessary permissions for access. Otherwise, the system will generate an error.


Security and Authentication

It is important to note that when a session expires or when logging out, the user must log in again to refresh their token.

Tools Used

  • Java Java: The primary programming language used for backend development of the platform.

  • Spring Boot Spring Boot: The framework used to build the backend of the application, providing a robust and scalable architecture.

  • Spring Security Spring Security: Implemented for authentication and authorization within the platform, ensuring secure access to functionalities.

  • JWT JWT (JSON Web Tokens): Used for managing authentication and secure communication between the web application and microservices.

  • MongoDB MongoDB: NoSQL database used for storing various types of data across different services.

  • MySQL MySQL: Relational database used for managing structured data related to orders, reviews, and other transactional information.

  • Spring Cloud Spring Cloud: Provides tools for managing distributed systems, including configuration management, service discovery, and circuit breakers.

  • Spring Cloud Gateway Spring Cloud Gateway: Used as an API Gateway to route requests to various microservices.

  • Feign Feign Client: Used for declarative REST client creation, simplifying communication between microservices.

  • Zipkin Zipkin: Distributed tracing system used for monitoring and troubleshooting the performance of microservices.

  • JasperReports JasperReports: Reporting tool used for generating and formatting invoices and other documents.

  • DataFaker DataFaker: Library used for generating realistic test data, such as random books and user profiles.

  • HTML5 CSS3 JavaScript Bootstrap HTML, CSS, JS, Bootstrap: Front-end technologies used to develop the user interface, ensuring a responsive and interactive experience.

  • Docker Docker Compose Docker and Docker Compose: Used to containerize and orchestrate the microservices, simplifying deployment and scaling.

Installation

Prerequisites

  • Java 17 or higher
  • Gradle (instead of Maven)
  • Docker and Docker Compose
  • Configured databases (MongoDB and MySQL)

Steps

  1. Clone the repository:

    git clone https://github.com/user/book-house.git
  2. Navigate to the project directory:

    cd book-house
  3. Configure databases:

    • Deploy MongoDB either in the cloud or locally (e.g., MongoDB Atlas).
    • Deploy MySQL either in the cloud or locally.
  4. Configure local properties:

    • AuthService: Configure the JWT secret in the application.properties file.

      security.jwt.secret-key=addjwtkey
    • CatalogueService: Configure whether you want to generate random books on application startup in the application.properties file.

      library.catalogue.generate-books-on-startup=false
      library.catalogue.generate-books-count=50
    • ClientService: Configure local properties such as the port, encryption secret, and PayPal configuration in the application.properties file.

      crypto.secret-key=${CRYPTO_SECRET_KEY:addKey}
      paypal.client-id=${PAYPAL_CLIENT_ID:addClientId}
      paypal.client-secret=${PAYPAL_CLIENT_SECRET:addClientSecret}
      paypal.mode=${PAYPAL_MODE:sandbox}
    • ConfigServer: Configure access to your Git repository in the application.properties file.

      spring.cloud.config.server.git.uri=add your git repo here with the folder in url
      spring.cloud.config.server.git.clone-on-start=true
      spring.cloud.config.server.git.username=add your git username here
      spring.cloud.config.server.git.password=add your git password or token here
      spring.cloud.config.server.git.default-label=master

Warning

Reference should be made to the folder where the configuration files are located, not to the repository in general.

  • GatewayService: Configure the JWT secret in the application.properties file.

    security.jwt.secret-key=addjwtkey
  • NotificationService: Configure SendGrid in the application.properties file.

    sendgrid.api.key=add_your_sendgrid_api_key_here
    sendgrid.api.sender-mail=example@gmail.com
  • Modify in the Auth, Catalogue and Notification services the following url of MongoDB (this is in the properties of the configuration server).

    spring.data.mongodb.uri=${SPRING_DATA_MONGODB_URI:add_your_mongodb_uri_here}
  • Modify in the Cart and Review services the following MySQL configuration (this is in the properties of the configuration server).

    spring.datasource.url=${SPRING_DATASOURCE_URL:add_your_mysql_url_here}
    spring.datasource.username=${SPRING_DATASOURCE_USERNAME:add_your_mysql_username_here}
    spring.datasource.password=${SPRING_DATASOURCE_PASSWORD:add_your_mysql_password_here}
  1. Run the services:

    • Configure and run with Docker Compose:

      Create a .env file in the same directory as docker-compose.yml with the following variables:

      # Eureka configuration
      EUREKA_PORT=8761
      
      # Config Server configuration
      CONFIG_SERVER_PORT=8889
      
      # Database configuration
      MONGO_URI=mongodb+srv://libraryUser:your_password@librarycluster.mongodb.net/
      MONGO_AUTH_DB=auth_db
      MONGO_CATALOGUE_DB=catalogue_db
      MONGO_NOTIFICATION_DB=notification_db
      
      MYSQL_URL=jdbc:mysql://your_mysql_host:3306/
      MYSQL_USER=root
      MYSQL_PASSWORD=your_mysql_password
      MYSQL_SHOPPING_CART_DB=shopping_cart
      MYSQL_REVIEW_DB=review_db
      
      # Gateway configuration
      GATEWAY_PORT=8090
      
      # Client configuration
      CLIENT_PORT=8081
      
      # Client configuration
      
      CRYPTO_SECRET_KEY=crypto_secret_key
      
      PAYPAL_CLIENT_ID=key
      PAYPAL_CLIENT_SECRET=secret

      Then, run the services with Docker Compose:

      docker-compose up --build
    • Without Docker Compose:

      If not using Docker Compose, follow this order to run the projects:

      1. DiscoveryServer (Service discovery)
      2. ConfigServer (Centralized configuration server)
      3. AuthService
      4. CatalogueService
      5. CartService
      6. ReviewService
      7. NotificationService
      8. GatewayService (API Gateway)
      9. ClientService (User interface)
  2. Access the application:

    Open your browser and visit http://localhost:8081 to access the user interface.

Areas for Improvement

  • Performance Enhancement in Recommendation Algorithm: There is no recommendation algorithm; it was only simulated.

  • Expand Administration Panel Functionality: Add additional features to the admin panel for more comprehensive and detailed management.

  • Add Unit and Integration Tests for Greater Code Coverage: Implement and improve tests to ensure code stability and detect issues early.

  • Pagination in the Backend: Implement pagination to handle large volumes of data more efficiently and improve page load speed.

  • Documentation and Code Organization: Add explanatory comments and improve code organization to facilitate maintenance and understanding.

Contributors

Here are the contributors to this project:

darvybm
darvybm
AnthonyBeato
AnthonyBeato

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact Me

LinkedIn Badge Email Badge

About

Book management system with a microservices architecture, developed using Spring Boot and Spring Cloud, featuring functionalities such as catalog management, shopping cart, authentication, reviews, notifications, and invoicing.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published