Skip to content

gianluca-sabena/spring-clean-architecture

Repository files navigation

Spring clean

An opinionated spring template based on a "clean architecture". (See credits)

Architecture

┌─────────────────────────────────────┐
│Framework                            │
│ ┌────────────────────────────────┐  │
│ │Adapters                        │  │
│ │    ┌────────────────────────┐  │  │
│ │    │Use cases               │  │  │
│ │    │   ┌─────────────────┐  │  │  │
│ │    │   │Entities         │  │  │  │
│ │    │   │- Customers.java │  │  │  │
│ │    │   └─────────────────┘  │  │  │
│ │    │- Ports (CustomerRep...)│  │  │
│ │    │- CreateCustomer        │  │  │
│ │    │- FindCustomer          │  │  │
│ │    │- LoginCustomer         │  │  │
│ │    └────────────────────────┘  │  │
│ │- Jdbc                          │  │
│ │- Memory                        │  │
│ └────────────────────────────────┘  │
│- Spring Batch                       │
│- Spring Servlet                     │
└─────────────────────────────────────┘

1. Setup Environment

Java 17 or higher is required

Linux environment is required to run docker container

Linux/WSL2 - Recommended

  • Install sdkman https://sdkman.io/
  • Install java sdk install java 20.0.2-open
  • Install docker

Windows

  • Install scoop.sh https://scoop.sh/
  • Install java scoop install openjdk20
  • Install git with bash scoop install main/git
  • Start a bash terminal with git-bash.exe

2. Run

Open a terminal with a bash compatible shell

Use devel.sh -h to print help main actions

  • Start docker compose with postgreSQL devel.sh du
  • devel.sh test -> execute ./gradlew build
  • devel.sh buid -> execute ./gradlew build
  • devel.sh run -> execute ./gradlew bootRun

3. Setup Project

In order to switch adapter from memory to jdbc

Short answer: use devel.sh config

Long answer:

    1. edit settings.gradle and comment include 'adapters:memory' and uncomment include 'adapters:jdbc'
    1. In folder: frameworks / servlet edit file build.gradle and comment implementation project(':adapters:memory') and uncomment implementation project(':adapters:jdbc')
    1. Repeat step 2 for all other frameworks...

4. Test

Framework/servlet

  • Create a customer curl -X POST http://127.0.0.1:8080/customers --header "Content-Type: application/json" --data '{"email":"xyz@ab.com", "lastName": "Me", "firstName": "You"}'
  • List customers curl -X GET http://127.0.0.1:8080/customers

TODO

  • Experiments with application properties
  • JDBC with postgresql and oracle with ucp
  • Add tests to adapter
  • Oauth2 with local IDP provider (https://www.keycloak.org/)
  • Tescontainers
  • Buid jar
  • Add more entities (item, order)
  • Integrate lombok for entities
  • Add a serialization adapter

Credits

This project was inspired by:

Resources

Releases

No releases published

Packages

No packages published