Refactor existing React Native (Expo) project to Atomic Design component structure
Refactors React Native Expo projects into Atomic Design structure with analysis, approval, and automated execution.
/plugin marketplace add IvanTorresEdge/molcajete.ai/plugin install react-native@Molcajete.aiRefactor existing React Native (Expo) project to Atomic Design component structure with analysis, plan approval, and automated execution.
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
--target | string | No | components directory | Specific directory or component to refactor |
--dry-run | boolean | No | false | Show plan without executing |
--skip-stories | boolean | No | false | Skip Storybook story generation |
--skip-tests | boolean | No | false | Skip test file updates |
Detect Expo project:
app.json or app.config.js -> Expo projectIdentify component directory:
components/ for Expo projects (no src/ prefix)Verify or create atomic design directories:
components/
├── atoms/
│ ├── .gitkeep
│ └── index.ts
├── molecules/
│ ├── .gitkeep
│ └── index.ts
├── organisms/
│ ├── .gitkeep
│ └── index.ts
├── templates/
│ ├── .gitkeep
│ └── index.ts
└── index.ts
Create barrel exports if missing:
Level barrel export template:
// components/atoms/index.ts
// Barrel export for atoms
// Components will be added here as they are created or moved
Main barrel export template:
// components/index.ts
export * from './atoms';
export * from './molecules';
export * from './organisms';
export * from './templates';
Invoke the code-analyzer agent with reference to atomic-design-mobile skill to:
Scan component directories using Glob patterns:
components/**/*.tsx (excluding tests and stories)**/*.test.tsx, **/*.spec.tsx, **/*.stories.tsxatoms/, molecules/, organisms/, templates/)app/** (Expo Router screens)Analyze each component:
Classify components using atomic-design-mobile skill criteria:
Assign confidence levels:
Detect circular dependencies and generate warnings
Generate RefactoringPlan with:
Present plan using AskUserQuestion with options:
Move component directories to atomic level folders:
components/Button/ -> components/atoms/Button/*.tsx, index.ts, __tests__/*, *.stories.tsxUpdate all import statements across codebase:
from '@/components/Button' -> from '@/components/atoms'from '../Button' -> from '@/components/atoms'Create/update barrel exports at each level:
// components/atoms/index.ts
export { Button } from './Button';
export type { ButtonProps } from './Button';
Generate Storybook stories (if not --skip-stories):
'Atoms/Button', 'Molecules/FormField'Update test file imports (if not --skip-tests)
Execute post-change-verification skill protocol:
Detect package manager (check lock files: pnpm-lock.yaml, yarn.lock, package-lock.json, bun.lockb)
Run format:
<pkg> run format
Run lint:
<pkg> run lint
Run type-check:
<pkg> run type-check # or npx tsc --noEmit
Run tests:
<pkg> test
Display completion summary with verification results:
=== REFACTORING COMPLETE ===
Files changed: 35
Components moved: 18
Stories created: 14
Barrel exports updated: 5
=== POST-CHANGE VERIFICATION ===
Format: PASSED
Lint: PASSED (0 errors, 0 warnings)
Type-check: PASSED (0 errors)
Tests: PASSED (18/18)
Pre-existing issues: NONE
=== TASK COMPLETE ===
Next steps:
1. Run Storybook on device to verify stories
2. Review the changes in your git diff
3. Commit when satisfied
To undo: git checkout -- components/
components/
Button/
Button.tsx
index.ts
Input/
Input.tsx
index.ts
SearchBar/
SearchBar.tsx
index.ts
Header/
Header.tsx
index.ts
ScreenLayout/
ScreenLayout.tsx
index.ts
components/
atoms/
Button/
Button.tsx
Button.stories.tsx
index.ts
Input/
Input.tsx
Input.stories.tsx
index.ts
index.ts
molecules/
SearchBar/
SearchBar.tsx
SearchBar.stories.tsx
index.ts
index.ts
organisms/
Header/
Header.tsx
Header.stories.tsx
index.ts
index.ts
templates/
ScreenLayout/
ScreenLayout.tsx
index.ts
index.ts
index.ts
/react-native:refactor-atomic-design
/react-native:refactor-atomic-design --target components/ui
/react-native:refactor-atomic-design --skip-stories
/react-native:refactor-atomic-design --dry-run
src/ directoryapp/ directory remain there (Expo Router convention)