-
Notifications
You must be signed in to change notification settings - Fork 0
Technical Specification: Enterprise-Grade Dagger DI, SSOT Data Layer, & Firebase Integration
This document outlines the implementation strategy for transitioning Rho Studio UI to a production-hardened state. The focus is on Transactional Integrity, Strict Session Isolation, and Scalable Infrastructure tailored for high-stakes fintech environments.
1. Dagger Dependency Injection: Component Dependency & Scoped Orchestration
We will implement a Pure Dagger architecture using Component Dependencies to maintain strict module encapsulation and explicit lifecycle control.
1.1 Multi-Module Component Topology
To preserve the "Clean Architecture" boundaries, we avoid Subcomponents and instead use Component Dependencies.
CoreComponent(in:core:data):- Scope:
@Singleton. - Exposure: Explicitly exposes
AuthRepository,SessionManager, andJsoninfrastructure. - Responsibility: Houses stateless or global-state services.
- Scope:
UserComponent(in:appor:core:data):- Scope:
@UserScope. - Dependency:
CoreComponent. - Lifetime: Created upon successful login; invalidated immediately upon logout.
- Responsibility: Hosts session-sensitive interactors and transient state for flows like Loan Wizards.
- Scope:
FeatureComponents (in:features:*):- Dependency:
CoreComponent(andUserComponentfor authenticated features). - Responsibility: Provides feature-specific ViewModels via multibinding.
- Dependency:
1.2 Scoped Component Management
We will implement a ComponentManager at the :app level to orchestrate the lifecycle of the UserComponent. This ensures that when a user logs out, the entire session-scoped graph is garbage collected, fulfilling fintech requirements for Secure Session Isolation.
1.3 ViewModel Multibinding & Factory
- Implement a
DaggerViewModelFactoryin:core:uithat leverages aMap<Class<? extends ViewModel>, Provider<ViewModel>>. - Use
@IntoMapand@ViewModelKeyin feature modules to decouple the UI from the instantiation of business logic.
2. Data Layer: SSOT & Secure Transactional Integrity
Refining the Data Layer to ensure a Single Source of Truth (SSOT) and secure persistence.
2.1 SessionManager & Repository Refactoring (Architectural Split)
- Repository Abstraction: Refactor
SessionRepositoryto follow Clean Architecture by splitting it into its respective modules::core:domain: Houses theSessionRepositoryinterface.:core:data: Houses theSessionRepositoryImplimplementation.
- DI Integration: Remove Singleton boilerplate from
SessionManager. It becomes a standard injectable class managed by Dagger. - Reactive State Flow: Transition to a sealed-class-based state (
SessionState.Uninitialized,Authenticated(User), etc.) to prevent invalid state transitions. - Transactional Integrity: Ensure that
updateSession()andclearSession()are atomic operations, coordinating theStateFlowupdate with theDataStorewrite.
2.2 Secure Persistence with Encrypted DataStore
- Replace
SharedPreferenceswith Jetpack DataStore (Proto or Preferences). - Implement Tink-based encryption (via
EncryptedSharedPreferencesor a customSecurityDataStore) to protect session tokens and PII (Personally Identifiable Information) on disk.
3. Firebase Authentication: Robust Integration & SDK Decoupling
Integrating Firebase while maintaining a generic, testable domain.
3.1 Remote Data Source Abstraction
FirebaseRemoteDataSource: A wrapper around the Firebase SDK. This class will be the only point of contact with Firebase, allowing us to swap it with aFakefor unit tests without hitting the real SDK.- Error Mapping: Implement a
FirebaseErrorMapperto transform SDK exceptions into domain-levelAppFailuretypes (e.g.,InvalidCredentials,AccountLocked).
3.2 AuthRepository Implementation
- Coordinates between
FirebaseRemoteDataSourceandSessionManager. - Implements an "Offline-First" awareness: ensuring the local session is updated only after successful remote verification.
4. Performance & Scalability Strategy
As the volume of UseCases and business logic grows, we mitigate overhead:
dagger.Lazy<T>&dagger.Provider<T>: Extensively used in ViewModels to defer UseCase instantiation until the exact moment of execution.- Compile-Time Graph Validation: Dagger's static analysis ensures that all dependency requirements are satisfied at build time, eliminating runtime DI crashes.
- Leak Detection: Use of
LeakCanaryduring verification to ensureUserComponentand its dependencies are properly reclaimed post-logout.
5. Incremental Development Roadmap
To ensure stability and maintain transactional integrity, the implementation will be executed in the following incremental phases:
Phase 1: Environment & Core DI Infrastructure
- Dependency Injection & Firebase Setup: Update
libs.versions.tomlwith Dagger 2, Firebase BOM, and DataStore dependencies. Apply plugins and dependencies to all modulebuild.gradle.ktsfiles. - Annotation Definition: Create
@UserScopeand@ViewModelKeyin:core:domainor:core:ui. - Core Data Module: Create
CoreModuleandCoreComponentin:core:datato provideJsonand basic infrastructure. - ViewModel Factory: Implement
DaggerViewModelFactoryin:core:ui.
Phase 2: Data Layer Refactoring (SSOT)
- Architectural Repository Split: Relocate the
SessionRepositoryinterface to:core:domainand keepSessionRepositoryImplin:core:data. - Injectable SessionManager: Refactor
SessionManager.ktto remove the singleton pattern and support constructor injection. - Secure Persistence: Implement
EncryptedDataStorelogic in:core:datato replaceSharedPreferences. - Repository Implementation: Update
SessionRepositoryImplandAuthRepositoryImplto use constructor injection and the newDataStore.
Phase 3: Feature & App Layer Integration
- Feature Multibinding: Annotate
LoginViewModelandHomeViewModelwith@Injectand register them in their respective Dagger modules using@IntoMap. - UserComponent Orchestration: Implement the
ComponentManagerin:appto manage the lifecycle of the@UserScopegraph. - Application & Activity Wiring: Initialize the Dagger graph in
RhoApplication.ktand trigger injection inMainActivity.kt.
Phase 4: Firebase Integration & Final Polish
- Remote Data Source: Implement
FirebaseRemoteDataSourcewrapper. - Production Repository: Switch
AuthRepositoryImplfrom mock logic to real Firebase authentication. - Final Audit: Execute memory profiling and encryption verification.
6. Verification & Audit Plan
6.1 Automated Testing
- DI Graph Audit: Build-time verification of the complete Dagger graph.
- Transactional Logic: Unit tests for
SessionManagerto verify atomic state transitions during edge cases (e.g., failed logout). - Domain Logic: 90%+ coverage for UseCases using Dagger-provided mocks.
6.2 Manual Verification & Compliance
- Session Purge Audit: Verify memory reclamation of
@UserScopeobjects using Memory Profiler. - Encryption Audit: Inspect
DataStorefiles on a rooted device (or via App Inspection) to confirm PII encryption. - Fintech UX Verification: Verify the "Secure Logout" flow ensures no PII is visible in the UI after a session termination.
Rho.Studio® - Engineering Department - Contact alexis.tercero@rho.studio
List view
0 of 0 selected 0 issues of 0 selected
There are no open issues in this milestone
Add issues to milestones to help organize your work for a particular release or project. Find and add issues with no milestones in this repo.