The CSS & JS Minifier extension follows a modular architecture pattern that separates concerns into distinct layers for better maintainability, testability, and code reusability.
- Purpose: Clean activation/deactivation lifecycle management
- Responsibilities: Command registration, event listener setup, configuration management
- Size: Reduced from 220 → 81 lines (63% reduction)
- Purpose: VS Code command handlers and user interaction logic
- Components:
minifyCommand.ts- Unified command logic with processDocument() core functionindex.ts- Command exports with comprehensive documentation
- Purpose: Business logic and external API integrations
- Components:
minificationService.ts- Toptal API communication with error handlingfileService.ts- File system operations and filename utilitiesindex.ts- Service exports with module documentation
- Purpose: Reusable validation and utility functions
- Components:
validators.ts- File type and content validation with user feedbackindex.ts- Utility exports with module documentation
- Each module has a single responsibility
- Clear boundaries between UI logic, business logic, and utilities
- Easier to locate and modify specific functionality
- No duplicate validation or API logic between commands
- Shared utilities across different command handlers
- Consistent error handling patterns
- Pure functions easier to unit test
- Isolated business logic can be tested independently
- Mocking external dependencies is straightforward
- 63% reduction in main file complexity
- Self-documenting code with comprehensive JSDoc
- Clear module dependencies and exports
- IntelliSense support for all module functions
- Type safety with proper interfaces
- Consistent coding patterns throughout
User Action (Command/Keybinding/Context Menu)
↓
Command Handler (commands/minifyCommand.ts)
↓
Validation (utils/validators.ts)
↓
Minification Service (services/minificationService.ts)
↓
File Operations (services/fileService.ts)
↓
User Feedback (VS Code Notifications)
extension.ts
↓
commands/index.ts
↓
commands/minifyCommand.ts
↓
├── utils/validators.ts
├── services/minificationService.ts
└── services/fileService.ts
- Validation Layer: Input validation with user-friendly messages
- Service Layer: API error handling with retry logic and specific error codes
- Command Layer: Coordination and user notification
- Extension Layer: Global error catching and logging
- All errors show appropriate VS Code notifications
- Context-aware error messages (file type, network issues, API limits)
- Graceful degradation when services are unavailable
- All configuration accessed through
vscode.workspace.getConfiguration() - Settings validated at the point of use
- Default values provided for all optional settings
- Settings can be changed without extension restart
- Configuration changes take effect immediately
- Per-workspace and global configuration support
- Modules loaded only when needed
- Webpack bundling for optimal distribution size
- Tree shaking removes unused code
- Request debouncing for rapid user actions
- Response caching where appropriate
- Timeout handling for slow network conditions
- Service layer can be extended with new minification providers
- Command layer supports additional file types
- Validation layer can accommodate new file formats
- All user-facing strings externalized to
.nlsfiles - Message formatting prepared for multiple languages
- Locale-specific error handling
Last Updated: October 16, 2025 Extension Version: 1.0.0