Looking at the clean architecture layers and flow diagrams, and implemented it my self in my applications, I've always wondered which layer is supposed to contain the DB, or any 3rd Party service or SDK.
Looking at both of these images raises the question if there isn't violation in the outer layers.
I've imagined the layers division like this:
But this means that there is a violation of the dependancy rule. Since the gateway always knows about both the external service, and the application it self, the entities.
Is there a correct way to draw these layers? I've read a couple of resources asking this question, but didn't really get a full answers to what I need. For example: https://groups.google.com/g/clean-code-discussion/c/oUrgGi2r3Fk?pli=1, Doesn't repository pattern in clean architecture violate Dependency inversion principle?
I get it that the meaning of clean architecture is kept, and the inner layers, the entities and the use case, aren't affected by a change in the DB and the gateway, but was just wondering if maybe this is more accurate:
edit:
From the book:
Recall that we do not allow SQL in the use cases layer; instead, we use gateway interfaces that have appropriate methods. Those gateways are implemented by classes in the database layer.
So I guess this means that the data access is really in the most outer layer:
Maybe for this specific example, there is no real use for the interface adapters layer?
But also from the book about interface adapters layer:
Similarly, data is converted, in this layer, from the form most convenient for entities and use cases, to the form most convenient for whatever persistence framework is being used (i.e., the database). No code inward of this circle should know anything at all about the database. If the database is a SQL database, then all SQL should be restricted to this layer—and in particular to the parts of this layer that have to do with the database.
Also in this layer is any other adapter necessary to convert data from some external form, such as an external service, to the internal form used by the use cases and entities.
So it kinda contradicts that the data access is in the database layer, since this is what it does, converts from the DB, for example SQL rows, into the application's entities. Are these layers not really separated? I'm confused.