×
Back to book

SpringBot Architecture

Learn about the technology that we use for SpringBot. This article provides a high level overview of the different technologies and frameworks used by SpringBot, along with resources to assist developers with becoming familiar with and start working with the bot.

From a high-level overview, the server-side uses Spring, Hibernate, and PostgreSQL, while the client-side uses Angular. The API between the server-side and client-side uses REST, with emphasis on the OpenAPI and Swagger definitions. It also uses GraphQL and a scattering of other cool technologies.

SpringBot has two main components, a Spring Boot server-side and an Angular client-side.

Main Technologies

Server-Side

The Spring framework is the most popular modern Java application framework^ and we take advantage of its suite of features as part of SpringBot.

^ According to the 2019 Github developer survey.

The SpringBot server-side application is built using Java Spring Boot. There are a couple of options available to help you become available with Spring Boot:

  1. Start with a Spring demo project. Pick from the many Getting Started projects and guides which are available, or
  2. Follow the Building an Application with Spring Boot guide.

Client-Side

The client-side of SpringBot is built using Angular (v 7.0). Before you start using the bots, we recommend that you first become familiar with the Angular technology. The below articles are a good place to start:

  1. Introduction of Angular
  2. Key concepts
  3. Basic tutorial (Focusing on the Angular fundamentals)

Supporting Tools and Libraries

Server-Side

Gradle (Dependency Management)

We use Gradle for two different purposes: to help automate our local environment setup, and to use plugins to handle common configurations between different projects. Spring Boot has a plugin which integrates with Gradle, which we use to auto-configure a lot of things, alongside the following plugins:

Plugins

  • Java/War for building artifacts
  • Eclipse and Idea (for IDE integration)
  • org.springframework.boot to expose the commands,
    • bootRun - Run the application in dev
    • bootWar - Create a .war artifact, used in conjunction with the war plugin.
    • bootJar - Create a .jar artifact.
  • com.benjaminsproule.swagger - OpenAPI documentation
  • io.spring.dependency-management - Supplies Maven like dependency management
  • com.adarshr.test-logger - Makes test logs more readable.

Repositories

For dependency management, we need to get our dependencies from somewhere. While we use Gradle for plugins, we make use of Maven Central for repositories, as it can work with both Maven and Gradle. We also support the Maven local repository to allow for any local dependencies to also be integrated within our application for use during development. While this is supported, we strongly discourage this use for any environment outside of the a local development one.

Java (v11)

While Spring supports many different versions of Java, SpringBot does not. While we have the intention of supporting the newest version of Java with long term support, SpringBot was built with support for Java 11 or greater.

Hibernate (ORM)

An ORM was used to simplify and abstract away the data layer from the application logic. Hibernate was chosen as the ORM due to both its popularity and level of integration with Spring.

We utilise various Hibernate features, including Validation, Entity Manager, and Envers for auditing. We also make use of JPA (Java Persistence API) Hibernate to simplify things further. Spring Data JPA acts as a layer over the top of Hibernate to provide us with abstractions to assist with easy access to data.

Within SpringBot we make use of the PagingAndSortingRepository which provides simple paging and sorting in your interface. This allows us to simply define our queries as method stubs.

Lombok

Java is well known for its verbosity. To help combat this and assist in the creation of more readable, maintainable code, we make use of Project Lombok which is a library that abstracts away large portions of boiler plate code. Lombok is supported by most IDEs and build tools, with first party support for Intellij, Eclipse and VS Code.

While supported, there is one caveat for using Lombok. Annotation processing must be enabled for each editor. See Using Lombok for details.

QueryDSL

While Hibernate JPA provides fantastic tooling, constructing complex queries can still be a lot of work. Springbot makes use of another layer on top of a given repository to help combat this. QueryDSL is used to assist in building more flexible and dynamic queries for filters and search.

QueryDSL plays well with JPA and provides and nicer to user API than Hibernates.

GraphQL (API)

Springbot supports both the traditional REST API as well as the more modern GraphQL. GraphQL is a query language designed and developed by Facebook. Many people claim that GraphQL is the new REST. Our development team couldn't come to a consensus so we thought, why not both?

By supporting the best of both worlds, our client-side applications can communicate using the flexible GraphQL, but we still have a fully documented OpenAPI available for any third party integrations. To make developing with GraphQL easier, we make use of Voltair and Voyager. These two Spring Boot dependencies allow the discerning developer to easily explore their API.

To start getting your head around Spring Boot and GraphQL, have a look at this Getting Started with GraphQL and Spring Boot guide. We also recommend having a read of Introduction to GraphQL beforehand to make sure you understand the underlying concepts.

We make use of GraphQL Java Tools to manage the GraphQL schemas.

Swagger (API Documentation)

Swagger is an open source standard for OpenAPIs. SpringBot makes use of this with Springfox to automatically create the API documentation.

PostgreSQL (Database)

Behind every good Spring application is a good database, and as all good children believe, PostgreSQL is "The World's Most Advanced Open Source Relational Database". As such, SpringBot supports PostgreSQL out of the box. While PostgreSQL is our preferred database, Spring is not fussy and it is a simple task to switch to a different database technology.

For using embedding databases, a common technology to use is H2 as it makes the process simple.

Quartz Scheduler

We use Quartz Scheduler to manage our scheduled jobs, since its ability to work in a clustered environment differs from the core Spring scheduling functionality.

Client-Side

Testing Tools

Server-Side

Cucumber

Cucumber is a software tool used by computer programmers to write user acceptance tests in a logical language that is readable and understandable by non-techies. Its plain language parser, known as Gherkin, allows developers to write code that ensures expected software behaviour in a logical language.

Selenium

Selenium is a portable framework for testing web applications. Selenium provides a playback tool for authoring functional tests without the need to learn a test scripting language. The Selenium framework is used in conjunction with several other Java libraries such as WebDriverManager to automate the sourcing of web drivers and browsers to allow cross-browser testing.

Mockneat

Mockneat is an arbitrary data-generator open-source library written in Java and is being used as a powerful Random substitute or a mocking library. There is a tutorial available here.

JUnit

JUnit is a unit testing framework for the Java programming language and is being used as a simple framework to write repeatable tests.

Client-Side

Karma

Client-side test orchestration. See the karma-runner documentation for more details.

Jasmine

Client-side Unit testing framework. For more details see the Jasmine documentation.

Other Tools