Search code examples
androidarchitectureclean-architecture

Android Clean architecture - on which layer should I put given functionality


Imagine, that we have Android application, which is splitted by groups:

  • Presentation - which concerns fragments, viewmodels and view-specific logic
  • Domain - concerns use cases and interfaces, code is library and framework - independent
  • Data - storing and retrieving data, e.g. from database and REST API

And then there is a need to implement a library, which is responsible for communication with specific hardware, and stores states about it. This library should be used in domain layer, and will be used by implementation of interface from domain layer.

My question is: on which layer should we place implementation of this library? Data layer should be ok for that, or we should create additional layer - if yes, how should we name it?


Solution

  • Clean, Onion, and Hexagonal Architecture are different names for the same thing. However, they each have a unique vocabulary, designed to drive you to different blogs and books. Therefor I must point out that Clean Architecture doesn't have a domain layer. That term comes from Onion Architecture.

    In any case, no. A "library, which is responsible for communication with specific hardware" belongs in the outermost layer. Whether you want to call that layer adapter=, infrastructure=, or device drivers=.