Edison Android Exercise - Architecture
Document
1. Overview
This document presents the high-level architecture of the Edison Android Exercise application.
The app is designed to fetch and display cat facts from an API, allowing users to view and save
their favorite facts.
2. Architecture Pattern
The application adopts the MVVM (Model-View-ViewModel) architecture pattern. This
approach ensures a clear separation of concerns, enhances testability and improves
maintainability.
3. Components
Model:
● Represents the app's data.
● Includes CatFactEntity and FactResponse data classes.
View:
● Handles the user interface and interactions.
● Implemented via Activities and Fragments.
ViewModel:
● Acts as a bridge between the View and the Model.
● Manages data preparation for the View and processes user actions.
● Represented by the FactViewModel class.
Repository:
● Provides a clean abstraction layer for data management.
● The CatFactRepository interface and its implementation,
CatFactRepositoryImpl, manage data retrieval from both the API and the local
database.
Data Sources:
● Remote Data Source:
○ The FactService interface and its implementation handle communication with
the Cat Facts API.
● Local Data Source:
○ The CatFactDao interface and its implementation manage interactions with the
local database using Room.
4. Data Flow
1. The View (Activity/Fragment) observes the UI state exposed by the ViewModel.
2. When the View requires data, it triggers an action in the ViewModel (e.g.,
fetchCatFact()).
3. The ViewModel interacts with the Repository to fetch data from the appropriate source
(API or database).
4. The Repository returns data to the ViewModel.
5. The ViewModel updates the observed UI state.
6. The View updates its UI based on the updated state.
5. Dependencies
● Hilt: Dependency injection framework for managing object creation and lifecycles.
● Retrofit: Facilitates network communication with the API.
● Room: Provides local data persistence with a structured database.
● Coroutines: Supports asynchronous operations and efficient background thread
management.
● Flow: Enables reactive data handling and UI updates.
6. Error Handling
The app employs a Result sealed class to represent operation outcomes. This approach
allows for granular handling of success cases and various error types (e.g., network, API,
unknown).
7. Testing
● Unit Tests: Verify individual components, including ViewModel, Repository, and Data
Sources, in isolation.
● UI Tests: Validate user interface behavior and interactions.
8. Future Improvements
● Enhance error handling with detailed feedback mechanisms.
● Implement offline mode for improved user experience.
● Refine the UI design and overall user experience.
● Introduce additional features and functionality.
9. Conclusion
This document provides a high-level architectural overview of the Edison Android Exercise
application. By leveraging the MVVM pattern and a robust selection of dependencies, the app is
designed to be modular, testable, and maintainable. These architectural principles lay a solid
foundation for future enhancements and scalability.