Skip to content

Clean Architecture Refactoring: Fix Layer Boundaries & Modularization #72

Description

@buddhasaikia

Problem Statement

ThreadSimulator has good Clean Architecture foundation (70% aligned) but violates key principles:

  • UI layer imports data layer directly (MockDataSource in HomeScreenRoute.kt)
  • ViewModel bypasses domain layer (accesses repository directly for initial data)
  • Business logic in ViewModel (channel management, throttle selection should be in domain)
  • Tight coupling to infrastructure (ViewModel manages 6+ dependencies)
  • Monolithic structure (no feature modules for independent build/test)

Solution: Two-Phase Refactoring

Phase 1: Fix Layer Boundaries (Critical/High)

  • Create GetCompanyListUseCase
  • Create StreamCoordinationService (Domain)
  • Extract channel management from ViewModel
  • Refactor HomeViewModel dependencies (6+ → 3-4)
  • Remove MockDataSource import from UI layer
  • Verify InitCompanyListUseCase exists
  • Update ViewModel to use only use cases
  • Run tests and verify no regressions

Goal: Enforce UI-Domain-Data dependency rules. Outcome: 85-90% alignment.

Phase 2: Modularization (Medium Priority)

  • Create :core:common module
  • Create :core:model module
  • Create :core:di module
  • Create :feature:stockData module
  • Update app module build.gradle
  • Update imports across codebase
  • Verify modular build and tests

Goal: Enable independent feature modules. Outcome: 95%+ alignment.

Validation Checklist

After Phase 1:

  • No imports of com.bs.threadsimulator.data.* in UI layer
  • ViewModel imports only from domain layer
  • ViewModel constructor has 3-4 dependencies max
  • All tests pass: ./gradlew test
  • App builds: ./gradlew assembleDebug

After Phase 2:

  • Each module builds independently
  • No circular dependencies
  • Full app build succeeds: ./gradlew build

Effort

  • Phase 1: 3-5 hours
  • Phase 2: 4-6 hours

Backward Compatible: No breaking changes, public APIs unchanged.

See full plan in session workspace: plan.md

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions