mfe-skills / rules
Cursor rule53 starsChanged 39 days agoMITView on GitHub
MFE boundary review: MFE boundary rules — critical (rules 3 and 4). Load when this topic is in scope; part of mfe-skills.
We split this mfe-boundary-rules-core-critical.mdc into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 68
Prefer URL (first segment changes area.
- Distinctive: line 69
Use web storage or cookies for auth tokens
- Distinctive: line 70
Never pass complex domain objects between views
≈ “Common” is an estimate: at least 1 in 5 of the 6,350 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
---
description: MFE boundary review: MFE boundary rules — critical (rules 3 and 4). Load when this topic is in scope; part of mfe-skills.
alwaysApply: false
---
# MFE boundary rules — critical (rules 3 and 4)
## Contents
- Rule 3 — Hides implementation details behind an API contract
- Rule 4 — Communicates via events, not shared state
**Version**: 1.3 | **Skill**: reviewing-mfe-boundaries | **Source**: *Building Micro-Frontends* (O'Reilly).
Critical rules: hide implementation details; communicate via events not shared state.
For rules 1, 2, 5–8 and governance extensions: load `references/rules-core-standard.md`.
For framework-specific patterns: load `references/rules-toolchain.md`.
---
## Rule 3 — Hides implementation details behind an API contract
Define the API contract upfront between producer and consumer teams. Internal implementation details — frameworks, data fetching strategies, database schemas, code structure — stay hidden behind it.
**The API-first principle**: the contract is the binding agreement. Both teams can work in parallel, focused on their side of the contract. Either team can change their internals freely without affecting the other, as long as the contract is respected.
**Strong encapsulation is required** to avoid domain leaks into other parts of the application. When a micro-frontend exposes its internals — through direct imports, shared modules, or coupled data structures — changes inside cascade outside and independent deployment breaks down.
**Violation signals**:
- Direct imports from one micro-frontend's source into another
- Shared internal modules or utilities across micro-frontend boundaries
- Contract changes that require simultaneous updates across multiple teams
- A micro-frontend exposing more than what consumers strictly need
**Code-checkable patterns**:
```javascript
// ✗ CRITICAL — cross-boundary import, bypasses the API contract
import { UserStore } from '@org/auth-mfe/store'
import { useCart } from '@org/cart-mfe/hooks'
import { formatCurrency } from '@org/checkout-mfe/utils'
// ✓ Each micro-frontend accesses only its own internals
import { formatCurrency } from './utils/currency'
// ✓ Shared utilities belong in an npm package, not a micro-frontend
import { formatCurrency } from '@org/shared-utils'
```
**Aliased imports do not fix this**: `import { UserStore as Store } from '@org/auth-mfe/store'` is still a Rule 3 violation. The coupling exists at the resolved module level regardless of the local alias.
---
## Rule 4 — Communicates via events, not shared state
Micro-frontends must remain decoupled from each other. A global state manager shared across micro-frontends is an anti-pattern in distributed systems.
**Three channels — do not mix them up:**
| Channel | Who listens | Allowed events | Example |
|---------|-------------|----------------|---------|
| **Shell platform bus** | Shell only | `shell:alert`, `shell:modal:open`, `shell:toast` | MFE asks shell to show a modal |
| **Peer bus (horizontal split)** | Other MFEs on the same page | Domain namespaces (`catalog:*`, `checkout:*`) | Basket reacts to `catalog:itemAdded` |
| **URL / storage (vertical split)** | Owning MFE via URL or storage | N/A — use paths and tokens | `/catalog/product/sku-1`, `sessionStorage` auth token |
**Shell must not** subscribe to domain events (`catalog:productSelected`, `checkout:completed`). Those belong to peer MFEs or to URL/storage across views.
**For cross-view communication (vertical split)**:
- Prefer **URL** (first segment changes area; deeper paths stay in the owning MFE)
- Use **web storage** or **cookies** for auth tokens
- Never pass complex domain objects between views
**Violation signals**:
- Shared Redux, Zustand, or MobX store across micro-frontend boundaries
- `window.__mfe_*` or shell-owned global singletons holding domain data
- Shell `useEffect` handlers for `catalog:*`, `checkout:*`, or similar domain namespaces
- Props drilling domain objects or using callbacks as the primary coordination mechanism
**Code-checkable patterns**:
```javascript
// ✗ CRITICAL — shared store across boundaries
import { checkoutStore } from '@org/checkout-mfe/store'
// ✗ CRITICAL — shell listens to domain events
platformBus.on('catalog:productSelected', handler) // in shell App.tsx
// ✓ MFE → shell platform chrome
platformBus.emit('shell:alert', { message: 'Saved', variant: 'success' })
// ✓ Horizontal peers — domain events (not handled by shell)
eventBus.emit('catalog:itemAdded', { productId })
// ✓ Vertical split — URL
window.location.href = `/catalog/product/${productId}`
```
**Callback anti-pattern** (less severe but flag it):
```jsx
// ✗ Callbacks as primary coordination mechanism — brittle coupling
<CheckoutMicrofrontend
onUserDataNeeded={(cb) => cb(userData)}
onCartUpdate={(data) => updateParentCart(data)}
/>
```
---
---
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 3,978 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository15 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/mfe-architecture-boundary-design.mdcCursor rule
- .cursor/rules/mfe-architecture-canvas-pointer.mdcCursor rule
- .cursor/rules/mfe-architecture-decisions.mdcCursor rule
- .cursor/rules/mfe-architecture.mdcCursor rule
- .cursor/rules/mfe-architecture-rules-ref.mdcCursor rule
- .cursor/rules/mfe-boundary-code-patterns.mdcCursor rule
- .cursor/rules/mfe-boundary-remediation.mdcCursor rule
- .cursor/rules/mfe-boundary-review.mdcCursor rule
- .cursor/rules/mfe-boundary-routing.mdcCursor rule
- .cursor/rules/mfe-boundary-rules-core-standard.mdcCursor rule
- .cursor/rules/mfe-boundary-toolchain.mdcCursor rule
- reviewing-mfe-boundariesSkill
- understanding-mfe-architectureSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

