This project has been refactored to follow best practices with a modular component-based architecture.
non-react-app/
βββ index.html # Main HTML entry point (minimal, loads components)
βββ main.js # Main JavaScript entry point (orchestrates app initialization)
βββ src/
β βββ components/ # Component modules (separated by concern)
β β βββ button/
β β β βββ button.html # Button component markup
β β β βββ button.css # Button-specific styles
β β β βββ (no JS needed) # Static component
β β βββ dialog/
β β β βββ dialog.html # Dialog component markup
β β β βββ dialog.css # Dialog-specific styles
β β β βββ dialog.js # Dialog initialization logic
β β βββ sidebar/
β β βββ sidebar.html # Sidebar navigation markup
β β βββ sidebar.css # Sidebar-specific styles
β β βββ sidebar.js # Navigation logic
β βββ styles/
β β βββ base.css # Base styles, theme variables, layout
β β βββ global.css # Global styles (imported from main.js)
β βββ utils/
β βββ loadComponent.js # Utility to dynamically load HTML partials
β βββ theme.js # Theme switching functionality
βββ package.json
βββ PROJECT_STRUCTURE.md # This file
Each component is isolated in its own directory with:
- HTML - Component markup
- CSS - Component-specific styles
- JS - Component-specific logic (if needed)
- Each component is self-contained
- Components can be easily added, removed, or modified
- No tight coupling between components
- JavaScript modules use ES6 imports/exports
- Each module has a single responsibility
- Utility functions are separated from component logic
index.htmlis minimal and clean- Component HTML is loaded dynamically
- Styles are organized and imported separately
- index.html loads with basic structure and style imports
- main.js initializes:
- Web components library
- Theme system
- Component loader
- Component HTML files are dynamically loaded into containers
- Component JavaScript initializes interactivity after HTML loads
To add a new component (e.g., "card"):
-
Create component directory:
src/components/card/ -
Create component files:
card.html- Component markupcard.css- Component stylescard.js- Component logic (if needed)
-
Import styles in index.html:
<link rel="stylesheet" href="/src/components/card/card.css" />
-
Load component in main.js:
import { initCard } from './src/components/card/card.js'; await loadComponents([ // ... existing components { url: '/src/components/card/card.html', target: '#content-container' } ]); initCard(); // Initialize after HTML loads
-
Add navigation link (if needed) in sidebar.html:
<li class="nav-item"> <a class="nav-link" data-section="cards">Cards</a> </li>
β Maintainability - Easy to find and modify specific components β Scalability - Simple to add new components without affecting existing ones β Reusability - Components can be easily reused or extracted β Testability - Each module can be tested independently β Collaboration - Multiple developers can work on different components β Performance - Components can be lazy-loaded as needed β Clean Code - Clear organization following industry best practices
- Single Responsibility Principle - Each file/module has one clear purpose
- Don't Repeat Yourself (DRY) - Shared utilities are extracted
- Separation of Concerns - HTML, CSS, and JS are properly separated
- Modular Design - Components are independent and self-contained
- Clear Naming - Descriptive file and function names
- Documentation - Code comments explain purpose and usage