- Updated address retrieval in user service to replace billing info with a dedicated address method. - Adjusted API endpoints to use `PATCH /api/me/address` for address updates instead of billing updates. - Enhanced documentation to reflect changes in address management processes and API usage. - Removed deprecated types and services related to billing address handling, streamlining the codebase.
7.9 KiB
Codebase Refactoring Review Design Document
Overview
This design document outlines the fixes and improvements needed to complete the codebase refactoring properly. Based on the review, several issues were identified that need to be addressed to achieve the clean, atomic design architecture originally specified.
Issues Identified
1. Incomplete Atomic Design Implementation
Problem: Components are not properly categorized according to atomic design principles.
Current State:
- Catalog components are in
/components/catalog/instead of being properly categorized - Many components that should be molecules are mixed with atoms
- Business-specific components are in shared locations
Solution: Reorganize components into proper atomic design hierarchy:
components/
├── ui/ (Atoms - Basic building blocks)
│ ├── Button/
│ ├── Input/
│ ├── Badge/
│ └── LoadingSpinner/
├── common/ (Molecules - Combinations of atoms)
│ ├── DataTable/
│ ├── SearchBar/
│ ├── FormField/
│ └── StatusIndicator/
├── layout/ (Organisms - Complex UI sections)
│ ├── DashboardLayout/
│ ├── PageLayout/
│ └── AuthLayout/
└── business/ (Business-specific molecules)
├── ProductCard/
├── OrderSummary/
└── PricingDisplay/
2. Legacy Code and TODO Comments
Problem: Numerous TODO comments and legacy compatibility code remain.
Current Issues:
- Disabled exports with TODO comments in multiple index files
- Legacy compatibility exports in layout components
- Incomplete feature module implementations
- Deprecated component references
Solution: Clean up all legacy code and complete implementations.
3. Misplaced Business Components
Problem: Business-specific components are in shared locations.
Current Issues:
- Catalog components should be in the catalog feature module
- Product-specific components are in shared components directory
- Business logic mixed with presentation components
Solution: Move business components to appropriate feature modules.
4. Inconsistent Component Structure
Problem: Components don't follow consistent patterns.
Current Issues:
- Mixed file naming conventions
- Inconsistent folder structures
- Some components lack proper index files
- Export patterns are inconsistent
Solution: Standardize all component structures.
Proposed Architecture Fixes
Component Reorganization
Phase 1: Atomic Design Restructure
// Move catalog components to feature module
features/catalog/
├── components/
│ ├── ProductCard/
│ ├── ProductComparison/
│ ├── PricingDisplay/
│ ├── OrderSummary/
│ ├── ConfigurationStep/
│ └── index.ts
├── hooks/
├── services/
└── types/
// Keep only truly generic components in shared
components/common/
├── DataTable/
├── SearchBar/
├── FormField/
└── StatusIndicator/
Phase 2: Clean Up Legacy Code
// Remove legacy exports
// Before:
export { DashboardLayout as default } from "./dashboard-layout";
export { PageLayout as LegacyPageLayout } from "./page-layout";
// After:
export { DashboardLayout } from "./DashboardLayout";
export { PageLayout } from "./PageLayout";
Phase 3: Complete Feature Modules
// Complete feature module exports
// Before:
// Components - TODO: Enable when implemented
// export * from './components';
// After:
export * from './components';
export * from './hooks';
export * from './services';
export * from './types';
Component Standards
Naming Conventions
// Component files: PascalCase
ProductCard.tsx
OrderSummary.tsx
// Folders: PascalCase for components
ProductCard/
├── ProductCard.tsx
├── ProductCard.test.tsx
├── ProductCard.stories.tsx
└── index.ts
// Utility files: kebab-case
form-validation.ts
api-client.ts
Export Patterns
// Component index files
export { ComponentName } from './ComponentName';
export type { ComponentNameProps } from './ComponentName';
// Feature index files
export * from './components';
export * from './hooks';
export * from './services';
export * from './types';
File Structure Standards
Component Structure
ComponentName/
├── ComponentName.tsx # Main component
├── ComponentName.test.tsx # Unit tests
├── ComponentName.stories.tsx # Storybook stories (optional)
├── types.ts # Component-specific types (if complex)
└── index.ts # Exports
Feature Module Structure
features/feature-name/
├── components/
│ ├── ComponentA/
│ ├── ComponentB/
│ └── index.ts
├── hooks/
│ ├── useFeature.ts
│ └── index.ts
├── services/
│ ├── feature.service.ts
│ └── index.ts
├── types/
│ ├── feature.types.ts
│ └── index.ts
├── utils/
│ ├── feature.utils.ts
│ └── index.ts
└── index.ts
Implementation Strategy
Step 1: Component Audit and Categorization
-
Audit all components and categorize them properly:
- Atoms: Basic UI elements (Button, Input, Badge)
- Molecules: Combinations of atoms (FormField, SearchBar)
- Organisms: Complex sections (Layouts, DataTable)
- Business Components: Feature-specific (ProductCard, OrderSummary)
-
Create migration plan for moving components to correct locations
Step 2: Legacy Code Cleanup
- Remove all TODO comments that represent incomplete work
- Complete or remove disabled exports
- Remove legacy compatibility code
- Standardize naming conventions throughout
Step 3: Feature Module Completion
- Move business components to appropriate feature modules
- Complete feature module implementations
- Ensure proper encapsulation of business logic
- Create proper public APIs for features
Step 4: Component Standardization
- Standardize component structure across all components
- Ensure consistent exports and imports
- Add missing index files where needed
- Update all import statements to use new locations
Step 5: Documentation and Testing
- Update component documentation
- Ensure all components have proper TypeScript types
- Add missing tests for new component structure
- Update Storybook stories if applicable
Quality Assurance
Validation Criteria
- No TODO comments in production code
- No legacy compatibility exports
- All components properly categorized according to atomic design
- Consistent naming conventions throughout
- Complete feature module implementations
- Proper separation of concerns between shared and business components
- All imports use new component locations
- No duplicate or redundant components
Testing Strategy
- Component unit tests for all refactored components
- Integration tests for feature modules
- Visual regression tests to ensure UI consistency
- Bundle size analysis to ensure no bloat from refactoring
- Performance testing to ensure no degradation
Risk Mitigation
Breaking Changes
- Gradual migration of imports to new locations
- Temporary compatibility exports during transition
- Comprehensive testing before removing old components
Performance Impact
- Bundle analysis to ensure tree-shaking works properly
- Code splitting verification for feature modules
- Loading performance monitoring during migration
Developer Experience
- Clear migration guide for team members
- Updated documentation for new component locations
- IDE support for new import paths
- Linting rules to enforce new patterns