--- name: atomic-design description: Atomic Design methodology for React component architecture. Use for structuring component libraries, organizing UI hierarchies, and creating scalable design systems. Triggers on requests for component organization, design system structure, UI hierarchy, or questions about Atoms/Molecules/Organisms/Templates/Pages. --- # Atomic Design Patterns ## Component Hierarchy ``` src/components/ ├── atoms/ # Smallest building blocks ├── molecules/ # Simple component groups ├── organisms/ # Complex UI sections ├── templates/ # Page layouts └── pages/ # Complete views ``` ## Level Definitions ### Atoms Indivisible UI elements. No dependencies on other components. ```tsx // atoms/Button/Button.tsx export const Button: FC = ({ children, variant, size, ...props }) => ( ); // atoms/Input/Input.tsx export const Input: FC = ({ label, error, ...props }) => (
{label && } {error && {error}}
); // atoms/Icon/Icon.tsx export const Icon: FC = ({ name, size = 24 }) => ( ); ``` **Examples:** Button, Input, Label, Icon, Avatar, Badge, Spinner, Divider ### Molecules Combine atoms into functional units with single responsibility. ```tsx // molecules/SearchField/SearchField.tsx export const SearchField: FC = ({ onSearch, placeholder }) => { const [value, setValue] = useState(''); return (
setValue(e.target.value)} placeholder={placeholder} />
); }; // molecules/FormField/FormField.tsx export const FormField: FC = ({ label, error, children }) => (
{children} {error && {error}}
); ``` **Examples:** SearchField, FormField, NavItem, Card, MenuItem, Toast ### Organisms Complex, self-contained sections with business logic. ```tsx // organisms/Header/Header.tsx export const Header: FC = ({ user, onLogout }) => (
); // organisms/ProductCard/ProductCard.tsx export const ProductCard: FC = ({ product, onAddToCart }) => (
{product.name}
{product.name}
); ``` **Examples:** Header, Footer, ProductCard, CommentSection, Sidebar, DataTable ### Templates Page-level layouts without real content. Define structure only. ```tsx // templates/DashboardLayout/DashboardLayout.tsx export const DashboardLayout: FC = ({ sidebar, header, content }) => (
{header}
{content}
); ``` ### Pages Templates filled with real data. Connect to state/APIs. ```tsx // pages/DashboardPage/DashboardPage.tsx export const DashboardPage: FC = () => { const { data: stats } = useStats(); const { user } = useAuth(); return ( } header={
} content={} /> ); }; ``` ## Decision Guide | Question | Atom | Molecule | Organism | |----------|------|----------|----------| | Has child components? | No | Yes | Yes | | Has business logic? | No | Minimal | Yes | | Reusable across projects? | Yes | Usually | Sometimes | | Contains API calls? | No | No | Possible | ## Naming Conventions - **Atoms:** Single noun (`Button`, `Input`, `Icon`) - **Molecules:** Descriptive compound (`SearchField`, `NavItem`) - **Organisms:** Domain-specific (`ProductCard`, `CheckoutForm`) - **Templates:** Layout suffix (`DashboardLayout`, `AuthLayout`) - **Pages:** Page suffix (`HomePage`, `ProductPage`) ## Export Pattern ```tsx // components/atoms/index.ts export { Button } from './Button'; export { Input } from './Input'; export { Icon } from './Icon'; // components/index.ts export * from './atoms'; export * from './molecules'; export * from './organisms'; ```