write-viewmodel

Writes ViewModels for the Alkaa Kotlin Multiplatform project following sealed state and flow patterns.

1.6k|163|Updated Jan 10, 2018
One-click install
npx skills add https://github.com/igorescodro/alkaa --skill write-viewmodel
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: write-viewmodel
Source: https://github.com/igorescodro/alkaa/tree/main/.claude/skills/write-viewmodel
Command: npx skills add https://github.com/igorescodro/alkaa --skill write-viewmodel

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Writing ViewModels in the Alkaa project requires strict adherence to architectural conventions: sealed state classes, cold Flow exposure, use case injection, correct coroutine scope selection, and dedicated mappers. This Skill encodes those rules so generated or modified ViewModels match the project's established patterns without manual review of existing code.

Core Features & Use Cases

  • Sealed State Class Guidance: Enforces data object for stateless states, data class for data-carrying states, and ImmutableList for list payloads.
  • Flow and Scope Rules: Prescribes cold Flow<ViewState> by default, StateFlow only for shared streams, applicationScope for DB mutations, and viewModelScope for UI-bound work.
  • Common Mistake Prevention: Flags anti-patterns like calling repositories directly, inline mapping, ViewModel-to-ViewModel dependencies, and mock-based tests.
  • Use Case: When asked to "create a ViewModel for the task detail screen", the Skill produces a ViewModel with injected use cases, a dedicated mapper, a sealed TaskDetailViewState, and matching fake-based unit tests.

Quick Start

Ask the AI to create a ViewModel for a new screen in the Alkaa project, for example by saying "add a ViewModel for the settings screen that loads the current theme".

Frequently Asked Questions about write-viewmodel

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a ViewModel in the Alkaa project?

Create a sealed ViewState class, inject use cases and a mapper as constructor parameters, and expose state as a cold Flow<ViewState>. Use applicationScope for database mutations and viewModelScope for UI-bound work, following the patterns in references/CODE_PATTERNS.md.

Should a Kotlin ViewModel expose StateFlow or cold Flow?

In Alkaa, expose a cold Flow<ViewState> by default. Use a hot StateFlow only when multiple collectors share the same stream or the flow can be modified from multiple places.

Can a ViewModel call a repository directly in Clean Architecture?

No. In this project ViewModels must inject use cases, never repositories or other ViewModels. If shared logic is needed between ViewModels, extract it into a use case first.

Which coroutine scope should I use for database writes in a ViewModel?

Use applicationScope.launch for database inserts, updates, deletes, and network calls that must persist, since it survives ViewModel destruction. Reserve viewModelScope for debounced UI updates and short-lived UI-bound work.

How do I unit test a ViewModel without mocks?

Write a fake class implementing the use case interface, use runTest with Flow.first() for single-value assertions, and pass AppCoroutineScope with a test dispatcher. Cover every reachable state branch: Loading, Empty, Loaded, and Error.