7.4 KiB
Atomic Design Structure for MetaBuilder
Overview
This document describes the atomic design pattern implementation for MetaBuilder's React components. Components are organized into three categories: Atoms, Molecules, and Organisms.
Principles
Atoms
Definition: Smallest, indivisible UI elements that cannot be broken down further without losing meaning.
Characteristics:
- Single responsibility
- No dependencies on other custom components (only shadcn/ui)
- Highly reusable
- Stateless or minimal state
- Examples: buttons, inputs, labels, badges, icons
Location: src/components/atoms/
Molecules
Definition: Groups of atoms that function together as a cohesive unit.
Characteristics:
- Composed of 2-5 atoms
- Single, focused purpose
- Reusable across multiple contexts
- Can have internal state but no complex business logic
- Examples: form fields with labels, search bars, card headers
Location: src/components/molecules/
Organisms
Definition: Complex components that form distinct sections of an interface.
Characteristics:
- Composed of molecules and atoms
- May contain business logic
- Often specific to a particular feature
- Can be entire sections or panels
- Examples: navigation bars, data tables, forms, editors
Location: src/components/organisms/
Current Component Organization
Atoms (src/components/atoms/)
Foundational elements that should remain in the atoms folder:
- All shadcn/ui components (
@/components/ui/*) - Icon components (from
@phosphor-icons/react) - Basic styled elements
Molecules (src/components/molecules/)
Simple composite components:
SecurityBadge- Severity indicator for security warningsUserCard- Compact user displayTenantCard- Tenant information displayTabNavigation- Tab bar with scrollEmptyState- Empty state placeholderCredentialsDisplay- Username/password display with copyPreviewBanner- Preview mode indicatorPropertyField- Form field with label and inputClassBadge- CSS class display badgeDropdownOption- Single dropdown option
Organisms (src/components/organisms/)
Complex feature components:
SchemaEditor- Full schema editing interfaceComponentCatalog- Component browsing and selectionPropertyInspector- Component property editorCssClassBuilder- Visual CSS class selectorCssClassManager- CSS class library managementDropdownConfigManager- Dropdown configuration interfaceDatabaseManager- Database management panelUserManagement- User CRUD interfacePackageManager- Package browsing and installationPackageImportExport- Import/export functionalityLuaEditor- Lua script editorLuaSnippetLibrary- Lua snippet managementJsonEditor- JSON editing interfaceCodeEditor- Monaco-based code editorNerdModeIDE- Full IDE panelThemeEditor- Theme customization interfaceSMTPConfigEditor- SMTP configuration formIRCWebchat- IRC chat interfaceIRCWebchatDeclarative- Declarative IRC chatWorkflowEditor- Workflow configurationPageRoutesManager- Page routing managementGodCredentialsSettings- God credentials managementScreenshotAnalyzer- Screenshot analysis toolGitHubActionsFetcher- GitHub actions integrationAuditLogViewer- Audit log display
Pages/Levels (src/components/)
Top-level page components (remain at root level):
Level1- Public landing pageLevel2- User dashboardLevel3- Admin panelLevel4- God-tier builderLevel5- Super God panelLogin- AuthenticationUnifiedLogin- Unified auth interfacePasswordChangeDialog- Password change modal
Shared Utilities (src/components/shared/)
Shared helpers and utilities:
constants.ts- Shared constantstypes.ts- Shared type definitionsutils.ts- Shared utility functions
Migration Guide
Step 1: Create Folder Structure
src/components/
├── atoms/ # Smallest UI elements
├── molecules/ # Simple composite components
├── organisms/ # Complex feature components
├── shared/ # Shared utilities and types
├── ui/ # shadcn components (existing)
└── [Level components] # Top-level pages remain at root
Step 2: Move Components
Components should be moved according to their complexity:
- Start with atoms (if any custom ones exist)
- Move molecules (2-5 atom combinations)
- Move organisms (complex features)
- Update all import paths
Step 3: Update Imports
Old import:
import { ComponentCatalog } from '@/components/ComponentCatalog'
New import:
import { ComponentCatalog } from '@/components/organisms/ComponentCatalog'
Step 4: Create Index Files
Each folder should have an index.ts for easier imports:
// src/components/molecules/index.ts
export { SecurityBadge } from './SecurityBadge'
export { UserCard } from './UserCard'
export { TenantCard } from './TenantCard'
// ... etc
This allows cleaner imports:
import { SecurityBadge, UserCard } from '@/components/molecules'
Benefits
- Clarity: Easy to understand component complexity at a glance
- Reusability: Clear separation encourages reuse of simpler components
- Maintainability: Changes to atoms automatically propagate to molecules and organisms
- Testability: Atoms and molecules are easier to test in isolation
- Documentation: Clear hierarchy serves as living documentation
- Onboarding: New developers can quickly understand the architecture
- Refactoring: Easy to identify when organisms should be broken down
Best Practices
- Atoms should never import molecules or organisms
- Molecules should only import atoms
- Organisms can import atoms, molecules, and other organisms
- Use TypeScript interfaces to define props clearly
- Keep business logic in organisms, not atoms/molecules
- Make atoms and molecules as generic as possible
- Use composition over inheritance
- Document complex organisms with JSDoc comments
File Naming Conventions
- Use PascalCase for component files:
SecurityBadge.tsx - Use kebab-case for style files:
security-badge.module.css - Use camelCase for utility files:
formatUtils.ts - Index files should re-export components:
index.ts
Component Template
// src/components/atoms/ExampleAtom.tsx
import { cn } from '@/lib/utils'
interface ExampleAtomProps {
label: string
variant?: 'primary' | 'secondary'
className?: string
}
export function ExampleAtom({
label,
variant = 'primary',
className
}: ExampleAtomProps) {
return (
<div className={cn('base-styles', className)}>
{label}
</div>
)
}
Migration Checklist
- Create folder structure (atoms, molecules, organisms, shared)
- Identify and categorize all existing components
- Create index files for each folder
- Move atoms to their folder
- Move molecules to their folder
- Move organisms to their folder
- Update all import statements
- Update tests to use new paths
- Verify application builds successfully
- Verify all functionality works
- Update documentation