Node.js Project Architecture
by @abczsl520
Node.js project architecture standards for AI-assisted development. Enforces file splitting (<400 lines), config externalization, route modularization, and a...
clawhub install nodejs-project-archπ About This Skill
name: nodejs-project-arch description: Node.js project architecture standards for AI-assisted development. Enforces file splitting (<400 lines), config externalization, route modularization, and admin dashboards. Use when creating new Node.js projects, refactoring large single-file codebases, or when AI context window is being consumed by oversized files. Covers H5 games (Canvas/Phaser/Matter.js), data tools (crawlers/scrapers), content platforms, monitoring dashboards, API services, and SDK libraries.
Node.js Project Architecture for AI-Friendly Development
Architecture standards that keep files small enough for AI agents to read/edit without blowing the context window.
Core Rules
index.html max 200 lines, server.js entry max 100 linesconfig.json, loaded at runtime, editable via admin dashboardroutes/ by domain, services/ for shared logic, db.js for databaseadmin.html + routes/admin.js for config hot-reloadProject Type Selection
Determine project type, then read the corresponding reference:
| Type | Signals | Reference | |------|---------|-----------| | H5 Game | Canvas, Phaser, Matter.js, game loop, sprites | references/game.md | | Data Tool | Crawler, scraper, scheduler, data sync, analytics | references/tool.md | | Content/Utility | Generator, library, publisher, file processing | references/tool.md | | Dashboard/Monitor | Charts, real-time, alerts, metrics | references/tool.md | | API Service | REST endpoints, middleware, microservice | references/tool.md | | SDK/Library | Shared module, build step, multi-consumer | references/sdk.md |
Quick Start (All Types)
1. Identify project type from table above
2. Read the corresponding reference file
3. Create directory structure per the reference
4. Extract hardcoded values β config.json
5. Split large files by function (each <400 lines)
6. Add routes/admin.js + admin.html
7. Frontend: config.js fetches /api/config at startup, code reads GAME_CONFIG.xxx or APP_CONFIG.xxx
8. Test locally β backup β deploy
config.json Pattern (Universal)
// Server: load and serve config
const config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
app.get('/api/config', (req, res) => {
const safe = { ...config };
delete safe.admin; // strip secrets
res.json(safe);
});// Admin: hot-reload
app.post('/admin/config', requireAdmin, (req, res) => {
fs.writeFileSync('./config.json.bak', fs.readFileSync('./config.json'));
fs.writeFileSync('./config.json', JSON.stringify(req.body, null, 2));
Object.assign(config, req.body);
res.json({ ok: true });
});
Admin Dashboard Pattern (Universal)
admin.html auto-generates form from config structure:
x-admin-password header)Why This Matters
Large single files consume massive context tokens when AI reads them: