- 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.
284 lines
7.9 KiB
Markdown
284 lines
7.9 KiB
Markdown
# 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
|
|
|
|
```typescript
|
|
// 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
|
|
|
|
```typescript
|
|
// 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
|
|
|
|
```typescript
|
|
// 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
|
|
|
|
```typescript
|
|
// 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
|
|
|
|
```typescript
|
|
// 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
|
|
|
|
```typescript
|
|
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
|
|
|
|
```typescript
|
|
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
|
|
|
|
1. **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)
|
|
|
|
2. **Create migration plan** for moving components to correct locations
|
|
|
|
### Step 2: Legacy Code Cleanup
|
|
|
|
1. **Remove all TODO comments** that represent incomplete work
|
|
2. **Complete or remove** disabled exports
|
|
3. **Remove legacy compatibility** code
|
|
4. **Standardize naming** conventions throughout
|
|
|
|
### Step 3: Feature Module Completion
|
|
|
|
1. **Move business components** to appropriate feature modules
|
|
2. **Complete feature module** implementations
|
|
3. **Ensure proper encapsulation** of business logic
|
|
4. **Create proper public APIs** for features
|
|
|
|
### Step 4: Component Standardization
|
|
|
|
1. **Standardize component structure** across all components
|
|
2. **Ensure consistent exports** and imports
|
|
3. **Add missing index files** where needed
|
|
4. **Update all import statements** to use new locations
|
|
|
|
### Step 5: Documentation and Testing
|
|
|
|
1. **Update component documentation**
|
|
2. **Ensure all components have proper TypeScript types**
|
|
3. **Add missing tests** for new component structure
|
|
4. **Update Storybook stories** if applicable
|
|
|
|
## Quality Assurance
|
|
|
|
### Validation Criteria
|
|
|
|
1. **No TODO comments** in production code
|
|
2. **No legacy compatibility** exports
|
|
3. **All components properly categorized** according to atomic design
|
|
4. **Consistent naming conventions** throughout
|
|
5. **Complete feature module** implementations
|
|
6. **Proper separation of concerns** between shared and business components
|
|
7. **All imports use new component locations**
|
|
8. **No duplicate or redundant components**
|
|
|
|
### Testing Strategy
|
|
|
|
1. **Component unit tests** for all refactored components
|
|
2. **Integration tests** for feature modules
|
|
3. **Visual regression tests** to ensure UI consistency
|
|
4. **Bundle size analysis** to ensure no bloat from refactoring
|
|
5. **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 |