This is a simple hands-on Spring application demonstrating how to implement Clean Architecture (Uncle Bob).
You can find the accompanying slides, here.
This codebase utilizes injection, to easily swap the persistence gateway. Thus, by only swapping (injecting) another Gateway, one can go from in-memory persistence to a persistent storage (i.e. Mongo), see here, without changing anything else (domain models / logic ect). This accounts for the notion that a database is an implementation detail.
- Setup Dockerfile to host container with Mongo, enable Injecting Mongo Gateway
- Uncomment Spring Mongo Webstarter dependency and Mongo Gateway to enable swapping In-memory storage with Persistent Storage.
Note: this application comes with the Gradle Wrapper, therefore one does not need to install Gradle
- Make sure prerequisites are met, then clone the repo:
$ git clone git@github.com:srmds/clean-architecture-spring-kotlin.git
- Navigate to root of project, then:
$ ./gradlew clean build --stacktrace
$ ./gradlew bootRun --stacktrace
Here you will find how the different layers have each own responsibilty, and which corresponding class is represented in each layer.
Register new Companies to an online platform.
In order to register a new company As a site admin I need to be able to register new companies
- A company must have a name
-
Given that the company has approved to be listed on the public online platform
-
When I register the new arrived company with platform API
-
Then I should have a verification that the registration has succedeed and
-
And overall the new company is listed in the overview of
GET
/api/v1/companies
HTTP 200 OK
[
{
"name": "CompanyName",
"website": "https://example.com",
"missionStatement": "Lorum ipsum dolor...",
"logo": "https://via.placeholder.com/50x50.png"
},
...
]
POST
/api/v1/companies
{
"name": "CompanyName",
"website": "https://example.com",
"missionStatement": "Lorum ipsum dolor...",
"logo": "https://via.placeholder.com/50x50.png"
}
HTTP 201 CREATED
{
"id": "eb4cce9f-2055-444c-8a21-107c9c0cb410",
"name": "CompanyName",
"website": "https://example.com",
"missionStatement": "Lorum ipsum dolor...",
"logo": "https://via.placeholder.com/50x50.png",
"registration": {
"status": "ACCEPTED",
"date": "2019-12-03 22:46:58"
}
}