Hi! I created a backend based on the Clean Archite...
# server
e
Hi! I created a backend based on the Clean Architecture principles. Feedback would be very much appreciated! The application is separated into three modules: Domain, Usecases and Adapters • Domain module contains all entities, it's validation and repository interfaces • Usecases module performs actions on the domain entities and repositories and does authorization The domain and usecase modules do not have any external dependencies. • Adapter layer: each adapter is implemented as a standalone module, lowering dependence on specific frameworks and libraries and making them interchangable. The server module consumes all adapters (e.g. databases, (graphql) endpoints, authentication logic) GraphQL endpoints are auto-generated from the Usecases Used technologies: Ktor, JWT, Exposed, Flyway, KGraphQL/GraphQL generated endpoints. https://github.com/ESchouten/CleanArchitecture
👏 3
a
If you need to implement logging, in which module are you gonna place the logger?
e
@Andika Wasisto For external logging serviced, I'd implement it in a new adapter and inject it into the usecases via an interface, for local system logging either the same could be done so it could be changed to more advanced logging without changing the usecase layer, or you could just implement the library in the domain or usecase layer itself
a
I'd implement it in a new adapter and inject it into the usecases via an interface
@ESchouten I assume you would implement it in
adapters/logging/src/main/kotlin/logging/LoggerImpl.kt
. Where would you put the
Logger
interface? Assuming the interface will be used by both the use case layer and the adapter layer
e
@Andika Wasisto Exactly! You could place the interface in the usecases/dependency folder like PasswordEncoder and Authenticator interface. At the config adapter, in the Koin file, you need to define the dependency for injection like done with the password encoder. Having done this, the dependency will be injected correctly when required in the usecase constructor
a
Since the
Logger
interface will be used by multiple layers, not just the use case layer, I think it's better to create a
common
or
sharedkernel
module to contain these cross-cutting components References: https://github.com/ardalis/CleanArchitecture/tree/main/src https://github.com/jasontaylordev/NorthwindTraders/tree/master/Src