MVVM Architecture Enforcer
This skill enforces the MTM Receiving Application architecture rules.
When to Use This Skill
Use this skill when you are asked to:
- •Create or modify a ViewModel, Service, or DAO
- •Review code for architecture violations
- •Update XAML bindings
- •Add or refactor database access logic
Architecture Rules (Must Follow)
Forbidden
- •ViewModels calling DAOs directly (must go through Services)
- •ViewModels accessing
Helper_Database_*classes - •Static DAO classes
- •DAOs throwing exceptions
- •MySQL raw SQL in C# (stored procedures only)
- •SQL Server / Infor Visual write operations (read-only)
- •Runtime
{Binding}in XAML (use{x:Bind}only) - •Business logic in
.xaml.cscode-behind
Required
- •Layer flow: View (XAML) → ViewModel → Service → DAO → Database
- •ViewModels are
partialand inherit fromViewModel_Shared_Base - •Services are interface-based (
IService_*) and injected - •DAOs are instance-based, injected, and return
Model_Dao_Result - •XAML uses
{x:Bind}with explicitMode
Quick Validation Checklist
- • ViewModel is
partial - • ViewModel inherits from
ViewModel_Shared_Base - • ViewModel calls only Services, not DAOs or
Helper_Database_* - • Service interface exists and is registered in DI
- • DAO is instance-based, returns
Model_Dao_Result, and does not throw - • XAML uses
{x:Bind}(not{Binding})
How to Run the Validator
Basic Usage (from repo root)
powershell
.\.github\skills\mvvm-architecture-enforcer\scripts\validate-mvvm.ps1
Advanced Options
powershell
# Scan a specific directory .\.github\skills\mvvm-architecture-enforcer\scripts\validate-mvvm.ps1 -Path "Module_Dunnage" # Get structured output (for automation) .\.github\skills\mvvm-architecture-enforcer\scripts\validate-mvvm.ps1 -PassThru # Enable verbose logging .\.github\skills\mvvm-architecture-enforcer\scripts\validate-mvvm.ps1 -Verbose
Understanding the Output
No violations:
code
No MVVM violations found.
With violations:
code
WARNING: Found 2 MVVM violation(s).
Module_Dunnage\ViewModels\ViewModel_Example.cs: ViewModel references Dao_* directly (forbidden)
Module_Dunnage\Views\View_Example.xaml: XAML uses {Binding} outside allowed collection control context (forbidden; use {x:Bind})
Violation types:
- •
ViewModel references Dao_* directly (forbidden)- ViewModel is calling a DAO instead of a Service - •
ViewModel references Helper_Database_* (forbidden)- ViewModel is using database helpers directly - •
ViewModel is missing 'partial class'- ViewModel class is not declared as partial - •
XAML uses {Binding} outside allowed collection control context- XAML is using runtime binding where compiled binding should be used
Allowed exceptions for {Binding}:
- •Inside DataGrid columns and templates
- •Inside ItemsControl, ItemsRepeater, ListView, GridView templates
- •ElementName bindings (e.g.,
{Binding ElementName=Root, Path=...}) - •RelativeSource bindings (e.g.,
{Binding RelativeSource={RelativeSource Self}})
Resource Links
- •Validator script: validate-mvvm.ps1
- •Detailed rules: architecture-rules.md
- •Fix examples: common-violations.md
- •ViewModel scaffold: viewmodel-template.cs
- •Service scaffold: service-template.cs
Workflow: Audit MVVM violations
- •Identify the target files (ViewModel
.csand XAML.xaml). - •Run validate-mvvm.ps1 over the repo or module.
- •Summarize violations by file.
- •Propose fixes that preserve the required layer flow.
- •Apply fixes with minimal changes.
- •Re-run the validation script.
Workflow: Create a new ViewModel (repo-standard)
- •Start from viewmodel-template.cs.
- •Ensure the class is
partialand inherits fromViewModel_Shared_Base. - •Inject Services (never DAOs) into the constructor.
- •Use
[ObservableProperty]for bindable state. - •Use
[RelayCommand]for UI actions. - •Ensure async commands end with
Async. - •Ensure corresponding XAML uses
{x:Bind}with explicitMode.
Workflow: Fix XAML binding violations
- •Search for
{Binding ...}. - •Convert to
{x:Bind ...}. - •Add explicit
Mode(OneWay/TwoWay/OneTime). - •For TwoWay text entry, set
UpdateSourceTrigger=PropertyChangedwhen appropriate.