Open gradywetherbee opened 11 months ago
TL;DR: The dependency on a third-party library places the implementation in the infrastructure layer, while the interface remains in the domain layer.
If we translate this:
const Id = Object.freeze({
makeId: cuid,
isValidId: cuid.isCuid
})
into
interface Id {
makeId(): string
isValidId(id: string): boolean
}
The interface itself is dictated by the Domain Layer, specifically by the Entities
in this case, but it can also be dictated by the use-cases
. Either way, the Id
object is a part of the domain logic, as it provides a fundamental service (ID generation and validation) that is used across the domain.
The fact that the interface implementation depends on a 3rd party library is not crucial here. While the implementation itself belongs to the infrastructure (framework) layer, the important point is that entities work with something that fulfills the Id
interface.
I see that the factory builders for entities like
comment
acceptId
as an argument. Is the implementation ofId
in the Id folder considered part of the "framework" layer in clean architecture because it's relying on an external dependency (cuid) directly?How should I be thinking about this?