# Atomic Component Library - Quick Start ## ๐Ÿ“š Documentation Overview This project now uses an **Atomic Design** component architecture. Here's how to navigate the documentation: ### Essential Reading (Start Here!) 1. **[ATOMIC_REFACTOR_SUMMARY.md](./ATOMIC_REFACTOR_SUMMARY.md)** - Overview of changes - What changed and why - Component inventory - Benefits and usage patterns - Next steps 2. **[ATOMIC_COMPONENTS.md](./ATOMIC_COMPONENTS.md)** - Complete guide - Atomic design methodology explained - Component hierarchy rules - When to create each type - Best practices and patterns - Migration guide 3. **[ATOMIC_USAGE_EXAMPLES.md](./ATOMIC_USAGE_EXAMPLES.md)** - Practical examples - 10+ real-world usage examples - Code templates - Testing patterns - Quick start guide 4. **[COMPONENT_MAP.md](./COMPONENT_MAP.md)** - Visual reference - Component composition diagrams - Dependency maps - Data flow examples - Performance tips ## ๐ŸŽฏ Quick Reference ### Component Levels | Level | Purpose | Example | Import From | |-------|---------|---------|-------------| | **Atom** | Single UI element | `AppLogo`, `StatusIcon` | `@/components/atoms` | | **Molecule** | 2-5 atoms combined | `SaveIndicator`, `ToolbarButton` | `@/components/molecules` | | **Organism** | Complex composition | `AppHeader`, `NavigationMenu` | `@/components/organisms` | | **Feature** | Domain-specific | `CodeEditor`, `ModelDesigner` | `@/components/[Name]` | ### Directory Structure ``` src/components/ โ”œโ”€โ”€ atoms/ # 7 building blocks โ”œโ”€โ”€ molecules/ # 10 simple combinations โ”œโ”€โ”€ organisms/ # 4 complex components โ”œโ”€โ”€ ui/ # shadcn base components โ””โ”€โ”€ [features]/ # Feature components ``` ## ๐Ÿš€ Usage Examples ### Using Atoms ```tsx import { AppLogo, StatusIcon, ErrorBadge } from '@/components/atoms' ``` ### Using Molecules ```tsx import { SaveIndicator, ToolbarButton, EmptyState } from '@/components/molecules' } label="Add" onClick={handleAdd} /> } title="No files" description="Get started" /> ``` ### Using Organisms ```tsx import { AppHeader, PageHeader, NavigationMenu } from '@/components/organisms' ``` ## ๐Ÿ“‹ Component Inventory ### Atoms (7) - `AppLogo` - Application logo - `TabIcon` - Icon with variants - `StatusIcon` - Save/sync status - `ErrorBadge` - Error counter - `IconWrapper` - Icon container - `LoadingSpinner` - Loading animation - `EmptyStateIcon` - Empty state icon ### Molecules (10) - `SaveIndicator` - Save status display - `AppBranding` - Logo + title - `PageHeaderContent` - Page title section - `ToolbarButton` - Button with tooltip - `NavigationItem` - Nav link - `NavigationGroupHeader` - Group header - `EmptyState` - Empty state view - `LoadingState` - Loading view - `StatCard` - Statistics card - `LabelWithBadge` - Label + badge ### Organisms (4) - `NavigationMenu` - Sidebar navigation - `PageHeader` - Page header - `ToolbarActions` - Action toolbar - `AppHeader` - Application header ## ๐Ÿ› ๏ธ Creating New Components ### 1. Determine Component Level Ask yourself: - Can it be broken down? โ†’ Not an atom - Does it combine atoms? โ†’ At least a molecule - Does it have complex state? โ†’ Probably an organism - Is it feature-specific? โ†’ Feature component ### 2. Create the Component ```tsx // src/components/atoms/MyAtom.tsx interface MyAtomProps { value: string variant?: 'default' | 'primary' } export function MyAtom({ value, variant = 'default' }: MyAtomProps) { return {value} } ``` ### 3. Update Index File ```tsx // src/components/atoms/index.ts export { MyAtom } from './MyAtom' ``` ### 4. Use in Your Code ```tsx import { MyAtom } from '@/components/atoms' ``` ## โœ… Best Practices ### DO: - โœ… Use atoms for single-purpose elements - โœ… Compose molecules from atoms - โœ… Build organisms from molecules/atoms - โœ… Keep feature logic in feature components - โœ… Export from index files - โœ… Use TypeScript types - โœ… Follow naming conventions ### DON'T: - โŒ Import organisms in atoms - โŒ Import molecules in atoms - โŒ Duplicate atom functionality - โŒ Mix business logic in atoms/molecules - โŒ Skip TypeScript types - โŒ Create "god components" ## ๐Ÿ“Š Import Hierarchy ``` Feature Components โ†“ can import Organisms โ†“ can import Molecules โ†“ can import Atoms โ†“ can import shadcn UI ``` ## ๐Ÿ”ง Common Patterns ### Pattern 1: Status Display ```tsx const isRecent = Date.now() - lastSaved < 3000 ``` ### Pattern 2: Empty State ```tsx } title="No files yet" description="Create your first file" action={} /> ``` ### Pattern 3: Loading State ```tsx {isLoading ? ( ) : ( )} ``` ### Pattern 4: Stat Cards ```tsx
} label="Files" value={fileCount} /> } label="Models" value={modelCount} /> } label="Components" value={compCount} />
``` ## ๐Ÿงช Testing ### Atoms (Unit Tests) ```tsx describe('StatusIcon', () => { it('shows CheckCircle when saved', () => { render() expect(screen.getByTestId('check-circle')).toBeInTheDocument() }) }) ``` ### Molecules (Integration Tests) ```tsx describe('SaveIndicator', () => { it('shows saved text when recent', () => { render() expect(screen.getByText('Saved')).toBeInTheDocument() }) }) ``` ### Organisms (E2E Tests) ```tsx describe('NavigationMenu', () => { it('navigates when item clicked', () => { render() userEvent.click(screen.getByText('Code Editor')) expect(onTabChange).toHaveBeenCalledWith('code') }) }) ``` ## ๐ŸŽจ Styling All components use: - **Tailwind** for utility classes - **CSS variables** for theming - **Responsive** design patterns - **Accessible** markup Example: ```tsx
{/* Responsive spacing and text sizing */}
``` ## ๐Ÿ“ TypeScript All components are fully typed: ```tsx interface ComponentProps { required: string optional?: number callback?: () => void variant?: 'default' | 'primary' } export function Component({ required, optional = 0 }: ComponentProps) { // Implementation } ``` ## ๐Ÿšฆ Next Steps 1. **Read the docs** - Start with ATOMIC_REFACTOR_SUMMARY.md 2. **Review examples** - Check ATOMIC_USAGE_EXAMPLES.md 3. **Study the maps** - See COMPONENT_MAP.md for visual guides 4. **Try it out** - Create a new molecule or atom 5. **Refactor** - Identify components to atomize ## ๐Ÿ’ก Tips - Start with molecules for most use cases - Extract atoms when you see duplication - Build organisms for major UI sections - Keep feature components for domain logic - Use index files for clean imports - Follow the existing patterns ## ๐Ÿค Contributing When adding new atomic components: 1. Choose the appropriate level 2. Create the component file 3. Add TypeScript types 4. Update the index.ts 5. Add to COMPONENT_MAP.md 6. Create usage examples 7. Write tests ## ๐Ÿ“ž Need Help? 1. Check the documentation files 2. Look at existing component examples 3. Review the component map 4. Follow established patterns 5. Ask questions in code reviews ## ๐Ÿ”— Resources - **Atomic Design**: https://atomicdesign.bradfrost.com/ - **Component-Driven**: https://www.componentdriven.org/ - **React Patterns**: https://reactpatterns.com/ --- **Remember**: The atomic structure makes components more reusable, testable, and maintainable. When in doubt, start small (atom/molecule) and grow as needed!