Assist_Design/CUSTOMER-DOMAIN-CLEANUP.md

117 lines
3.0 KiB
Markdown

# Customer Domain Cleanup Plan
## Problems Identified
### 1. Too Many Aliases
```typescript
// Current mess:
User, UserProfile, AuthenticatedUser // 3 names for same thing!
UserAuth, PortalUser // 2 names for same thing!
CustomerAddress, Address // 2 names for same thing!
CustomerData, CustomerProfile // CustomerProfile is manually defined, not from schema!
```
### 2. Manual Interface (BAD)
```typescript
// This bypasses schema-first approach!
export interface CustomerProfile {
id: string;
email: string;
// ... manually duplicated fields
}
```
### 3. Unnecessary Schema Type Exports
```typescript
export type CustomerAddressSchema = typeof customerAddressSchema; // Unused
export type CustomerSchema = typeof customerSchema; // Unused
// ... etc
```
### 4. Confusing Naming
- `Customer` = Full WHMCS customer schema (internal use only)
- `CustomerData` = Profile subset
- `CustomerProfile` = Duplicate manual interface (deprecated)
## Cleanup Plan
### Keep Only These Core Types:
```typescript
// === User Entity Types ===
UserAuth // Auth state from portal DB
User // Complete user (auth + profile)
// === WHMCS Data Types ===
CustomerAddress // Address structure
CustomerData // Profile data from WHMCS (internal provider use)
// === Supporting Types ===
CustomerEmailPreferences
CustomerUser // Sub-users
CustomerStats // Billing stats
AddressFormData // Form validation
// === Internal Provider Types ===
Customer // Full WHMCS schema (only used in WHMCS mapper)
// === Role ===
UserRole
```
### Remove These:
-`PortalUser` (use `UserAuth`)
-`UserProfile` (use `User`)
-`AuthenticatedUser` (use `User`)
-`CustomerProfile` interface (use `User` or `CustomerData`)
-`Address` alias (use `CustomerAddress`)
- ❌ All schema type exports (`CustomerAddressSchema`, etc.)
-`addressSchema` const alias (use `customerAddressSchema`)
## Implementation
### 1. Clean types.ts
Remove:
- All deprecated alias types
- Manual `CustomerProfile` interface
- Schema type exports
- `addressSchema` alias
### 2. Clean index.ts
Export only:
- Core types: `User`, `UserAuth`, `UserRole`
- Supporting types: `CustomerAddress`, `CustomerData`, `CustomerEmailPreferences`, `CustomerUser`, `CustomerStats`, `AddressFormData`
- Internal: `Customer` (for WHMCS mapper only)
### 3. Update BFF imports (only 9 occurrences!)
Replace any remaining:
- `CustomerProfile``User`
- Other deprecated → proper type
## Result: Clean & Clear
```typescript
// Customer Domain Exports (CLEAN!)
// === User Types ===
User // Complete user for APIs
UserAuth // Auth state for JWT
UserRole // "USER" | "ADMIN"
// === WHMCS Types ===
CustomerAddress // Address structure
CustomerData // Profile data (internal)
// === Supporting ===
CustomerEmailPreferences
CustomerUser
CustomerStats
AddressFormData
// === Internal ===
Customer // Full WHMCS schema (mapper only)
```
**No aliases. No confusion. Schema-first.**