PickMe Dec 23, 2025

The ViewModel Manager Pattern: How We Tamed a 2000+ Line ViewModel Into Clean, Testable Code

M6 Related OWASP risk: Inadequate Privacy Controls Learn more →

Article Summary

Chamod Lakmal from PickMe Engineering turned a 2,100-line ViewModel nightmare into 350 lines of clean, testable code. His team's test coverage jumped from 12% to 87%, and onboarding time dropped from 2 weeks to 2 days.

PickMe's checkout feature had become unmaintainable: a single ViewModel with 18 dependencies, 50+ StateFlows, and 2,000+ lines of tangled business logic. The team introduced the ViewModel Manager Pattern, extracting domain-specific logic into focused, injectable classes that share the ViewModel's lifecycle while maintaining clear separation of concerns.

Key Takeaways

Critical Insight

The ViewModel Manager Pattern uses composition to extract domain logic into ViewModelScoped classes, transforming massive ViewModels into clean coordinators that are 86% easier to test and dramatically faster to understand.

The article includes complete code examples showing how to build your first Manager step-by-step, plus a practical migration strategy for refactoring existing monster ViewModels without a risky big-bang rewrite.

About This Article

Problem

PickMe's checkout ViewModel grew to over 2,000 lines with 18 dependencies and 50+ StateFlows scattered throughout. Testing became nearly impossible with only 12% coverage, and the team dealt with constant merge conflicts.

Solution

Chamod Lakmal split the code using the ViewModel Manager Pattern. Six focused classes took shape: ProductManager, CartManager, PaymentManager, OrderManager, ShippingManager, and AnalyticsManager. Each one handles a single responsibility.

Impact

Test setup went from 85 lines down to 12 lines, an 86% reduction. Test coverage jumped to 87%. New developers got up to speed in two days instead of two weeks, and the code became much easier to understand.