mitchtabian / Open-API-Android-App

Kotlin, MVI, Hilt, Retrofit2, Coroutines, Room Persistence, REST API, Token Authentication
692 stars 231 forks source link

Question to acthitecture: Where to put potential workers? #33

Open Berki2021 opened 3 years ago

Berki2021 commented 3 years ago

I really like this repository, and it's architecture and project-structure. Currently, I am trying to implement "clean-achitecture" to one of my projects and stumbled upon one question: Where to put all the worker classes? For example, let's look at the following CoroutineWorker:

@HiltWorker
class DocumentListWorker @AssistedInject constructor(
    @Assisted context: Context,
    @Assisted params: WorkerParameters,
    private val firebaseEntity: DocumentRepository,
    private val documentDao: DocumentDao,
    private val networkMapper: DocumentNetworkMapper,
) : CoroutineWorker(context, params) {
    override suspend fun doWork(): Result {
        Timber.d("Started DocumentWorker")
        // Get Data from Cloud Firestore and map it to a DocumentCacheEntity to insert it to the database
        val documentEntityList = firebaseEntity.getAllDocuments()
        val documentCacheList = networkMapper.mapFromEntityList(documentEntityList)

        documentDao.deleteAll()
        documentDao.insert(documentCacheList)

        return Result.success()
    }
}

My question is: In which package would such a class fit the best? Here are my thoughts:

  1. Not into presentation, because it has nothing to do with ui
  2. Not into domain because it does not represent any sort of domain-data
  3. Not into interactors
  4. Somewhere into datasource, maybe into network as business -> datasource -> network -> worker OR
  5. As another package inside datasource, so business -> datasource -> worker?

I appreciate any answer, thank you very much

razaghimahdi commented 3 years ago

adding worker package to datasource looks good, maybe adding this class to Utils package? which is could be in presentation package?