Knowder Library Development Rules
You are helping develop "Knowder" - a lightweight JavaScript library for displaying engaging facts during loading states. The primary goal is to transform user frustration during loading into engagement while maintaining exceptional performance.
Core Principles (NON-NEGOTIABLE)
1. Bundle Size Supremacy
**HARD LIMIT**: <5KB gzipped final bundleEvery byte matters - question every characterUse bundlesize tool to verify on every buildNO external runtime dependencies (zero dependencies rule)Vanilla JavaScript only - no frameworks2. Performance First
Initialization must be <50msMemory usage must stay <1MBMaintain 60fps animationsCPU impact <1% during idleUse native CSS transitions/animations onlyOptimize for browser rendering engine3. Developer Experience Excellence
API must be intuitive (max 3 main methods)Zero configuration should work out of boxFramework agnostic designComprehensive documentation with examplesClear error messages and graceful degradationTechnical Constraints
Code Style & Patterns
Use ES6+ features (target modern browsers only)Prefer functional programming patterns where possibleUse singleton pattern for main APIImplement proper error handling and input validationComment complex logic thoroughlyUse JSDoc for all public methodsDOM Manipulation Rules
Use native DOM APIs only (no jQuery)Minimize DOM queries and mutationsUse documentFragment for complex DOM operationsImplement proper cleanup to prevent memory leaksRespect user accessibility preferencesAnimation Guidelines
CSS transitions/animations only (no JavaScript animations)Use transform and opacity for GPU accelerationRespect prefers-reduced-motion media queryKeep animations smooth and non-jarringAim for 60fps performanceFile Organization
```
src/
├── core/
│ ├── factLoader.js # Main API class
│ ├── factStorage.js # Data management
│ └── display.js # DOM/animation engine
├── data/
│ └── defaultFacts.js # Default fact database
└── index.js # Public API exports
```
Development Workflow
Testing Requirements
Maintain 90%+ test coverageWrite tests before implementing features (TDD)Test in multiple browsers (Chrome, Firefox, Safari, Edge)Include accessibility testingPerformance regression testingCode Quality Gates
1. All tests must pass
2. Bundle size must be <5KB gzipped
3. ESLint must pass with zero warnings
4. No console.log statements in production code
5. Proper JSDoc documentation for all public APIs
Git Commit Guidelines
Use conventional commit formatInclude bundle size impact in commit messagesReference TODO items being completedSmall, focused commitsAPI Design Rules
Public API Surface
```javascript
// Main methods (keep to 3 maximum)
Knowder.init(options) // Initialize with config
Knowder.start(category) // Start displaying facts
Knowder.stop() // Stop and cleanup
// Utility methods (minimal)
Knowder.addFacts(category, facts) // Add custom facts
Knowder.getCategories() // List categories
```
Configuration Schema
Use sensible defaults for everythingMake all options optionalValidate input and provide clear error messagesSupport both programmatic and declarative configurationError Handling Strategy
Never crash the host applicationUse console.warn for non-critical errorsProvide fallback behavior for all scenariosClear error messages with suggested fixesContent Guidelines
Default Facts Criteria
Must be genuinely interesting and surprisingKeep under 140 characters for readabilityVerify accuracy before inclusionEnsure cultural sensitivity and inclusivityCategorize appropriately (general, science, tech, history)Fact Quality Standards
Prefer "did you know" style revelationsInclude credible sources in commentsAvoid controversial or sensitive topicsMake facts universally understandableTest readability with diverse audiencesBrowser Support Strategy
Supported Browsers
Chrome 88+ (ES6 modules, modern CSS)Firefox 78+ (similar feature support)Safari 14+ (WebKit parity)Edge 88+ (Chromium-based)Feature Detection
Use feature detection over browser detectionGraceful degradation for unsupported featuresNo polyfills (to maintain zero dependencies)Progressive enhancement approachBuild & Distribution Rules
Build Process
Use Rollup.js for optimal tree shakingGenerate both ESM and UMD buildsAggressive minification with TerserSource maps for debuggingAutomated bundle analysisQuality Assurance
Run bundlesize check on every buildLighthouse performance auditsCross-browser automated testingAccessibility compliance verificationSecurity vulnerability scanningDocumentation Standards
Code Documentation
JSDoc for all public methods and classesInclude usage examples in commentsDocument performance characteristicsExplain design decisions in complex codeUser Documentation
Quick start guide with working examplesComplete API referenceFramework integration examplesTroubleshooting guidePerformance best practicesCode Review Checklist
When suggesting or reviewing code, always verify:
[ ] Bundle size impact assessed[ ] Performance implications considered[ ] Error handling implemented[ ] Tests written/updated[ ] Documentation updated[ ] Accessibility verifiedCritical Questions
1. "Does this add unnecessary bytes to the bundle?"
2. "Could this impact performance negatively?"
3. "Is this the simplest possible solution?"
4. "Does this maintain backward compatibility?"
5. "Is this accessible to all users?"
Emergency Protocols
If Bundle Size Exceeds Limit
1. STOP all development
2. Analyze what caused the increase
3. Remove/optimize offending code
4. Consider if feature is essential
5. Document decision rationale
If Performance Regresses
1. Identify the performance bottleneck
2. Use browser dev tools to profile
3. Optimize the critical path
4. Add performance test to prevent regression
5. Update performance documentation
Success Metrics to Track
Technical Metrics
Bundle size trendInitialization timeMemory usage patternTest coverage percentageDocumentation completenessUser Experience Metrics
API ease of useDeveloper onboarding timeIntegration complexityCommunity feedback sentimentBug report frequencyRemember
Every decision should be evaluated through the lens of performance, simplicity, and developer experience. When in doubt, choose the solution that maintains the smallest bundle size and clearest API.