# DSS MCP Plugin - Strategic Analysis & Architecture Review **Date:** December 9, 2024 **Phase:** Post-Phase 1 Implementation (Storybook Integration Complete) **Purpose:** Deep thinking on architecture alignment, workflow validation, and next steps --- ## Executive Summary After completing Phase 1 (Storybook Integration) via Zen Swarm methodology, a deep architectural review reveals critical insights that should inform our path forward: ###πŸ” Key Findings: 1. **Translation Dictionaries are NOT implemented** in DSS Python core (only documented in principles) 2. **"Skins" concept may be misaligned** with actual DSS architecture 3. **Phase 2/3 implementation plan needs refinement** based on what's actually in the codebase 4. **Workflow validation is critical** before proceeding to Phase 2 --- ## 1. Current Architecture State ### DSS Python Core (`dss-mvp1/dss/`) ``` dss/ β”œβ”€β”€ βœ… storybook/ # Scanner, generator, theme (MCP Phase 1 COMPLETE) β”‚ β”œβ”€β”€ scanner.py # StorybookScanner - scan existing stories β”‚ β”œβ”€β”€ generator.py # StoryGenerator - generate CSF3/CSF2/MDX stories β”‚ β”œβ”€β”€ theme.py # ThemeGenerator - create Storybook themes β”‚ └── config.py # Configuration utilities β”‚ β”œβ”€β”€ βœ… themes/ # Default light/dark themes (FULLY IMPLEMENTED) β”‚ └── default_themes.py # get_default_light_theme(), get_default_dark_theme() β”‚ β”œβ”€β”€ βœ… ingest/ # Multi-source token extraction (COMPLETE) β”‚ β”œβ”€β”€ css.py # CSSTokenSource β”‚ β”œβ”€β”€ scss.py # SCSSTokenSource β”‚ β”œβ”€β”€ tailwind.py # TailwindTokenSource β”‚ β”œβ”€β”€ json_tokens.py # JSONTokenSource β”‚ └── merge.py # TokenMerger β”‚ β”œβ”€β”€ βœ… tools/ # External tool integrations β”‚ β”œβ”€β”€ figma.py # FigmaWrapper (MCP tools exist) β”‚ β”œβ”€β”€ shadcn.py # ShadcnWrapper (no MCP tools yet) β”‚ └── style_dictionary.py # StyleDictionaryWrapper (no MCP tools yet) β”‚ β”œβ”€β”€ βœ… analyze/ # Code analysis and scanning β”‚ β”œβ”€β”€ scanner.py # ProjectScanner β”‚ β”œβ”€β”€ react.py # ReactAnalyzer β”‚ β”œβ”€β”€ quick_wins.py # QuickWinFinder β”‚ └── styles.py # StyleAnalyzer β”‚ β”œβ”€β”€ βœ… export_import/ # Project export/import β”‚ β”œβ”€β”€ exporter.py # Export project data β”‚ β”œβ”€β”€ importer.py # Import project data β”‚ └── merger.py # Merge strategies β”‚ β”œβ”€β”€ βœ… models/ # Data structures β”‚ β”œβ”€β”€ theme.py # Theme, DesignToken, TokenCategory β”‚ β”œβ”€β”€ component.py # Component, ComponentVariant β”‚ └── project.py # Project, ProjectMetadata β”‚ β”œβ”€β”€ ❌ translations/ # MISSING - Not implemented! β”‚ └── (no files) # Translation dictionaries are documented but not coded β”‚ └── βœ… storage/ # SQLite persistence └── database.py # get_connection(), Project/Token storage ``` ### MCP Plugin Layer (`tools/dss_mcp/`) ``` tools/dss_mcp/ β”œβ”€β”€ server.py # FastAPI + SSE server β”œβ”€β”€ handler.py # Unified tool router β”œβ”€β”€ integrations/ β”‚ β”œβ”€β”€ base.py # BaseIntegration, CircuitBreaker β”‚ β”œβ”€β”€ figma.py # βœ… 5 Figma tools (COMPLETE) β”‚ └── storybook.py # βœ… 5 Storybook tools (Phase 1 COMPLETE) β”œβ”€β”€ tools/ β”‚ β”œβ”€β”€ project_tools.py # βœ… 7 project management tools β”‚ β”œβ”€β”€ workflow_tools.py # βœ… Workflow orchestration β”‚ └── debug_tools.py # βœ… Debug utilities └── context/ └── project_context.py # Project context management ``` --- ## 2. Critical Discovery: Translation Dictionaries Don't Exist ### What the Principles Document Says: From `DSS_PRINCIPLES.md`: ``` project-acme/ β”œβ”€β”€ .dss/ β”‚ β”œβ”€β”€ config.json β”‚ └── translations/ β”‚ β”œβ”€β”€ figma.json # Figma β†’ DSS mappings β”‚ β”œβ”€β”€ legacy-css.json # Legacy CSS β†’ DSS mappings β”‚ └── custom.json # Custom props specific to ACME ``` ### What Actually Exists: **NOTHING.** There is no Python module for: - Reading translation dictionaries - Writing translation dictionaries - Applying translation dictionaries - Validating translation dictionaries - Merging custom props **Impact:** Phase 2 "Skin Management" tools cannot be implemented as planned because the underlying Python functionality doesn't exist. --- ## 3. The "Skin" vs "Theme" Confusion ### What the Implementation Plan Assumes: **Phase 2: Skin/Theme Management** - `theme_list_skins` - List available skins - `theme_get_skin` - Get skin details - `theme_create_skin` - Create new skin - `theme_apply_skin` - Apply skin to project - `theme_export_tokens` - Export tokens **Assumption:** "Skins" are first-class objects stored somewhere. ### What the Codebase Actually Has: **Themes:** Only 2 base themes exist: - `get_default_light_theme()` - Returns `Theme` object - `get_default_dark_theme()` - Returns `Theme` object **No "Skins":** The concept of client-specific "skins" is NOT implemented. ### What "Skins" SHOULD Be (Based on Principles): A "skin" is: 1. **Base Theme** (light or dark) 2. **+ Translation Dictionary** (legacy β†’ DSS mappings) 3. **+ Custom Props** (client-specific extensions) **Reality:** Without translation dictionary implementation, "skins" cannot be created. --- ## 4. Workflow Validation Analysis ### Target Workflow 1: Import from Figma βœ… ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ WORKFLOW 1: Import from Figma β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ 1. figma_fetch_file(fileKey) βœ… Works β”‚ β”‚ 2. figma_extract_tokens(fileId) βœ… Works β”‚ β”‚ 3. figma_import_components(fileId) βœ… Works β”‚ β”‚ 4. Store tokens in database βœ… Works β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Status: FULLY FUNCTIONAL Gaps: None ``` ### Target Workflow 2: Load Skins into Storybook 🟑 ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ WORKFLOW 2: Load Skins into Storybook β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ 1. storybook_scan(projectId) βœ… Phase 1β”‚ β”‚ 2. Get client "skin" configuration ❌ BLOCKEDβ”‚ β”‚ β†’ No translation dictionary support β”‚ β”‚ 3. Merge base theme + custom props ❌ BLOCKEDβ”‚ β”‚ β†’ No merge logic exists β”‚ β”‚ 4. storybook_generate_theme(tokens) βœ… Phase 1β”‚ β”‚ 5. Load Storybook with theme βœ… Phase 1β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Status: 60% FUNCTIONAL Gaps: Translation dictionary system, custom props merger ``` **Current Capability:** Can generate Storybook theme from base DSS theme **Missing:** Cannot apply client-specific customizations ### Target Workflow 3: Apply Design to Project ❌ ``` β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ WORKFLOW 3: Apply Design to Project β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€ β”‚ 1. Load project configuration ❌ BLOCKEDβ”‚ β”‚ β†’ No translation dictionary support β”‚ β”‚ 2. Resolve tokens (DSS + custom) ❌ BLOCKEDβ”‚ β”‚ β†’ No token resolution logic β”‚ β”‚ 3. Generate output files (CSS/SCSS) 🟑 PARTIALβ”‚ β”‚ β†’ style-dictionary exists but no MCP tools β”‚ β”‚ 4. Update component imports ❌ BLOCKEDβ”‚ β”‚ β†’ No component rewrite logic β”‚ β”‚ 5. Validate application ❌ BLOCKEDβ”‚ β”‚ β†’ No validation against translations β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ Status: 10% FUNCTIONAL Gaps: Complete translation dictionary system, token resolution, code generation ``` --- ## 5. What Needs to Be Built ### Foundation Layer (Critical - Build First) **Translation Dictionary System** - NOT IMPLEMENTED ```python # Needs to be created in dss-mvp1/dss/translations/ dss/translations/ β”œβ”€β”€ __init__.py β”œβ”€β”€ dictionary.py # TranslationDictionary class β”œβ”€β”€ mapping.py # TokenMapping, ComponentMapping β”œβ”€β”€ loader.py # Load from .dss/translations/*.json β”œβ”€β”€ writer.py # Write dictionary files β”œβ”€β”€ merger.py # Merge base theme + custom props β”œβ”€β”€ validator.py # Validate dictionary schema └── resolver.py # Resolve token paths (e.g., "color.primary.500") Core Functionality: - Load translation dictionaries from project .dss/translations/ - Parse mappings: { "--brand-blue": "color.primary.500" } - Resolve token references - Merge custom props into base theme - Validate mappings against DSS canonical structure - Write/update dictionary files ``` **Without this, Phase 2 and Phase 3 cannot be completed.** ### Phase 2 (Depends on Translation Dictionary System) **Skin/Theme Management** - Should be renamed to **"Project Theme Configuration"** Tools should actually do: 1. `theme_list_themes` - List available base themes (light/dark) 2. `theme_get_config` - Get project's theme configuration (.dss/config.json) 3. `theme_set_base` - Set project's base theme (light/dark) 4. `theme_add_custom_prop` - Add custom token to project (.dss/translations/custom.json) 5. `theme_export_resolved` - Export fully resolved tokens (base + custom + translations) ### Phase 3 (Depends on Both Above) **Design Application** - Generate output files Tools need: 1. `design_resolve_tokens` - Resolve all tokens for project (DSS + translations + custom) 2. `design_generate_css` - Generate CSS variables file 3. `design_generate_scss` - Generate SCSS variables file 4. `design_update_imports` - Rewrite component imports 5. `design_validate` - Validate that all tokens are mapped --- ## 6. Strategic Options ### Option A: Build Translation Dictionary System First ⭐ RECOMMENDED **Approach:** 1. Pause MCP tool development 2. Build `dss.translations` Python module (foundation layer) 3. Test translation dictionary loading/merging 4. Then resume MCP tool implementation with correct architecture **Pros:** - Aligns with DSS core principles - Enables real workflows - Solid foundation for Phase 2/3 **Cons:** - Delays MCP completion by 2-3 days - Requires core DSS architecture work ### Option B: Simplified Phase 2 (No Translation Dictionaries) **Approach:** 1. Implement Phase 2 tools WITHOUT translation dictionary support 2. Tools only work with base themes 3. Custom props come later **Pros:** - Faster MCP completion - Some functionality better than none **Cons:** - Doesn't align with DSS principles - Will need refactoring later - Can't achieve target workflows ### Option C: Skip to Phase 3 (Code Generation Only) **Approach:** 1. Skip Phase 2 entirely 2. Implement Phase 3 code generation tools 3. Generate CSS/SCSS from base themes only **Pros:** - Tangible output (actual CSS files) - Tests style-dictionary integration **Cons:** - Still blocked by translation dictionary gap - Workflows incomplete --- ## 7. Recommendations ### Immediate Actions: 1. **Validate Phase 1 with Simple Test** - Test storybook_scan on dss-mvp1 project - Test storybook_generate_theme with base light theme - Confirm tools actually work end-to-end 2. **Decide on Translation Dictionary Architecture** - Should it be Python module or keep as JSON-only? - Who owns the schema validation? - How do custom props extend base themes? 3. **Refine Phase 2/3 Plan** - Update tool definitions based on actual DSS architecture - Remove "skin" terminology, use "project theme configuration" - Add translation dictionary tools if we build that module ### Long-term Strategy: **Path 1: Minimal MCP (Fast)** - Complete Phase 2/3 without translation dictionaries - Basic theme application only - Good for demo, limited for production **Path 2: Complete DSS (Correct)** ⭐ RECOMMENDED - Build translation dictionary foundation - Implement Phase 2/3 properly aligned with principles - Full workflow support, production-ready --- ## 8. Questions for Architectural Decision 1. **Should we build the translation dictionary Python module?** - If yes: Who implements it? (Core team vs. MCP team) - If no: How do we achieve the documented DSS principles? 2. **What is the actual definition of a "skin"?** - Is it base theme + translation dictionary? - Or is it just a preset of custom props? - Should we rename to avoid confusion? 3. **Can we ship Phase 1 alone as MVP?** - Figma import + Storybook generation works - Workflow 1 is complete - Is that enough value? 4. **Should Phases 2/3 wait for translation dictionary implementation?** - Or build simplified versions now? - Trade-offs between speed and correctness? --- ## 9. Conclusion **We're at a critical architectural decision point.** Phase 1 (Storybook) is production-ready, but Phases 2-3 cannot be properly implemented without the translation dictionary foundation layer that's documented in principles but not coded. **Two Paths Forward:** 1. **Fast Path:** Complete MCP with simplified tools (no translation dictionaries) - Timeline: 2-3 days - Result: Partial workflow support, will need refactoring 2. **Correct Path:** Build translation dictionary system first, then complete MCP - Timeline: 5-7 days - Result: Full workflow support, aligned with DSS principles **My Recommendation:** Choose the Correct Path. Build the foundation right. --- **Next Step:** User decision on which path to take.