Driver FixRecommendedSound, Wi-Fi or graphics acting up? Check drivers firstFind missing or outdated drivers fast.Check DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk4 min

MVVM and Clean Architecture: Where Your Code Belongs

MVVM organizes presentation; Clean Architecture governs dependency direction. Here’s where UI commands, business rules, use cases, and infrastructure belong.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

MVVM and Clean Architecture answer different questions. MVVM organizes the UI and its presentation logic; Clean Architecture sets the direction dependencies may point. A button command usually belongs in a view model, a business invariant in the domain core, and a database implementation in infrastructure. You can use both patterns together without adopting one mandatory folder or project layout.

What each pattern is responsible for

MVVM organizes a screen

Microsoft describes MVVM as a UI architectural pattern that decouples UI and non-UI code. The view presents controls and binds to a view model; the view model exposes screen state and interactions; the model represents application data or behavior. The view model may adapt model data for display, but it is not automatically the domain model. Microsoft Learn explains these roles in its Model-View-ViewModel (MVVM) and Windows data binding and MVVM guidance.

As an Amazon Associate I earn from qualifying purchases.

Clean Architecture organizes dependencies

Clean Architecture is about keeping business and application rules at the core while implementation details—such as databases, frameworks, and external services—depend inward on core abstractions. The central rule is dependency direction, not a required number of layers, projects, repositories, or interfaces. See Microsoft’s Common web application architectures and DDD-oriented microservice design.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Where each kind of code belongs

Responsibility Typical home Why
Layout, controls, accessibility presentation View / UI Describes what is rendered; should not own business rules.
Screen state, binding properties, presentation commands ViewModel Supplies binding targets and coordinates user-facing interactions.
Business invariants and domain behavior Domain / application core Should not depend on UI or infrastructure technology.
A user-goal operation such as “submit order” Application use case or service Coordinates the operation and delegates business rules to the domain.
Database, HTTP client, file-system implementation Infrastructure Implements the data-access or service abstractions used inward by the core.
Binding conversions and visual-only behavior Presentation edge, often view or converter Keeps display adaptation near the UI unless it represents reusable domain meaning.

These are useful defaults, not laws. Put code where its reason to change and required dependencies make sense.

Trace a button press through both patterns

  1. The view renders the button. Its markup or UI code defines appearance, accessibility labels, and binding to an action; it should not decide whether the action is valid under business rules.
  2. The view model exposes the command. A command such as SubmitOrderCommand is presentation behavior: it may manage a busy indicator, validation messages, or navigation state.
  3. The application use case coordinates the goal. The view model invokes an application-facing abstraction, for example an order-submission service, rather than constructing a database context.
  4. The domain enforces invariants. Rules such as whether an order can be submitted belong with the business model, not in the button handler.
  5. Infrastructure performs external work. A database adapter or HTTP client implements the abstraction the core depends on and handles the technology-specific operation.

In this arrangement, MVVM shapes the presentation edge while Clean Architecture protects inward dependency direction. Microsoft’s WinUI 3 architecture guidance likewise says layers should depend in one direction and view models should not reference UI types.

How the patterns differ

Question MVVM Clean Architecture
What it organizes The relationship between view, view model, and model. Dependency direction between core policy and outer implementation details.
Main boundary View ↔ ViewModel ↔ Model. Application core ↔ infrastructure and other outer layers.
Useful test seam Test view-model behavior without rendering the view. Test core rules without relying on infrastructure implementations.
Cost to watch Binding and view-model ceremony that may not help a small screen. Layers, interfaces, or project splits added without protecting a meaningful dependency.

When to add structure—and when not to

MVVM is useful when the UI has meaningful state or complexity

Consider it when screens have substantial data flow, multiple screens share behavior, UI and non-UI code are becoming coupled, or view-model behavior needs independent tests. Microsoft identifies testing view models without the view, redesigning UI without changing view-model or model code, and parallel designer/developer work as benefits. For a simple single-page tool or prototype, code-behind can be reasonable; add the pattern as complexity creates a need rather than treating it as an entry requirement.

Clean Architecture is useful when core rules need insulation

Keep the core independent when business behavior should survive a change of database, framework, or delivery mechanism. Start with the dependency boundaries that solve actual coupling. Separate projects or additional interfaces are worthwhile when they protect those boundaries; they are not a scorecard for architectural quality.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Neither pattern requires the other. Some small applications do not need a separate model layer, and MVVM does not by itself guarantee that domain rules are isolated from infrastructure. Microsoft notes that advanced MVVM techniques have scale-dependent costs in its Windows data binding and MVVM guidance.

Warning signs that code is in the wrong place

  • A view or code-behind contains business decisions that must also hold for other screens or non-UI callers.
  • A view model imports UI control types or directly creates a concrete database context.
  • A domain rule requires a UI framework or database library merely to compile.
  • A use case contains all business logic instead of coordinating the domain behavior.
  • Interfaces, projects, or layers exist without isolating a dependency that matters.
Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Further reading

For a book-length treatment of Clean Architecture in .NET, the Microsoft Press Store lists Dino Esposito’s Clean Architecture with .NET, first edition, published 12 March 2024, ISBN 9780138203283. Its stated scope spans presentation, application, domain, and infrastructure layers; it is relevant to Clean Architecture rather than established here as a direct MVVM tutorial. See the Microsoft Press Store listing.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Outdated Drivers Are Slowing You DownFree scan - exact matches
Windows Errors? Fix Them Before They SpreadFree repair scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.