Skills DirectorySkills Directory
SkillsLearnSecurityCategoriesDocsCommunityBlog
Sign InSubmit Skill
Skills Directory

Security-tested agent skills for Claude, coding agents, and AI workflows.

Directory

  • Browse Skills
  • All Skills A–Z
  • Claude Skills
  • Claude Code Skills
  • Agent Skills
  • Categories
  • Submit a Skill

Learn

  • Learn Hub
  • Install Claude Skills
  • Write SKILL.md
  • Skills vs MCP
  • Directories Compared

Security

  • Security
  • Methodology
  • Secure Claude Skills
  • Security Badges

Company

  • About
  • Community
  • Blog
  • API Docs
  • Advertise

2026 Skills Directory. All rights reserved.

Back to skills

Mvvm Pattern

ASecurity

Separate UI from business logic using Model (data), View (UI markup), and ViewModel (presentation logic with data binding) for testable, reactive applications

22 stars
0 votes
0 copies
0 views
Added 9/20/2026
developmentjavascriptgojavaswiftc#reactvueangularexpresstesting

Works with

cliapi

Security Analysis

A100/100

Scanned 9/20/2026

Install to Claude Code

$npx -y skills add lev-os/agents --skill mvvm-pattern --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Mvvm Pattern?

Add the live security badge to your README — it updates automatically with every re-scan.

Security grade badge for Mvvm Pattern
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/lev-os-mvvm-pattern/badge)](https://www.skillsdirectory.com/skills/lev-os-mvvm-pattern)

More formats (shields.io, HTML) on the badges page.

Download Zip
Files
SKILL.md
---
name: mvvm-pattern
description: Separate UI from business logic using Model (data), View (UI markup), and ViewModel (presentation logic with data binding) for testable, reactive applications
---

# Model-View-ViewModel (MVVM)

## Overview

Model-View-ViewModel is an architectural pattern designed for modern UI frameworks with data binding capabilities, enabling automatic synchronization between UI and application state. Introduced by John Gossman (Microsoft WPF/Silverlight architect) in 2005, MVVM evolved from MVC to leverage declarative data binding in frameworks like WPF, Angular, Vue, SwiftUI, and Jetpack Compose. The pattern eliminates most "glue code" that manually updates UI when data changes.

The three components are: Model (business logic and data sources), View (UI markup with binding expressions), and ViewModel (presentation logic that exposes bindable properties and commands). The key differentiator from MVC is the ViewModel - a "value converter" that shapes Model data for View consumption and handles View logic without knowing View implementation details. Two-way data binding keeps View and ViewModel synchronized automatically, enabling reactive UIs where changes propagate instantly.

## When to Use

- Frameworks with robust data binding (WPF, Xamarin, Angular, Vue, SwiftUI, Jetpack Compose)
- Applications with complex UI state requiring synchronization across multiple components
- Teams needing high testability - ViewModel can be unit tested without UI
- "Massive View Controller" problems where presentation logic bloats UI code
- Desktop/mobile apps with frequent UI changes but stable business logic
- Real-time dashboards where data updates must reflect instantly in UI
- Cross-platform development sharing ViewModels across iOS/Android
- Separating UI designers (working in markup) from developers (writing ViewModels)

## The Process

### Step 1: Define the Model - Business Logic Layer

The Model represents domain entities, data access, and business rules. Identical to MVC - no UI dependencies.

**Ask:** "What are the core business entities? Where does data come from (API, database, cache)?"

**Implementation:** Create domain classes with business logic. Models expose data but don't know about ViewModels or Views. Use repositories/services for data access.

**Example:** `UserModel` with `getUserProfile(id)`, `validateEmail(email)`, `updatePassword(old, new)`. Returns domain objects. No UI-specific formatting.

### Step 2: Create the ViewModel - Presentation Logic

ViewModel exposes data and operations the View needs, converting Model data to View-friendly formats. Contains presentation logic, validation, and commands.

**Ask:** "What data does the View need to display? What actions can users perform? How should Model data be formatted?"

**Implementation:** Expose observable properties (React state, Vue reactive, SwiftUI @Published). Implement commands/methods for user actions. Transform Model data for display.

**Example:** `UserProfileViewModel` exposes `fullName` (computed from firstName + lastName), `isEmailValid` (bool for validation state), `saveProfileCommand` (triggered by Save button). Updates when Model changes.

### Step 3: Build the View - UI Markup with Data Binding

View is declarative markup (XAML, HTML, SwiftUI) that binds to ViewModel properties. Contains no logic - only bindings and layout.

**Ask:** "How should ViewModel data be rendered? What UI controls map to ViewModel properties and commands?"

**Implementation:** Use binding syntax to connect UI elements to ViewModel. Text inputs bind to properties, buttons bind to commands. Framework handles synchronization.

**Example:** `<input v-model="fullName" />` binds to ViewModel `fullName` property. `<button @click="saveProfileCommand">Save</button>` triggers ViewModel method. No JavaScript/Swift code in View - pure markup.

### Step 4: Establish Two-Way Data Binding

Configure automatic synchronization between View and ViewModel using framework binding mechanisms.

**Flow:** User types in input → Framework updates ViewModel property → ViewModel validates/transforms → ViewModel notifies observers → View updates automatically.

**Implementation:** Mark ViewModel properties as observable (INotifyPropertyChanged in C#, @Published in Swift, Vue reactive, React useState). Framework propagates changes bidirectionally.

**Example:** User edits email field → ViewModel `email` property updates → ViewModel runs validation → `isEmailValid` changes → Save button enable/disable state updates automatically.

### Step 5: Implement Commands for User Actions

ViewModel exposes commands (methods) that View invokes for user interactions. Commands encapsulate "what happens when user clicks this."

**Ask:** "What actions can users perform? What business logic should execute?"

**Implementation:** Create command objects or methods that update Model, perform async operations, handle errors. View binds buttons/gestures to commands.

**Example:** `saveProfileCommand` validates inputs, calls `UserModel.updateProfile()`, handles success/error, updates UI state (loading spinner, success message). View just binds button - no code.

### Step 6: Maintain Separation and Testability

ViewModel should have zero View dependencies - no imports of UI frameworks (UIKit, SwiftUI, Android views).

**Validation:** Can you unit test ViewModel without rendering UI? Can you swap View implementations (web → mobile) without changing ViewModel?

**Testing:** Mock Models, instantiate ViewModel, call commands, assert observable properties changed correctly. No UI automation needed.

## Example Application

**Situation:** Social media iOS app with "Massive View Controller" problem - 2000-line view controllers mixing networking, business logic, and UI updates. Difficult to test, frequent bugs in UI state management.

**Application of MVVM:**
- **Model:** `PostRepository` fetches posts from API, caches locally. `Post` entities with like/comment logic. `UserRepository` manages authentication.
- **ViewModel:** `FeedViewModel` exposes `@Published var posts: [PostViewModel]`, `isLoading: Bool`, `refreshCommand`. Each `PostViewModel` has `likePostCommand`, `shareCommand`. Transforms API data to display format (relative timestamps, formatted counts).
- **View:** SwiftUI `FeedView` with `ForEach(viewModel.posts)` binding. `PostView` binds to `PostViewModel` properties. Buttons use `.onTapGesture { viewModel.likePostCommand() }`. Pure declarative UI.

**Outcome:** ViewModel unit tests cover 100% of presentation logic (mock repositories). View reduced to 150 lines of SwiftUI markup. Reused ViewModels for iPad version with different layouts. Bug rate decreased 60% - state synchronization automatic.

## Anti-Patterns

- ViewModel importing View frameworks (UIKit, SwiftUI) - breaks testability and separation
- Business logic in ViewModel instead of Model - ViewModel should orchestrate, not implement
- View directly accessing Model - bypassing ViewModel breaks separation of concerns
- Over-relying on two-way binding for complex state - can create debugging nightmares
- Treating MVVM as silver bullet when MVC suffices - data binding overhead for simple UIs
- "Massive ViewModel" replacing "Massive View Controller" - need to decompose ViewModels too
- Using MVVM in frameworks without data binding - defeats the purpose, use MVC instead
- Tight coupling between specific View and ViewModel - should be reusable across Views

## Related

- mvc-pattern (predecessor pattern without data binding)
- observer-pattern (mechanism for property change notifications)
- data-binding (core enabling technology)
- reactive-programming (RxSwift, Combine, RxJS for advanced MVVM)
- clean-architecture (system-level architecture complementing MVVM)
- presentation-model (Martin Fowler pattern similar to ViewModel)
- unidirectional-data-flow (alternative to two-way binding)

Attribution

lev-oslev-os
View sourceMore from lev-os →
SSkills DirectorySkills Directory

Your tool, in front of Claude Code builders.

3 founder slots · $299/mo · GSC-verified traffic · sponsors can never buy grades.

See placements

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments (0)

No comments yet. Be the first to comment!

SSkills DirectorySkills Directory

Your tool, in front of Claude Code builders.

3 founder slots · $299/mo · GSC-verified traffic · sponsors can never buy grades.

See placements

Related Skills

Browser Extension Developer

Use this skill when developing or maintaining browser extension code in the `browser/` directory, including Chrome/Firefox/Edge compatibility, content scripts, background scripts, or i18n updates.

281612 votes

Seo Optimizer

SEO optimization with keyword analysis, readability assessment, technical validation, content quality. Use for search rankings, blog posts, content audits, or encountering keyword density, readability scores, meta tags, schema markup errors.

2132 votes

Google Official Seo Guide

Official Google SEO guide covering search optimization, best practices, Search Console, crawling, indexing, and improving website search visibility based on official Google documentation

1862 votes

Tanstack Start

Build a full-stack TanStack Start app on Cloudflare Workers from scratch — SSR, file-based routing, server functions, D1+Drizzle, better-auth, Tailwind v4+shadcn/ui. Use whenever the user mentions TanStack Start, asks to scaffold a full-stack Cloudflare app with SSR, wants an SSR dashboard, or asks for a React 19 + Cloudflare Workers app with file-based routing and server functions — even if they don't name TanStack Start specifically. No template repo — Claude generates every file fresh per ...

9881 votes

Pentest

PTES-aligned adversarial security audit for backend, frontend, and mobile applications. Produces a CVSS-scored Hacker Report with verified PoCs and phased remediation.

5491 votes
View all in development →