Skip to content

chore: enhance UI development guidelines with component hierarchy and feature organization#25060

Merged
georgewrmarshall merged 4 commits intomainfrom
cursor-rules
Jan 23, 2026
Merged

chore: enhance UI development guidelines with component hierarchy and feature organization#25060
georgewrmarshall merged 4 commits intomainfrom
cursor-rules

Conversation

@georgewrmarshall
Copy link
Copy Markdown
Contributor

@georgewrmarshall georgewrmarshall commented Jan 22, 2026

Description

Enhanced the UI development guidelines in .cursor/rules/ui-development-guidelines.mdc to provide comprehensive guidance for component selection, reuse, and organization. This update addresses critical issues with the glob pattern matching and adds extensive documentation for working with the design system, component library, and feature-specific components.

Key improvements:

  1. Fixed critical glob pattern - Changed from app/*.{tsx,ts,jsx,js} (matched 0 files) to app/**/*.{tsx,jsx} (now matches 2,893 UI component files)
  2. Enhanced component hierarchy - Added 4-tier decision tree with clear rules for when to use design system, component library, feature components, or custom implementations
  3. Added feature component organization - Guidance on checking for and reusing existing feature-specific components (e.g., PerpsTradingCard, PredictionMarketOrderPanel) before building new ones
  4. Component documentation access - Instructions for accessing TypeScript type definitions and JSDoc comments
  5. Legacy code migration guidelines - Clear path for migrating StyleSheet-based code to design system primitives
  6. Box component best practices - When to use props vs twClassName, spacing system, color tokens
  7. Enhanced code review checklist - 8-point checklist and AI agent guidelines

Changelog

CHANGELOG entry: null

Related issues

Fixes: N/A (Internal documentation improvement)

Manual testing steps

Feature: UI Development Guidelines Application

  Scenario: AI agent implements a feature-specific component
    Given an AI agent needs to implement a new Perps trading card
    
    When the agent reads the UI development guidelines
    Then the guidelines should instruct to check app/features/perps/components/ first
    And the guidelines should direct to reuse existing PerpsTradingCard if found
    And the guidelines should require using Box/Text primitives if building new component

  Scenario: Developer verifies glob pattern matches their component files
    Given a developer working on files in app/component-library/
    
    When they check if guidelines apply to their components
    Then the glob pattern app/**/*.{tsx,jsx} should match their files
    And they should receive guidance on using design system components

Screenshots/Recordings

N/A - Documentation only change

Before

  • Glob pattern matched 0 files
  • Basic 3-tier component hierarchy
  • No guidance on feature-specific component reuse
  • Missing migration guidelines
  • No Box component best practices

After

  • Glob pattern matches 2,893 UI component files
  • Comprehensive 4-tier hierarchy with decision tree
  • Clear workflow for checking/reusing feature components
  • Complete migration guidelines with examples
  • Detailed Box component best practices
  • Enhanced AI agent guidelines

Pre-merge author checklist

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

Note

Updates .cursor/rules/ui-development-guidelines.mdc with comprehensive, enforceable guidance.

  • Fixes glob to app/**/*.{tsx,jsx} to correctly target all UI files
  • Introduces a strict 4-tier component hierarchy with a clear decision tree prioritizing @metamask/design-system-react-native
  • Adds component docs references, code templates, and Box best practices (props vs twClassName, spacing, color tokens)
  • Provides legacy migration steps and example (StyleSheet → design system/Tailwind)
  • Expands error prevention with a code review checklist and AI agent guidelines
  • Adds enforcement notes to reject non-design-system patterns

Written by Cursor Bugbot for commit a7b3c7b. This will update automatically on new commits. Configure here.

@github-actions
Copy link
Copy Markdown
Contributor

CLA Signature Action: All authors have signed the CLA. You may need to manually re-run the blocking PR check if it doesn't pass in a few minutes.

@metamaskbot metamaskbot added the team-design-system All issues relating to design system in Mobile label Jan 22, 2026
@georgewrmarshall georgewrmarshall self-assigned this Jan 22, 2026
Comment on lines -3 to +4
globs: 'app/*.{tsx,ts,jsx,js}'
globs:
- 'app/**/*.{tsx,jsx}'
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes glob pattern

@georgewrmarshall georgewrmarshall marked this pull request as ready for review January 22, 2026 20:38
Comment on lines +16 to 19
### The Rule: Check Design System First
**Before writing any new component or choosing what to use, ask: "Does @metamask/design-system-react-native have this?"**

1. **FIRST**: Use `@metamask/design-system-react-native` components
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prioritise @metamask/design-system-react-native components

1. **FIRST**: Use `@metamask/design-system-react-native` components
2. **SECOND**: Use `app/component-library` components only if design system lacks the component
3. **LAST RESORT**: Custom components with StyleSheet (avoid unless absolutely necessary)
- **Always use for**: Box (layout), Text (typography), Button/ButtonBase/ButtonIcon, Icon, Checkbox
Copy link
Copy Markdown
Contributor Author

@georgewrmarshall georgewrmarshall Jan 22, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding ButtonBase, we only want it used when Button or other app/feature buttons don’t meet the need. It could be a good option for custom buttons that follow the same shape and size as Button, but don’t fit an existing variant or pattern. In those cases, use ButtonBase to create a feature-specific button. 🤔

- **Examples**: `BridgeInputSelector`, `StakeInputView`, `NFTDetailsModal`, `PerpsTradingCard`, `PredictionMarketOrderPanel`
- **Location**: Can live in feature directories (`app/components/Views/*/components/`, `app/features/*/`)
- **Rule**: Must be built using Box, Text, and other design system primitives - NO raw View/Text or StyleSheet
- **Reuse**: Check if a feature-specific component already exists in the feature's directory before building a new one. These components should be reused within their feature domain.
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was an important addition we still want to use feature specific components where appropriate

Comment on lines +37 to +39
4. **LAST RESORT**: Custom components with StyleSheet
- **Only when**: Highly specialized one-off needs with no design system equivalent AND no component-library equivalent
- **Requires**: Strong justification why design system primitives can't be composed
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we need to give an example here. Maybe complex animations?

Comment on lines +47 to +48
├─ Is it BottomSheet, Tabs, Header, ListItem, Skeleton, Tag, Modal, etc?
│ └─ YES → Use app/component-library [STOP]
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will need to update this rule as we release more @metamask/design-system-react-native components 🤔

Comment on lines +147 to +165
## Component Documentation Access

### Type Definitions & JSDoc Comments
All @metamask/design-system-react-native components have comprehensive TypeScript definitions with JSDoc comments:

- **Box**: `/node_modules/@metamask/design-system-react-native/dist/components/Box/Box.types.d.cts`
- **Text**: `/node_modules/@metamask/design-system-react-native/dist/components/Text/Text.types.d.cts`
- **Button**: `/node_modules/@metamask/design-system-react-native/dist/components/Button/Button.types.d.cts`

When unsure about component APIs:
1. Read the `.types.d.cts` files for complete prop documentation
2. Reference `app/component-library/components/design-system.stories.tsx` for usage examples
3. Check GitHub source: https://github.com/MetaMask/metamask-design-system/tree/main/packages/design-system-react-native/src/components

### Box Component Quick Reference
- **Spacing**: Use `gap`, `padding*`, `margin*` props with values 0-12 (maps to 0px-48px)
- **Flexbox**: Use `flexDirection`, `alignItems`, `justifyContent` enum props
- **Colors**: Use `backgroundColor` and `borderColor` with semantic tokens
- **Tailwind**: Use `twClassName` for utilities not covered by props
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if this helps the agent or if it’ll handle it by default, but I don’t think there’s any harm in specifying it. We keep most of our comprehensive docs in READMEs in the repo, so it’s worth thinking about how we can make those accessible to the agent. For now, I’ve added the link to the components folder:
https://github.com/MetaMask/metamask-design-system/tree/main/packages/design-system-react-native/src/components

>
```

## Box Component Best Practices
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding Box component best practices here to encourage the use of Box props. This should help with code sharing across platforms as we have Box available in both. They have the same component api

| Manual padding/margin | `twClassName="p-4 m-2"` |

## Error Prevention
## Legacy Code Migration Guidelines
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could probably become its own doc eventually, though I’m not sure engineers will have time to migrate files they’re actively working on. There’s not much incentive to do it beyond good engineering practices and reducing tech debt.

Remove example directory structure that doesn't reflect actual codebase organization. Keep focus on principles rather than specific paths.
Remove entire section about feature organization since:
- app/features/ only contains SampleFeature (dev/test only)
- Actual features live in app/components/Views/[FeatureName]/
- Simplified tier 3 to just mention typical location
- Updated decision tree to reference actual path pattern
- Removed hypothetical Perps/Predictions examples

Keep focus on principles (check for existing, reuse, use design system) without prescribing specific organizational structure.
Remove all prescriptive location guidance for where feature UI should live:
- Removed 'Location: Typically in app/components/Views/[FeatureName]/components/'
- Changed decision tree from specific path to 'search codebase for similar components'

Per SampleFeature README, real features are distributed across /app/components/,
/app/reducers/, /app/core/controllers/, etc. - not in a prescribed structure.

Keep focus on principles (reuse, search first, use design system) without
prescribing organizational structure.
@github-actions
Copy link
Copy Markdown
Contributor

🔍 Smart E2E Test Selection

  • Selected E2E tags: None (no tests recommended)
  • Risk Level: low
  • AI Confidence: 98%
click to see 🤖 AI reasoning details

The only changed file is .cursor/rules/ui-development-guidelines.mdc, which is a Cursor AI editor configuration file containing documentation and guidelines for UI development. This file:

  1. Does not affect application code: It's a .mdc (Markdown Configuration) file in the .cursor/rules/ directory, which is used by the Cursor AI editor to provide coding suggestions and guidelines.

  2. Does not affect test infrastructure: No changes to E2E tests, test fixtures, page objects, or test utilities.

  3. Does not affect build or CI: No changes to package.json, metro.config.js, babel.config.js, .detoxrc.js, or any GitHub workflows.

  4. Content is purely documentation: The changes add expanded documentation about component hierarchy, decision trees, Box component best practices, legacy code migration guidelines, and code review checklists for AI assistants.

  5. No runtime impact: These files are not bundled with the application and have no effect on how the app runs or how tests execute.

This is a zero-risk change that only affects developer tooling (specifically Cursor AI suggestions). No E2E tests are needed to validate this change.

View GitHub Actions results

@sonarqubecloud
Copy link
Copy Markdown

@georgewrmarshall georgewrmarshall added this pull request to the merge queue Jan 22, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 23, 2026
@georgewrmarshall georgewrmarshall added this pull request to the merge queue Jan 23, 2026
Merged via the queue into main with commit 01483b6 Jan 23, 2026
58 checks passed
@georgewrmarshall georgewrmarshall deleted the cursor-rules branch January 23, 2026 00:45
@github-actions github-actions bot locked and limited conversation to collaborators Jan 23, 2026
@metamaskbot metamaskbot added the release-7.64.0 Issue or pull request that will be included in release 7.64.0 label Jan 23, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

release-7.64.0 Issue or pull request that will be included in release 7.64.0 size-M team-design-system All issues relating to design system in Mobile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants