- Home
- Skills
- Kaakati
- Rails Enterprise Dev
- Mvvm Architecture
mvvm-architecture_skill
- Shell
6
GitHub Stars
1
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill kaakati/rails-enterprise-dev --skill mvvm-architecture- SKILL.md10.7 KB
Overview
This skill helps iOS/tvOS engineers make expert MVVM decisions: choose a ViewModel pattern, carve service boundaries, pick dependency injection strategies, and design testable ViewModels. It codifies trade-offs and concrete anti-patterns to avoid while guiding implementation templates and testing approaches.
How this skill works
The skill inspects screen requirements (mutually exclusive states vs independent properties), dependency counts, and reuse needs to recommend one of three ViewModel patterns: state enum, published properties, or Combine-based publishers. It also evaluates where logic belongs (ViewModel vs service vs model), suggests DI patterns (default params vs factory/container), and provides testing patterns and mocks for reliable unit tests.
When to use it
- Designing a new screen ViewModel and deciding state representation
- Refactoring a large or brittle ViewModel into smaller, testable units
- Defining service boundaries and protocol-based APIs for network/caching
- Choosing how to inject dependencies into SwiftUI views (@StateObject patterns)
- Creating unit tests and mocks to validate state transitions and error handling
Best practices
- Use State Enum for mutually exclusive lifecycle states (loading → loaded → error)
- Prefer Published properties for multiple independent sections; use Combine for validation chains
- Inject services via protocols with default implementations to keep tests simple
- Avoid loading data in ViewModel init; trigger loads from the View (.task) to enable cancellation
- Mark @Published properties private(set), annotate ViewModels with @MainActor, and handle CancellationError separately
Example use cases
- Product detail screen: choose State Enum to force exhaustive UI handling
- Dashboard with independent panels: use Published properties to avoid combinatorial state
- Form with field validation: use Combine publishers for chained validation
- Feature with many cross-cutting services: use a factory/container to construct ViewModels
- Unit testing: inject MockServiceProtocol and assert state transitions without networking
FAQ
Use a factory or container when a ViewModel needs many dependencies or when construction logic is shared; prefer simple init parameters for one or two dependencies.
Why not start network loads in ViewModel init?
Starting loads in init prevents cancellation tied to view lifecycle and makes retries harder. Trigger loads from the View so SwiftUI can cancel tasks when the view disappears.