Skip to content

Latest commit

 

History

History
80 lines (53 loc) · 3.42 KB

README.md

File metadata and controls

80 lines (53 loc) · 3.42 KB

Clean Architecture

This project is a Java template for creating a Spring Boot application using the principles of Clean Architecture. This project also uses a pattern called CQRS. You can read more about that here.

Why

I'm a big fan of the popular .NET template by Jason Taylor therefore this template takes a lot of inspiration from that template, and aims to provide a similar experience in Spring and Java. Although, primarily, I have created this as more of a learning exercise. Feel free to use this however you wish.

Technologies

Todo

  • Integration Tests
  • Refactor domain layer to remove dependencies

Getting Started

Testing

This project uses JUnit4, Spring Security Test and Java Snapshot Testing for unit tests. I've chosen to use Snapshot Testing here as I believe this is quite a clean approach for validating the output of commands and queries, which can often become complex in real-world applications.

Generator

As there is quite a bit of boilerplate required to create new commands or queries, this project ships with a small generator utility to quickly create the necessary files and test files.

To set up the generator, run the following (you will need NodeJS, I use nvm to manage this easily):

cd generator
npm install

You can run the generator by running the following command. You will be presented with an interactive generator which will aim to do its best to get you started with new commands, queries, and events.

npm run generate

Overview

Domain

This layer contains all entities, events, enums, interfaces and logic specific to the domain layer.

Application

This layer contains all application logic and is dependent on the domain layer but has no dependencies on any other layers. This layer defines all the interfaces that are implemented in the infrastructure layer. For example, if you needed to add a new service, you would define the interface here and implement it in the interface layer.

Infrastructure

This layer contains classes for accessing external resources such as databases, file services, web services, etc. These classes should implement the interfaces defined in the application layer.

Web

This layer defines the entry point for the web service, which is a Spring Rest API. This layer handles configuring the Spring application and all the dependencies required, such as Spring Security, OpenAPI, Logging, etc. This layer depends on the application and infrastructure layers.

License

This project is licensed with the MIT license.