How android10/android-cleanarchitecture works
Project Type and Purpose
• This is an Android sample app that implements the Clean Architecture pattern.
• Its purpose is to demonstrate how to separate concerns in an Android application, making maintenance, testing, and scalability easier.
File Structure to Determine the Main Layers
• There are three main modules or packages:
a. Presentation: Contains Android UI code (Activities, Fragments, Adapters, Views) and dependency injection classes (Dagger modules and components).
b. Domain: Contains business logic, use cases (interactors such as GetUserDetails and GetUserList), domain models (e.g., User), exception handling (error bundles), and thread executor abstractions.
c. Data: Responsible for data handling and persistence. This layer implements caching (FileManager, UserCache), network calls (RestApi), entity mapping, repository implementations (UserDataRepository) and defines data sources (CloudUserDataStore, DiskUserDataStore).
Main Components and Their Interactions
• Presentation Layer:
• Android UI components (Activities, Fragments, Adapters and Views) reside here.
• Dependency Injection setup is provided through Dagger (modules and components in internal/di).
• It calls use cases (located in the domain layer) via presenters (UserListPresenter, UserDetailsPresenter).
• Domain Layer:
• Contains use cases (GetUserDetails and GetUserList) which encapsulate business logic.
• Contains domain models (User) and abstract executor interfaces (ThreadExecutor, PostExecutionThread) to control threading.
• Defines a repository interface (UserRepository) which is implemented in the data layer.
• Data Layer:
• Implements the repository pattern (UserDataRepository) to provide data to the domain layer.
• Houses data sources for remote calls (RestApi/ApiConnection) and local persistence (cache implementations, FileManager).
• Uses entity mappers (UserEntityDataMapper, UserEntityJsonMapper) to convert raw data into domain entities.
• For each section, list the key components:
• Presentation: UI components (activities, fragments), DI components (ApplicationComponent, ActivityComponent, etc.), navigators.
• Domain: Use Cases, Domain Models, Exception Contracts, and Execution Threads.
• Data: Repository implementations, Data Sources (Cloud & Disk), Caching mechanisms, Network APIs, and Entity Mappers.
• From Presentation → Domain: The presentation layer (via its presenters) calls use case methods.
• From Domain → Data: The use cases in the domain layer call the repository interface, which is implemented in the data layer.
Important Architectural Patterns and Design Principles
• Clean Architecture: Emphasize separation of concerns with domain logic being isolated from the data and presentation layers.
• Dependency Injection: Note the use of Dagger for managing dependencies in the presentation layer.
• Repository Pattern: Show how repositories abstract the source of data (remote vs. local).
• Interaction Layers: Make it clear that the presentation layer never directly accesses data sources but goes through the domain layer's use cases.
Incorporate Technology and Framework Details
• Android SDK: Underlying framework for the Presentation layer.
• Gradle: Build system used to manage project dependencies and builds.
• Dagger 2: Dependency Injection framework observed in the presentation internal/di directory.
• Networking or REST: Represented via classes like RestApi and ApiConnection for network operations.
• Caching: Illustrate caching techniques with classes like UserCache, FileManager, and serializers.
Final Elements
• Each major component (e.g., Use Cases, Repository, UI components, DI Components) should be distinctly labeled.