NoteMesh/
├── index.html # Main HTML file
├── style.css # All CSS styles and responsive design
├── app.js # Main application entry point (23 lines)
├── script/ # Modular JavaScript files
│ ├── models/
│ │ └── Note.js # Note data model (84 lines)
│ ├── managers/
│ │ ├── NoteManager.js # Note operations and storage (178 lines)
│ │ ├── ThemeManager.js# Theme switching logic (40 lines)
│ │ └── UIManager.js # UI interactions and rendering (850 lines)
│ ├── utils/ # Utility modules
│ │ ├── DateUtils.js # Date and time utilities (104 lines)
│ │ ├── StringUtils.js # String manipulation utilities (87 lines)
│ │ ├── ArrayUtils.js # Array and collection utilities (67 lines)
│ │ ├── StorageUtils.js# LocalStorage utilities (66 lines)
│ │ ├── DOMUtils.js # DOM manipulation utilities (81 lines)
│ │ ├── FileUtils.js # File and export utilities (44 lines)
│ │ ├── ValidationUtils.js # Input validation utilities (45 lines)
│ │ ├── PerformanceUtils.js # Performance optimization utilities (49 lines)
│ │ ├── ColorUtils.js # Color generation and manipulation (46 lines)
│ │ └── index.js # Utility modules index (8 lines)
│ └── graph/ # Graph visualization modules
│ ├── GraphConfig.js # Graph configuration constants (41 lines)
│ ├── GraphPhysics.js# Physics simulation engine (102 lines)
│ ├── GraphEventHandler.js # Event handling for graph (127 lines)
│ ├── GraphRenderUtils.js # Rendering utilities (254 lines)
│ └── GraphRenderer.js # Main graph renderer (254 lines)
├── app-backup.js # Original monolithic app.js (1,142 lines - backup)
├── utils.js # Original utils.js (599 lines - backup)
└── graph.js # Original graph.js (726 lines - backup)
- Purpose: Data model for individual notes
- Key Features:
- Note creation and serialization
- Link extraction (
[[Note Title]]format) - Word count calculation
- Tag parsing and management
- Search matching logic
- Purpose: Handles all note operations and persistence
- Key Features:
- CRUD operations (Create, Read, Update, Delete)
- LocalStorage persistence
- Search and filtering
- Tag management and statistics
- Note linking and backlinks
- Event system for UI updates
- Import/export functionality
- Purpose: Manages light/dark theme switching
- Key Features:
- Theme toggle functionality
- LocalStorage persistence
- Icon updates for theme state
- Programmatic theme setting
- Purpose: Handles all UI interactions and rendering
- Key Features:
- DOM element initialization
- Event binding and handling
- View switching (Notes, Graph, Tags)
- Modal management
- Mobile responsive behavior
- Search interface
- Keyboard shortcuts
- Notification system
- Purpose: Application initialization and coordination
- Key Features:
- Creates manager instances
- Initializes the application
- Global exports for debugging
- Module coordination
The scripts must be loaded in this specific order:
utils.js- Utility functionsgraph.js- Graph visualizationjs/models/Note.js- Data modeljs/managers/NoteManager.js- Data managementjs/managers/ThemeManager.js- Theme systemjs/managers/UIManager.js- UI managementapp.js- Application initialization
User Interaction
↓
UIManager (handles events)
↓
NoteManager (processes data)
↓
Note Model (data operations)
↓
LocalStorage (persistence)
↓
UIManager (updates display)
- Identify which module the feature belongs to
- Update the appropriate module
- Add any necessary UI components to UIManager
- Test the feature in isolation
- Ensure all modules still work together
- Use the event system in NoteManager for data changes
- Pass data through method parameters
- Avoid direct DOM manipulation outside UIManager
- Keep state management centralized
This modular architecture makes NoteMesh much more maintainable and easier to extend! 🚀
- Purpose: Data model for individual notes
- Key Functions: generateId(), extractLinks(), serialize(), deserialize()
- Dependencies: None (standalone model)
- Purpose: Handles all note operations and persistence
- Key Functions: addNote(), updateNote(), searchNotes(), event system
- Dependencies: Note.js, StorageUtils.js
- Purpose: Manages light/dark theme switching
- Key Functions: toggleTheme(), applyTheme(), updateThemeToggleIcon()
- Dependencies: StorageUtils.js
- Purpose: Handles all user interface interactions
- Key Functions: renderNotes(), mobile navigation, keyboard shortcuts
- Dependencies: NoteManager.js, ThemeManager.js, multiple utils
- Functions: formatDate(), getRelativeTime(), isToday(), isThisWeek()
- Use Cases: Note timestamps, relative time display
- Functions: escapeHtml(), truncate(), highlightSearchTerm(), wordCount()
- Use Cases: Text processing, search highlighting, security
- Functions: unique(), groupBy(), sortBy(), chunk()
- Use Cases: Note filtering, tag management, data organization
- Functions: setItem(), getItem(), removeItem(), clear()
- Use Cases: Safe localStorage operations with error handling
- Functions: createElement(), addEventListenerWithCleanup(), isInViewport()
- Use Cases: Dynamic UI creation, memory-safe events
- Functions: downloadAsFile(), readAsText(), formatFileSize()
- Use Cases: Note export/import, file handling
- Functions: isValidEmail(), isValidUrl(), isEmpty(), isValidLength()
- Use Cases: Input validation, data sanitization
- Functions: debounce(), throttle(), measureTime()
- Use Cases: Search optimization, event rate limiting
- Functions: randomHex(), stringToColor(), isLightOrDark()
- Use Cases: Tag colors, theme detection
- Purpose: Visual and physics configuration constants
- Contains: Node styling, edge styling, physics parameters
- Purpose: Force simulation engine for node positioning
- Key Function: updatePhysics() - handles repulsion, attraction, damping
- Purpose: Mouse/touch interaction handling
- Key Functions: onMouseDown(), onMouseMove(), onWheel(), touch events
- Purpose: Canvas drawing and rendering utilities
- Key Functions: renderNodes(), renderEdges(), renderUI(), text utilities
- Purpose: Main graph coordination and public API
- Key Functions: generateGraph(), startAnimation(), refresh(), zoomToFit()
This comprehensive modularization represents a best-practice software architecture that:
- Follows Single Responsibility Principle - Each module has one clear purpose
- Enables Easy Testing - Modules can be tested in isolation
- Supports Future Growth - New features can be added without disrupting existing code
- Promotes Code Reuse - Utilities and components are highly reusable
- Improves Debugging - Issues can be quickly isolated to specific modules
- Enhances Collaboration - Multiple developers can work on different modules
- Reduces Merge Conflicts - Smaller, focused files mean fewer conflicts