How thcainthry/erabook works
Main Components
• User Interface (UI) Layer:
• Activities & Fragments: Includes various fragments (home, discover, favorite, login, register, user info, etc.) and activities such as MainActivity and ForgotPasswordActivity.
• Layouts and Resources: Organized under app/src/main/res (layouts, drawables, navigation graphs, etc.).
• ViewModel Layer:
• Contains ViewModels for each functional area (AuthenticationViewModel, HomeViewModel, FavoriteViewModel, etc.). This layer manages UI-related data in a lifecycle-conscious manner.
• Data & Service Layer:
• API Service Integration:
▪ NYTService handles calls to the NYT Best Sellers API.
▪ GoogleApi (inside googlebooks folder) handles search and detail retrieval from Google Books.
▪ OSMService interacts with OpenStreetMap APIs for location-based services.
• Data Models: The data package contains structured models (e.g., VolumeInfo, AccessInfo, Epub, UserDataRemote, etc.) that mirror API responses and local storage representations.
• Dependency Injection (DI) Layer:
• Modules like BooksModule, NYTModule, and OSMModule support dependency injection, ensuring that services and components are easily provided and decoupled.
• Firebase Integration:
• Authentication: Managed through Firestore Auth.
• User Favorites & Profile: Data is stored and retrieved from the Firestore Database.
• External Service Integration:
• Countdown Timer & Notification Utilities: To remind the user (with NotificationUtils).
• Intent-based redirection for book purchases (redirecting users to Barnes and Noble pages).
Relationships and Data Flows
• The UI layer (activities/fragments) interacts with the ViewModels. The ViewModels handle business logic and call upon repository/service classes to fetch or update data.
• The service classes (NYTService, GoogleApi, OSMService) interact with their respective external APIs.
• Data models serve as the intermediary between these network calls and the ViewModels, ensuring structured data is passed along.
• Dependency injection modules ensure that services, repositories, and ViewModels are properly instantiated and available where needed.
• For authentication and user-specific data, Firebase serves as the backend – accessed via the relevant services that interact with Firestore and Auth APIs.
• Navigation between various screens is orchestrated using the navigation graph in the res/navigation folder.
Architectural Patterns and Design Principles
• MVVM (Model-View-ViewModel): Evident from the structure, where Activities/Fragments (View) communicate with ViewModels, which in turn use models and services to interact with the backend.
• Separation of Concerns: Different responsibilities (UI, data handling, network operations) are clearly separated into distinct packages.
• Dependency Injection: Simplifies testing and enables easier management of component dependencies.
• External API Integration: The separation of services (for NYT, Google Books, and OpenStreetMap) isolates external dependencies, making them replaceable or mockable during testing.