Mvvm architecture

From LedgerHQ/ledger-live · View interactive version

Mvvm architecture is an AI agent skill from the GitHub repository LedgerHQ/ledger-live. The Container, ViewModel, View convention of app composition code under apps/*/src/mvvm/** and of every features/flow package. Read when creating, editing or reviewing files in apps/*/src/mvvm/**, or view model and view files in features/flow/** (use*ViewModel.ts, *View.web.tsx, *View.native.tsx). D

How to use this skill

Skill file

MVVM Architecture

Scope

apps/<app>/src/mvvm/ holds two kinds of code:

the adapters that connect a feature package to app internals.

src/mvvm is not the default home of new code. Decide placement with

structure-flow first: business-aware UI and journeys go to

features/, data access to domain/, generic code to shared/. The app folder keeps only what

composes them.

Example: desktop src/mvvm/features/Contacts/ renders @features/flow-contacts and passes it

app-side adapters (useContactsCurrencySelectionAdapter, useContactsAddressValidationAdapter).

The contacts journey itself lives in the flow package.

The ViewModel pattern is not apps-only: it is also mandatory in every

features/flow package. The folder structure below is apps-only; the anatomy of a flow package

belongs to the CODE0 skill.

Folder Structure

Applies to apps/*/src/mvvm/ only.

src/mvvm/
├── features/
│   └── FeatureName/
│       ├── __integrations__/    ← mandatory integration tests
│       ├── components/          ← UI reused across this feature's screens
│       ├── screens/             ← individual screen folders
│       ├── hooks/               ← feature-scoped hooks, adapters to app internals
│       └── utils/               ← feature-scoped utilities
├── components/                  ← UI shared by several app features
├── hooks/
└── utils/

Place each element in the closest folder matching its reuse scope: screen-specific building blocks

stay in the screen folder, feature-level ones in FeatureName/components/, app-wide ones in

src/mvvm/components/. An element several apps need belongs in a package, not here.

Component & File Patterns

In src/mvvm/:

ViewModel Pattern

Components needing external logic use Container → ViewModel → View:

This applies to apps/*/src/mvvm/** and to features/flow/**.

In a `features/flow` package

One use<Screen>ViewModel.ts per screen produces data and handlers; <Screen>View.web.tsx and

<Screen>View.native.tsx render its props only, with no store, navigation or query hooks. The

container passes one to the other.

Example: @features/flow-portfolio-services-entry-points, every file of

CODE0:

index.ts                              ← export * only
ServicesEntryPoints.tsx               ← <ServicesEntryPointsView {...useServicesEntryPointsViewModel(props)} />
ServicesEntryPoints.types.ts          ← the container's props
useServicesEntryPointsViewModel.ts    ← feature flag, analytics, handlers
ServicesEntryPointsView.types.ts      ← the props contract both views share
ServicesEntryPointsView.web.tsx       ← props only
ServicesEntryPointsView.native.tsx    ← props only
ServicesEntryPoints.web.test.tsx
ServicesEntryPoints.native.test.tsx

Violation checklist: flag any View (`index.tsx` under `screens/` or `components/` in `src/mvvm/`, or `*View.web.tsx` / `*View.native.tsx` in `features/flow/`) that

❌ screens/UserProfileScreen/
     index.tsx   ← imports useSelector, useNavigation directly

✅ screens/UserProfileScreen/
     index.tsx                         ← props only
     useUserProfileScreenViewModel.ts  ← useSelector, useNavigation, RTK Query

Import Rules

into them.

Data Fetching

API calls and RTK Query endpoints live in a domain/api package such as @domain/api-push-devices.

A ViewModel in src/mvvm calls their hooks; it does not define endpoints. See

CODE0.

Design System

New UI in src/mvvm/ must use Lumen:

Testing

Every feature folder under src/mvvm/features/ must have an integration test in

__integrations__/; create a minimal test when the folder is first added. See

CODE0 skill.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.