err0r500 / go-realworld-clean

a clean architecture implementation of the realworldapp : https://github.com/gothinkster/realworld
MIT License
516 stars 81 forks source link

HTTP details on interface adapters layer #5

Closed Ridzhi closed 4 years ago

Ridzhi commented 4 years ago

Hi, thanks for example. Can you explain pls why you put http details (router for example) to interface adapters layer(implem directory)?. From reading articles on clean architecture it seems like it should be on a frameworks & drivers layer, isn't it?

err0r500 commented 4 years ago

Hi, I think that what is called "interface adapters layer" is merged with "frameworks & drivers" in this code base. On the UC layer, interfaces are declared ; in the "implem" layer they are... implemented.

As you can see, interfaces don't know a single thing about how they will be implemented, the job of mapping these abstract data structure with their corresponding implementation specific ones (the "interface adapters layer) is the responsibility of each implementation, so I merge both in order to minimize the numbers of levels of indirections while enforcing the exact same pattern.

I guess the single use case of actually separating "interface adapters" and "frameworks" is if you want to use the same adapter with 2 implementations. I think it's doesn't happen so often : I can think of abstracting over postresql and mysql implementations but even in this case I'd prefer copy/paste my data structures and be sure I don't introduce coupling between them.

I think the important thing with this kind of architecture is to get its "gist" and adapt it to your own needs, for instance I used it in Haskell and it worked unexpectedly well ! :)

I hope it makes sense and sorry for the delay.