Skip to content

Domain Layer & Use Case Implementation - #31

Merged
AlexisTercero55 merged 12 commits into
devfrom
27-plan-domain-layer-use-case-implementation
Aug 7, 2026
Merged

Domain Layer & Use Case Implementation#31
AlexisTercero55 merged 12 commits into
devfrom
27-plan-domain-layer-use-case-implementation

Conversation

@AlexisTercero55

@AlexisTercero55 AlexisTercero55 commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Development iteration: Architectural Evolution & Domain Integrity

This iteration represents the transition of Rho Studio UI from a feature-modularized prototype to a structured Clean Architecture system. We have successfully decoupled business logic from the Android Framework, implemented a reactive unidirectional data flow (UDF), and established a strict hierarchical module boundary system.

ezgif-140322f142fcc0a1

Advanced Multi-Module Topology #28

We have moved away from a monolithic :app structure to a Feature-Layered Modularization strategy. This optimizes build parallelization and enforces strict dependency inversion.

  • Feature Isolation: :features:auth and :features:home are now independent Android Libraries. They depend only on :core modules (:data,:domain,:ui), preventing circular dependencies and ensuring that changes in one feature cannot break another.
  • Encapsulation of UI Models: The ServiceModule data class was migrated from :core:ui to :features:home:model. This adheres to the Interface Segregation Principle, ensuring that core modules remain generic and do not carry feature-specific payloads.

Domain Layer & Interactor Pattern #29

The implementation of the :core:domain module introduces a platform-agnostic layer that houses the application's "truth."

  • BaseUseCase<P, R>: A standardized abstraction for business logic execution. It leverages Kotlin Coroutines to enforce suspend execution and provides a unified contract for error handling and execution state.
  • Use Case Implementation:
    • LoginUseCase: Encapsulates the authentication transaction. It validates Credentials (Domain Entity) before interacting with the data layer, ensuring business rules are met before network/disk I/O.
    • LogoutUseCase: Orchestrates an atomic session teardown. It coordinates the clearing of tokens in SessionManager and triggers global state resets.
  • Domain Entities: Entities like User and Credentials are now pure Kotlin data classes, preventing "leakage" of framework-specific logic (like Parcelable or Room annotations) into the business layer.

Reactive UI & Orchestration #30

The UI layer has been refined to use Jetpack Compose with a reactive state-push model, eliminating the manual synchronization bugs inherent in View-based systems.

  • StateFlow & Lifecycle Awareness: All ViewModels now expose state via StateFlow. UI components consume this state using collectAsState(), ensuring that recompositions only occur when the specific backing data changes.
  • Side-Effect Orchestration: In   MainActivity, we use LaunchedEffect keyed to isAuthenticated state. This transforms a state change into a one-time navigation event, preventing "multiple-navigation" bugs and ensuring that the NavHost is always in sync with the SessionManager.

Current State: Manual Dependency Management

While the architecture has been modularized, the project currently utilizes Manual Dependency Management.

  • Service Locators & Singletons: Components like SessionManager are managed as singletons.
  • Manual Instantiation: ViewModels currently instantiate their own dependencies (e.g., LogoutUseCase(SessionManager.getInstance())).
  • Roadmap: This sets the stage for the next phase: migrating to a formal DI (Dagger) to further decouple the ViewModel from its implementation details.

Infrastructure & Verification

  • CI/CD Pipeline: Implementation of .github/workflows/android.yml ensures that every commit is verified against a debug build and unit test suite.

  • Static Analysis: All source files have been standardized with ASCII branding and metadata headers, and code style is enforced through automated linting to maintain high maintainability standards.


Rho.Studio® - Engineering Department - Contact alexis.tercero@rho.studio

### MainActivity Refactor: StateFlow Migration
- Switched state observation from LiveData to StateFlow using collectAsState().
- Implemented lifecycleScope for error flow collection and onDestroy cleanup.
- Refined authentication-driven navigation logic within LaunchedEffect.

### `core:data` Refactor: SessionManager & SessionRepository
- SessionManager: Migrated LiveData to StateFlow; added @volatile thread-safety, CoroutineScope for async persistence, and lifecycle init/cleanup methods.
- SessionRepository: Extracted persistence into an interface with a SharedPreferences implementation (SessionRepositoryImpl) to decouple storage from the manager.
- Replace live data state with StateFlow.
- Update some build files.
- AuthRepository - define login operation.
- AuthRepositoryImpl - Mock implementation for development purposes.
- Credentials.kt - user's authentication data
- User.kt - user's info.
- Result.kt - standardized  status holder.
- standardized execution pattern for domain transactions
- LoginUseCase : : BaseUseCase<Credentials, User>()
- LoginUseCaseTest.
- LoginViewModel migration_2 to StateFlow
features:auth

- Compose login screen.
- Compose login inputs fields.
- Compose action login button.
features:auth

- Setup Gradle modules.
- Mising login button move.
:core:domain
:features:home
:core:ui
@AlexisTercero55 AlexisTercero55 added this to the Domain Layer milestone Aug 7, 2026
@AlexisTercero55 AlexisTercero55 self-assigned this Aug 7, 2026
@AlexisTercero55 AlexisTercero55 added Auth-feature UI compose feature - LoginViewModel Home-feature Compose Home screen. labels Aug 7, 2026
@AlexisTercero55 AlexisTercero55 added Core Rho Studio UI app codebase Compose UI UI Jetpack compose development first Domain layer Use cases of business flow Module Gradlew multi-module project migration_2 LiveData to StateFlow labels Aug 7, 2026
@AlexisTercero55 AlexisTercero55 moved this from Backlog to Ready in UI-Rho-Studio-Components Aug 7, 2026
@AlexisTercero55 AlexisTercero55 moved this from Ready to In progress in UI-Rho-Studio-Components Aug 7, 2026

@alexistercero-rho-dev alexistercero-rho-dev left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CODE REVIEW & CI/CD

Ready for application test: install and run on Samsung Galaxy A34 5G.

sha256:cd054915e6969a9847276117c36bfa91c550dff15ae225b164c9df06d600144d

Rho.Studio® - Engineering Department - Contact alexis.tercero@rho.studio

@AlexisTercero55
AlexisTercero55 merged commit 0008568 into dev Aug 7, 2026
2 checks passed
@github-project-automation github-project-automation Bot moved this from In progress to Done in UI-Rho-Studio-Components Aug 7, 2026
@alexistercero-rho-dev
alexistercero-rho-dev deleted the 27-plan-domain-layer-use-case-implementation branch August 7, 2026 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Auth-feature UI compose feature - LoginViewModel Compose UI UI Jetpack compose development first Core Rho Studio UI app codebase Domain layer Use cases of business flow Home-feature Compose Home screen. migration_2 LiveData to StateFlow Module Gradlew multi-module project

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

MIGRATION - LiveData to StateFlow Domain Layer - use cases - business rules setup Modularization - Multi-module project

2 participants