Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE-100] Main modules for data and domain #110

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ We use [Clean Architecture](#inspiration-material), to a very large extend. Our

![Q42-CA](https://user-images.githubusercontent.com/2270625/216325003-8629f40a-c46c-43e6-ba1e-342dfb524ff9.png)

Note that the image shows separate modules per feature for domain and data (ie. data:user and domain:user). It is recommended for larger projects
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure where the source for the image lives and whether it should be updated

to make this separation, but for smaller projects, it might be too much overhead. Therefore, this template starts with a single module for domain and data: domain:main
and data:main. Decide with your team whether you want to split these modules up.

#### Clean Architecture layers

- _UI_ with Jetpack Compose
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ dependencies {
implementation(project(":core:navigation"))
implementation(project(":feature:home"))
implementation(project(":feature:onboarding"))
implementation(project(":domain:user")) // needed for di
implementation(project(":data:user")) // needed for di
implementation(project(":domain:main")) // needed for di
implementation(project(":data:main")) // needed for di
implementation(project(":core:network")) // needed for di
implementation(libs.composeDestinations)

Expand Down
9 changes: 0 additions & 9 deletions data/article/build.gradle

This file was deleted.

File renamed without changes.
2 changes: 1 addition & 1 deletion data/user/build.gradle → data/main/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ android {
}

dependencies {
implementation project(':domain:user')
implementation project(':domain:main')
implementation project(':core:network')
implementation project(':core:actionresult')
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package nl.q42.template.data.user
package nl.q42.template.data.main

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import nl.q42.template.actionresult.domain.ActionResult
import nl.q42.template.actionresult.domain.getDataOrNull
import nl.q42.template.actionresult.domain.map
import nl.q42.template.data.user.local.UserLocalDataSource
import nl.q42.template.data.user.local.model.mapToUser
import nl.q42.template.data.user.remote.UserRemoteDataSource
import nl.q42.template.domain.user.model.User
import nl.q42.template.domain.user.repo.UserRepository
import nl.q42.template.data.main.local.UserLocalDataSource
import nl.q42.template.data.main.local.model.mapToUser
import nl.q42.template.data.main.remote.UserRemoteDataSource
import nl.q42.template.domain.main.model.User
import nl.q42.template.domain.main.repo.UserRepository
import javax.inject.Inject

internal class UserRepositoryImpl @Inject constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package nl.q42.template.data.user.di
package nl.q42.template.data.main.di

import dagger.Binds
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import nl.q42.template.data.user.UserRepositoryImpl
import nl.q42.template.data.user.remote.UserApi
import nl.q42.template.domain.user.repo.UserRepository
import nl.q42.template.data.main.UserRepositoryImpl
import nl.q42.template.data.main.remote.UserApi
import nl.q42.template.domain.main.repo.UserRepository
import retrofit2.Retrofit
import javax.inject.Singleton

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package nl.q42.template.data.user.local
package nl.q42.template.data.main.local

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.update
import nl.q42.template.data.user.local.model.UserEntity
import nl.q42.template.data.main.local.model.UserEntity
import javax.inject.Inject

internal class UserLocalDataSource @Inject constructor() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package nl.q42.template.data.main.local.model

import nl.q42.template.domain.main.model.EmailAddress
import nl.q42.template.domain.main.model.User

internal data class UserEntity(val email: String)

internal fun UserEntity.mapToUser() = User(email = EmailAddress(email))
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package nl.q42.template.data.main.mapper

import nl.q42.template.data.main.local.model.UserEntity
import nl.q42.template.data.main.remote.model.UserDTO

internal fun UserDTO.mapToEntity() = UserEntity(email = args.email)
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package nl.q42.template.data.user.remote
package nl.q42.template.data.main.remote

import com.haroldadmin.cnradapter.NetworkResponse
import nl.q42.template.actionresult.data.ApiErrorResponse
import nl.q42.template.data.user.remote.model.UserDTO
import nl.q42.template.data.main.remote.model.UserDTO
import retrofit2.http.GET
import retrofit2.http.Query

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package nl.q42.template.data.user.remote
package nl.q42.template.data.main.remote

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import nl.q42.template.actionresult.data.mapToActionResult
import nl.q42.template.actionresult.domain.ActionResult
import nl.q42.template.actionresult.domain.map
import nl.q42.template.data.user.local.model.UserEntity
import nl.q42.template.data.user.mapper.mapToEntity
import nl.q42.template.data.user.remote.model.UserDTO
import nl.q42.template.data.main.local.model.UserEntity
import nl.q42.template.data.main.mapper.mapToEntity
import nl.q42.template.data.main.remote.model.UserDTO
import javax.inject.Inject

internal class UserRemoteDataSource @Inject constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.q42.template.data.user.remote.model
package nl.q42.template.data.main.remote.model

import kotlinx.serialization.Serializable

Expand Down

This file was deleted.

This file was deleted.

1 change: 0 additions & 1 deletion domain/article/.gitignore

This file was deleted.

8 changes: 0 additions & 8 deletions domain/article/build.gradle

This file was deleted.

21 changes: 0 additions & 21 deletions domain/article/proguard-rules.pro

This file was deleted.

2 changes: 0 additions & 2 deletions domain/article/src/main/AndroidManifest.xml

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package nl.q42.template.domain.user.model
package nl.q42.template.domain.main.model

@JvmInline
value class EmailAddress(val value: String)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package nl.q42.template.domain.user.repo
package nl.q42.template.domain.main.repo

import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import nl.q42.template.actionresult.domain.ActionResult
import nl.q42.template.domain.user.model.User
import nl.q42.template.domain.main.model.User

interface UserRepository {
suspend fun fetchUser(): ActionResult<Unit>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package nl.q42.template.domain.user.usecase
package nl.q42.template.domain.main.usecase

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import nl.q42.template.actionresult.domain.ActionResult
import nl.q42.template.domain.user.repo.UserRepository
import nl.q42.template.domain.main.repo.UserRepository
import javax.inject.Inject

// A UseCase models an action so the name should begin with a verb. For Flows, use: GetSomethingFlowUseCase
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package nl.q42.template.domain.user.usecase
package nl.q42.template.domain.main.usecase

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flowOn
import nl.q42.template.domain.user.model.User
import nl.q42.template.domain.user.repo.UserRepository
import nl.q42.template.domain.main.model.User
import nl.q42.template.domain.main.repo.UserRepository
import javax.inject.Inject

class GetUserFlowUseCase @Inject constructor(private val userRepository: UserRepository) {
Expand Down
1 change: 0 additions & 1 deletion domain/user/.gitignore

This file was deleted.

21 changes: 0 additions & 21 deletions domain/user/proguard-rules.pro

This file was deleted.

2 changes: 0 additions & 2 deletions domain/user/src/main/AndroidManifest.xml

This file was deleted.

2 changes: 1 addition & 1 deletion feature/home/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ android {
}
}
dependencies {
implementation project(':domain:user')
implementation project(':domain:main')
implementation project(':core:ui')
implementation project(':core:actionresult')
implementation project(':core:navigation')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import nl.q42.template.actionresult.data.handleAction
import nl.q42.template.domain.user.usecase.FetchUserUseCase
import nl.q42.template.domain.user.usecase.GetUserFlowUseCase
import nl.q42.template.domain.main.usecase.FetchUserUseCase
import nl.q42.template.domain.main.usecase.GetUserFlowUseCase
import nl.q42.template.feature.home.R
import nl.q42.template.home.destinations.HomeSecondScreenDestination
import nl.q42.template.navigation.AppGraphRoutes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runTest
import nl.q42.template.actionresult.domain.ActionResult
import nl.q42.template.domain.user.usecase.FetchUserUseCase
import nl.q42.template.domain.user.usecase.GetUserFlowUseCase
import nl.q42.template.domain.main.usecase.FetchUserUseCase
import nl.q42.template.domain.main.usecase.GetUserFlowUseCase
import nl.q42.template.presentation.home.MainDispatcherRule
import org.junit.Rule
import org.junit.Test
Expand Down
2 changes: 1 addition & 1 deletion feature/onboarding/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ android {
}
}
dependencies {
implementation project(':domain:user')
implementation project(':domain:main')
implementation project(':core:ui')
implementation project(':core:actionresult')
implementation project(':core:navigation')
Expand Down
6 changes: 2 additions & 4 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,8 @@ dependencyResolutionManagement {
}
rootProject.name = "Template.Android"
include ":app"
include ":data:user"
include ":data:article"
include ":domain:user"
include ":domain:article"
include ':data:main'
include ':domain:main'
include ":feature:home"
include ":feature:onboarding"
include ":core:network"
Expand Down