THEME DUPLICATION CLEANUP PLAN

Comprehensive guidelines for AI-assisted development within the Editor platform

🚨 THEME DUPLICATION CLEANUP PLAN

⚠️ CRITICAL ISSUE IDENTIFIED

Extensive analysis reveals catastrophic duplication across theme libraries, causing:

📊 DUPLICATION SCOPE

IDENTICAL FILES (100% duplication):

PERFORMANCE IMPACT:

🎯 CLEANUP STRATEGY

Phase 1: Establish Source of Truth

Based on the migration architecture:

KEEP (Primary Sources):

DEPRECATE/REMOVE:

Phase 2: File Consolidation

SCSS Files → @theme-styles

# REMOVE duplicates from theme-engine:
libs/theme-engine/src/lib/styles/global.scss ❌ DELETE
libs/theme-engine/src/lib/styles/index.scss ❌ DELETE  
libs/theme-engine/src/lib/styles/ux-utilities.scss ❌ DELETE
libs/theme-engine/src/lib/styles/ux-variables.scss ❌ DELETE
libs/theme-engine/src/lib/styles/effects/ ❌ DELETE ENTIRE DIRECTORY
libs/theme-engine/src/lib/styles/utilities/ ❌ DELETE ENTIRE DIRECTORY
libs/theme-engine/src/lib/styles/mixins/ ❌ DELETE ENTIRE DIRECTORY

# KEEP only in theme-styles:
libs/theme-styles/src/lib/styles/global.scss ✅ KEEP
libs/theme-styles/src/lib/styles/index.scss ✅ KEEP

TypeScript Services → @theme-runtime

# REMOVE duplicates from theme-engine:
libs/theme-engine/src/lib/services/ ❌ DELETE ENTIRE DIRECTORY
libs/theme-engine/src/lib/utils-generators/ ❌ DELETE ENTIRE DIRECTORY

# KEEP only in theme-runtime:
libs/theme-runtime/src/lib/services/ ✅ KEEP
libs/theme-runtime/src/lib/utils-generators/ ✅ KEEP

Phase 3: Import Path Updates

Applications using theme-engine imports:

// BEFORE (duplicated):
import { ThemeManagerService } from 'libs/theme-engine';
import '@use libs/theme-engine/src/lib/styles/global.scss';

// AFTER (consolidated):
import { ThemeManagerService } from '@theme-runtime';
import '@use @theme-styles/global';

Search & Replace Commands:

# Update TypeScript imports:
find apps/ libs/ -name "*.ts" -exec sed -i '' 's|libs/theme-engine|@theme-runtime|g' {} \;
find apps/ libs/ -name "*.ts" -exec sed -i '' 's|theme-engine|@theme-runtime|g' {} \;

# Update SCSS imports:
find apps/ libs/ -name "*.scss" -exec sed -i '' 's|libs/theme-engine/src/lib/styles|@theme-styles|g' {} \;

Phase 4: Library Removal

Complete theme-engine Removal:

# Remove the entire theme-engine library:
rm -rf libs/theme-engine/

# Update workspace configuration:
# Remove theme-engine from:
# - tsconfig.base.json paths
# - nx.json projects
# - Any dependency references

🔧 IMPLEMENTATION STEPS

Step 1: Backup & Verification

# Create backup of current state:
cp -r libs/theme-engine/ backup/theme-engine-$(date +%Y%m%d)/
cp -r libs/theme-styles/ backup/theme-styles-$(date +%Y%m%d)/
cp -r libs/theme-runtime/ backup/theme-runtime-$(date +%Y%m%d)/

# Verify all theme libraries build:
npx nx build theme-runtime
npx nx build theme-styles  
npx nx build theme-dev-tools

Step 2: Import Path Migration

# Scan for all theme-engine usage:
grep -r "theme-engine" apps/ libs/ --exclude-dir=node_modules

# Update imports systematically:
find . -name "*.ts" -not -path "./node_modules/*" -exec grep -l "theme-engine" {} \; | \
  xargs sed -i '' 's|@theme-engine|@theme-runtime|g'

find . -name "*.scss" -not -path "./node_modules/*" -exec grep -l "theme-engine" {} \; | \
  xargs sed -i '' 's|theme-engine/src/lib/styles|@theme-styles|g'

Step 3: Build Verification

# Test all applications build correctly:
npx nx build ux-test
npx nx build editor-web  
npx nx build space-map
npx nx build docs-angular

# Test theme system still works:
npx nx serve ux-test --port 5300

Step 4: Clean Removal

# Remove theme-engine library:
rm -rf libs/theme-engine/

# Update workspace config:
# - Remove from tsconfig.base.json paths
# - Remove from package.json dependencies  
# - Update any remaining references

📊 EXPECTED BENEFITS

Bundle Size Reduction:

Performance Improvements:

Developer Experience:

⚠️ RISK MITIGATION

Safety Measures:

  1. Full backup before any changes
  2. Incremental migration (one app at a time)
  3. Build verification after each step
  4. Rollback plan (restore from backup)
  5. Testing theme functionality in each app

Rollback Strategy:

# If issues arise, restore from backup:
rm -rf libs/theme-runtime/ libs/theme-styles/
cp -r backup/theme-*-$(date +%Y%m%d)/ libs/
git checkout HEAD -- tsconfig.base.json

🚀 NEXT ACTIONS

IMMEDIATE (Today):

  1. ✅ Create this cleanup plan
  2. 🔄 Execute Step 1 (Backup & Verification)
  3. 🔄 Execute Step 2 (Import Path Migration)

THIS WEEK: 4. Execute Step 3 (Build Verification) 5. Execute Step 4 (Clean Removal) 6. Measure and document performance improvements

VALIDATION:


💡 WHY THIS HAPPENED

This duplication occurred because:

  1. Incomplete migration - Files were copied instead of moved
  2. No cleanup phase - Old duplicates weren't removed
  3. Missing validation - No duplicate detection in CI/CD
  4. Architectural ambiguity - Unclear which library owned what

This cleanup will complete the theme system consolidation and achieve the promised 89% bundle reduction that was advertised in the migration guide but never fully realized due to these duplications.