✓ Verified 💻 Development ✓ Enhanced Data

Nodejs Project Arch

AI-friendly Node.js architecture — keep files under 400 lines for 70-93% token savings.

Rating
4.9 (85 reviews)
Downloads
9,976 downloads
Version
1.0.0

Overview

AI-friendly Node.js architecture — keep files under 400 lines for 70-93% token savings.

Complete Documentation

View Source →

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

  • Single file max 400 lines, index.html max 200 lines, server.js entry max 100 lines
  • All tunable values in config.json, loaded at runtime, editable via admin dashboard
  • Backend: routes/ by domain, services/ for shared logic, db.js for database
  • Frontend: HTML skeleton only, JS/CSS in separate files
  • Every project gets admin.html + routes/admin.js for config hot-reload

Project Type Selection

Determine project type, then read the corresponding reference:

TypeSignalsReference
H5 GameCanvas, Phaser, Matter.js, game loop, spritesreferences/game.md
Data ToolCrawler, scraper, scheduler, data sync, analyticsreferences/tool.md
Content/UtilityGenerator, library, publisher, file processingreferences/tool.md
Dashboard/MonitorCharts, real-time, alerts, metricsreferences/tool.md
API ServiceREST endpoints, middleware, microservicereferences/tool.md
SDK/LibraryShared module, build step, multi-consumerreferences/sdk.md

Quick Start (All Types)

  • Identify project type from table above
  • Read the corresponding reference file
  • Create directory structure per the reference
  • Extract hardcoded values → config.json
  • Split large files by function (each <400 lines)
  • Add routes/admin.js + admin.html
  • Frontend: config.js fetches /api/config at startup, code reads GAME_CONFIG.xxx or APP_CONFIG.xxx
  • Test locally → backup → deploy

config.json Pattern (Universal)

javascript
// 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:

  • Password login (x-admin-password header)
  • Visual config editor with save + hot-reload
  • Stats overview (users/data/uptime)
  • Config backup history + restore

Why This Matters

Large single files consume massive context tokens when AI reads them:

  • 3000-line file → ~40K tokens per read (20% of 200K window)
  • 200-line module → ~2.7K tokens per read (1.3% of window)
  • Result: 10-15 productive rounds vs 3-5 before context compression

Installation

Terminal bash

openclaw install nodejs-project-arch
    
Copied!

💻Code Examples

example.js
// 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 });
});

Tags

#coding_agents-and-ides

Quick Info

Category Development
Model Claude 3.5
Complexity One-Click
Author abczsl520
Last Updated 3/10/2026
🚀
Optimized for
Claude 3.5
🧠

Ready to Install?

Get started with this skill in seconds

openclaw install nodejs-project-arch