Let's build a hit counter using a functional domain model based on the Tagless-Final style and The Clean Architecture.
This project is based on the post F[unctional] Core, IO[mperative] Shell.
The domain is the lowest layer. Each additional layer may access any of the layers beneath it.
.-------------------------------------------.
| LAYER 4: RUNNERS o |
|-----------------------------------------|-|
| * Main method with an http server | |
'-----------------------------------------|-'
|
.-----------------------------------------|-.
| LAYER 3: DRIVERS o v |
|--------------------------------------|--|-|
| * In-memory data store | | |
| * RDBMS/JDBC data store | | |
'--------------------------------------|--|-'
| |
impure | |
=======================================|==|==
pure | |
| |
.--------------------------------------|--|-.
| LAYER 2: USE CASES o v v |
|-----------------------------------|--|--|-|
| * Increment and get the count | | | |
'-----------------------------------|--|--|-'
| | |
.-----------------------------------|--|--|-.
| LAYER 1: DOMAIN v v v |
|-------------------------------------------|
| * Entities |
| * Count |
| * Operations |
| * Increment the count |
| * Get the count |
'-------------------------------------------'