How mkiperszmid/moviedb works
Main Components
• User Interface Layer: This includes activities, composable screens (such as HomeScreen and DetailScreen), presentation components (like HomeMoviePoster, CategoryTitle, etc.), and view models (HomeViewModel, DetailViewModel). This layer is responsible for handling user interactions and displaying data.
• Domain Layer: Contains business logic – the domain models (Movie, MovieDetail, MovieList, FilterType) and use cases (such as ReduceFilteredMovies). It also includes repository interfaces (MovieRepository) which abstract the data source.
• Data Layer: Split into several sub-components:
• Remote Data Source: Implements network operations. Contains APIs (MovieApi), DTOs (e.g., MovieDtoResponse, MovieDetailResponse, and related mapping classes such as MovieMapper and MovieDetailMapper), interceptors (ApiKeyInterceptor), and extensions to handle remote responses.
• Local Data Source: Manages local persistence. Includes the Room database (MovieDatabase), DAO (MovieDao), and entity definitions (MovieEntity) for caching data.
• Repository Implementation: MovieRepositoryImpl which connects domain requests to the appropriate data source (remote or local) and handles mapping between entities and domain models.
• Dependency Injection (DI): The DI layer (e.g., CoreModule) to manage dependencies across the project.
• Testing Modules: Although not a direct runtime component, the unit tests (in the /src/test directory) and instrumentation tests provide insight on how these layers are validated.
How the Components Interact
• The UI Layer (ViewModels and screens) triggers use cases from the Domain Layer.
• Use cases call the repository interface defined in the Domain Layer to fetch data.
• The repository interface is implemented by the Data Layer (MovieRepositoryImpl), which in turn decides whether to use remote data (via MovieApi and remote DTOs) or local data (via MovieDatabase/DAO).
• Mappers are applied as data passes from the Data to Domain layer, ensuring that the domain models remain decoupled from data transfer objects.
• Dependency Injection (via the CoreModule) wires all components together.
Architectural Patterns and Principles
• Clean Architecture: The separation between UI, Domain, and Data layers is central.
• Single Responsibility Principle: Each class or module (e.g., Repository vs. Mapper) follows a clear responsibility.
• Testability: The presence of unit and instrumentation testing: tests ensure that individual components work as expected.
• Use of Extensions and Interceptors to offload responsibilities from core classes (e.g., handling API key injection).