This directory contains the refactored, modular version of the WebUI assets.
✅ constants.js - API URLs, localStorage keys, default values ✅ state.js - Global application state (models, chat history, settings) ✅ dom.js - DOM element references and initialization ✅ helpers.js - Utility functions (debounce, localStorage, formatting)
✅ variables.css - CSS custom properties for theming ✅ base.css - Reset, typography, global styles
static/
├── README.md (this file)
├── QUICKSTART.md (how to use the modules)
├── js/
│ ├── constants.js
│ ├── state.js
│ ├── dom.js
│ ├── helpers.js
│ ├── models/ (create these as you migrate)
│ ├── ui/
│ ├── chat/
│ ├── api/
│ └── logs/
└── css/
├── variables.css
├── base.css
├── components/ (create these as you migrate)
└── features/
Keep webui.js and webui.css working, gradually extract modules:
-
Create
static/js/main.jsthat imports from both old and new:// Import new modules import { state } from "./state.js"; import { dom, initializeDOMReferences } from "./dom.js"; // Keep old webui.js functions temporarily // Gradually move them to modules
-
Update functions one at a time
-
Test after each change
-
Remove old files when done
-
Update
index.html:<!-- OLD --> <link rel="stylesheet" href="webui.css" /> <script src="webui.js" defer></script> <!-- NEW --> <link rel="stylesheet" href="static/css/main.css" /> <script type="module" src="static/js/main.js"></script>
-
Create
static/css/main.css:@import "./variables.css"; @import "./base.css"; /* Import other CSS modules as you create them */
-
Create
static/js/main.js(see QUICKSTART.md for example)
| Before | After |
|---|---|
| 1 file, 1500+ lines | 10-15 files, ~150 lines each |
| Hard to find things | Clear organization |
| No IDE autocomplete | Full autocomplete support |
| Global namespace pollution | Clean imports |
| Hard to test | Easy unit testing |
| Merge conflicts | Parallel development |
- Read
QUICKSTART.mdfor detailed usage examples - Read
INTEGRATION.mdfor HTML integration guide - Read
../REFACTORING.mdfor the full migration plan - Start extracting feature modules (models, chat, ui, api, logs)
- Test after each module extraction
- Update HTML to use new modular imports
- Remove old monolithic files when migration complete
function loadModelList() {
// 50 lines of tightly coupled code
// Uses global variables
// Hard to test
}import { state } from "../state.js";
import { dom } from "../dom.js";
export async function loadModelList() {
// Same logic, but:
// - Clear dependencies
// - Easy to test
// - Reusable
}| File | Before | Target After |
|---|---|---|
| webui.js | ~1500 lines | Deleted |
| webui.css | ~1600 lines | Deleted |
| Total | 3100 lines | ~150 lines/file × 20 files |
- Create directory structure
- Extract constants.js
- Extract state.js
- Extract dom.js
- Extract helpers.js
- Create CSS variables.css
- Create CSS base.css
- Create main.js entry point
- Extract models/* modules
- Extract chat/* modules
- Extract ui/* modules
- Extract api/* modules
- Extract logs/* modules
- Create remaining CSS modules
- Test all functionality
- Remove old files
- Update documentation
- Check
QUICKSTART.mdfor usage examples - Check
../REFACTORING.mdfor detailed migration plan - Each module file has JSDoc comments
- Use ES6 imports/exports throughout
- Keep modules small - Max 200 lines per file
- One responsibility - Each module does one thing well
- Clear imports - Always import what you need
- Test independently - Write unit tests for each module
- Document well - Use JSDoc comments
Happy refactoring! 🚀