Skip to content

Blog

Vim Set up

Hello

Hello world!

Terminal window
sudo apt-get install -y ripgrep

Set up initial file

Terminal window
mkdir -p ~/.config/nvim
cd ~/.config/nvim
touch init.lua
mkdir -p lua/mc/core
mkdir -p lua/mc/plugins
mkdir -p lua/mc/plugins

require(“mc.core.options”)

1.Building the catalog service

  • In first chapter of this series, we’ll start with a web application that exposes its functionality over HTTP through a REST API using Spring Boot. NovelNest system has a Catalog Service application that’s responsible for managing the books available in the catalog.

Initializing the project

  • We’ll generate a Spring project from IDEA and store it in the catalog-service repository on Github (which belongs to NovelNest organization)

NovelNest Architecture

REST API Specifications

  • Catalog Service will be responsible for supporting the following use cases:
    • View the list of books in the catalog
    • Search books by their ISBN.
    • Add a new book to the catalog
    • Edit information for an existing book.
    • Remove a book from the catalog.

In other words, we can say the application should provide an API to perform CRUD operations on books.

EndpointHTTP MethodRequest bodyStatusResponse bodyDescription
/v1/booksGET200Book[]Get all the books in the catalog
/v1/booksPOSTBook201BookAdd a new book to the catalog
402A book with the same ISBN already exists
/v1/books/{isbn}GET200BookGet the book with the given ISBN
404No book with the given ISBN exists
/v1/books/{isbn}PUTBook200BookUpdate the book with the given ISBN
201BookCreate a book with the given ISBN
/v1/books/{isbn}DELETE204Delete the book with the given ISBN

Business logic

The contract is established through the REST API, so let’s move on and look at the business logic. The solution is centered around three concepts:

  • Entity: an entity represents the noun in a domain. In this case: “Book”.
  • Service: a service defines the use cases for the domain. For example: “adding a book to the catalog”.
  • Repository: a repository is an abstraction to let the domain layer access data independently from its source.

Defining the domain entity

  • In the catalog service project, create a new com.novelnest.catalogservice.domain package for the business logic, create a Book java record to represent the domain entity.
package com.novelnest.catalogservice.domain;
public record Book (
String isbn,
String title,
String author,
Double price
){}

Tests

Unit tests

Integration tests

0.Introduction to NovelNest project

Preface

  • In this series, I aim to build an example web app as close as real-world scenario as possible and then set up the necessary infrastructure for it from scratch.

  • NovelNest is a specialized bookshop whose mission is to spread knowledge and information. The organization behind NovelNest - has decided to start selling its book online.

NovelNest system requirements

  • Books will be available for sale through the application: when a customer purchases a book, they should be able to check on the status of their order. Two categories of people will use the NovelNest application:
    • Customers can browser books in the catalog, buy some, and check their orders.
    • Employees can manage books, update existing ones, and add new items to the catalog.

NovelNest Architecture

NovelNest Architecture

Patterns and Technologies used in NovelNest project

Web and interactions

  • NovelNest comprises of several services that will have to communicate with each other to provide their functionality. We’ll build RESTful services that interact synchronously over HTTP, both in a blocking way and non-blocking ways (reactive-programming). Spring MVC and Spring WebFlux will be our main tools for accomplishing such a result.

Data

  • We’ll use PostgreSQL database to permanently store the data processed by the application.
  • Spring Data JDBC, Spring Data R2DBC (reactive)
  • Manage schema migrations with Flyway
  • Event-driven programming patterns: Spring AMQP and RabbitMQ
  • Session storage: Redis

Routing

  • Spring Cloud Gateway: a service that will act as an API Gateway to shield the outside from any internal API changes. It will also be an edge that we’ll use to address cross-cutting concerns, like security and resilience in one place. This service will be the entry point to the NovelNest app, and it will have to be highly available, performant and fault-tolerant.

Observability

  • The services in the NovelNest system should be observable.
  • Spring Boot Actuator
  • Prometheus, Grafana
  • Distributed tracing with OpenTelemetry
  • Logging: Fluentbit, Loki

Resilience

  • Spring Cloud Circuit Breaker, Resilience4j to implement circuit breakers, retries, timeouts and other patterns

Security:

  • Authentication, Authorization functionality
  • Secure communication between services, between users and applications.
  • Oauth 2.1 and OpenID connect.
  • Spring security
  • Keycload for indentity and access control management

Testing

  • Automated testing: JUnit5

Build and Deployment

  • Docker, Kubernetes
  • Spring Native and GraalVM
  • CI/CD: Jenkins, GitOps with ArgoCD

UI

  • Angular Framework