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:
- 2-4x bundle bloat (35,566 SCSS lines with massive duplicates)
- Performance degradation (styles loaded multiple times)
- Maintenance complexity (changes needed in multiple places)
- CSS conflicts (specificity wars between identical styles)
📊 DUPLICATION SCOPE
IDENTICAL FILES (100% duplication):
global.scss(498 lines) - theme-engine + theme-stylesindex.scss(97 lines) - theme-engine + theme-stylesux-utilities.scss(55 lines) - theme-engine + theme-stylesux-variables.scss(49 lines) - theme-engine + theme-stylestheme-scss-generator.service.ts- theme-engine + theme-runtime- 47 additional SCSS files with identical content
- 8 different index.scss files across libraries
PERFORMANCE IMPACT:
- Estimated 60-70% of theme SCSS code is duplicated
- Bundle sizes 2-4x larger than necessary
- CSS loading conflicts causing layout thrashing
🎯 CLEANUP STRATEGY
Phase 1: Establish Source of Truth
Based on the migration architecture:
KEEP (Primary Sources):
@theme-runtime→ Services, TypeScript logic, core functionality@theme-styles→ SCSS files, visual effects, utilities@theme-dev-tools→ Development components only
DEPRECATE/REMOVE:
libs/theme-engine→ ENTIRE LIBRARY (redundant with theme-styles + theme-runtime)
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:
- Before: 35,566 SCSS lines (with 60-70% duplication)
- After: ~12,000-15,000 SCSS lines (single source of truth)
- Savings: ~58-65% reduction in theme CSS bundle size
Performance Improvements:
- ✅ Faster build times (no duplicate processing)
- ✅ Smaller bundles (no duplicate CSS)
- ✅ Reduced CSS conflicts (single source of styles)
- ✅ Better tree-shaking (cleaner dependency graph)
Developer Experience:
- ✅ Single source of truth for theme modifications
- ✅ Consistent imports across the workspace
- ✅ Reduced maintenance (change once vs. multiple places)
- ✅ Clearer architecture (purpose-specific libraries)
⚠️ RISK MITIGATION
Safety Measures:
- Full backup before any changes
- Incremental migration (one app at a time)
- Build verification after each step
- Rollback plan (restore from backup)
- 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):
- ✅ Create this cleanup plan
- 🔄 Execute Step 1 (Backup & Verification)
- 🔄 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:
- Bundle size analysis (before/after)
- Performance testing across all apps
- Full regression testing of theme system
💡 WHY THIS HAPPENED
This duplication occurred because:
- Incomplete migration - Files were copied instead of moved
- No cleanup phase - Old duplicates weren't removed
- Missing validation - No duplicate detection in CI/CD
- 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.