Skip to content

abczsl520/nodejs-project-arch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

5 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ—๏ธ nodejs-project-arch

AI-friendly Node.js project architecture standards

Keep every file under 400 lines. Save 70-93% tokens. Get 3x more productive AI rounds.

ClawHub GitHub stars License: MIT

Install ยท Game Arch ยท Tool Arch ยท SDK Arch ยท Wiki


๐Ÿคฏ The Problem

AI agents working with large codebases hit the context window wall fast:

3000-line server.js  โ†’  ~40K tokens per read  โ†’  20% of context gone
After 3-5 rounds     โ†’  context compression   โ†’  agent forgets everything

โœ… The Solution

Split by function. Each file stays small. AI reads only what it needs:

200-line module      โ†’  ~2.7K tokens per read  โ†’  1.3% of context
After 10-15 rounds   โ†’  still going strong     โ†’  no compression needed

Real-World Token Savings

Scenario Before After Savings
Read one game feature 40K tokens 2.7K tokens 93%
Full dev round (readโ†’editโ†’verify) 52K tokens 4K tokens 92%
4-round SDK session 196K tokens 69K tokens 65%
Large data tool module 84K tokens 8K tokens 90%

๐Ÿ“ Core Rules

โœ… Single file        โ‰ค 400 lines
โœ… index.html         โ‰ค 200 lines
โœ… server.js (entry)  โ‰ค 100 lines
โœ… Tunable values     โ†’ config.json (hot-reloadable)
โœ… Backend            โ†’ routes/ by domain + services/ for shared logic
โœ… Frontend           โ†’ HTML skeleton + separate JS/CSS files
โœ… Every project      โ†’ admin.html + routes/admin.js

๐ŸŽฎ H5 Game

game-name/
  server.js            โ† Entry, routes only (<100 lines)
  config.json          โ† Gameplay values (admin can edit live)
  routes/
    auth.js            โ† Login/user
    game.js            โ† Game data API
    social.js          โ† Leaderboard/sharing
    admin.js           โ† Admin API + config CRUD
  public/
    index.html         โ† HTML skeleton (<200 lines)
    admin.html         โ† Admin dashboard
    css/style.css
    js/
      config.js        โ† Fetch config at startup
      game.js          โ† Core game logic
      renderer.js      โ† Rendering/visuals
      ui.js            โ† UI interactions
      audio.js         โ† Sound effects
    assets/

๐Ÿ”ง Data Tool / API / Dashboard

project-name/
  server.js            โ† Entry (<100 lines)
  config.json          โ† API keys, schedules, thresholds
  db.js                โ† DB init + helpers
  routes/
    api.js             โ† Query/export API
    task.js            โ† Task management
    admin.js           โ† Admin API
  services/
    crawler.js         โ† Business logic
    scheduler.js       โ† Cron/intervals
  public/
    index.html         โ† HTML skeleton (<200 lines)
    admin.html         โ† Admin dashboard
    css/style.css
    js/
      app.js           โ† Main logic
      table.js         โ† Table rendering
      api.js           โ† Fetch wrapper

๐Ÿ“ฆ SDK/Library

sdk-name/
  src/                 โ† Source modules (<200 lines each)
    core.js / auth.js / api.js / ui.js
  sdk-name.js          โ† Built output (merged single file)
  build.js             โ† Simple merge script
  test/test.html       โ† Test page
  CHANGELOG.md

Dev in src/ (small files for AI) โ†’ build merges into single file for consumers.

๐Ÿ”‘ config.json Pattern

// Load + serve (strip secrets)
const config = JSON.parse(fs.readFileSync('./config.json', 'utf8'));
app.get('/api/config', (req, res) => {
  const safe = { ...config };
  delete safe.admin;
  res.json(safe);
});

// Admin hot-reload (no restart needed)
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

Every project gets admin.html:

  • ๐Ÿ” Password login (x-admin-password header)
  • โš™๏ธ Visual config editor with save + hot-reload
  • ๐Ÿ“Š Stats overview (users / data / uptime)
  • ๐Ÿ“‹ Config backup history + one-click restore

๐Ÿš€ Installation

OpenClaw / ClawHub

clawhub install nodejs-project-arch

Manual

git clone https://github.com/abczsl520/nodejs-project-arch.git
cp -r nodejs-project-arch ~/.agents/skills/

The skill auto-activates when you ask your AI to:

  • "Create a new Node.js project"
  • "Refactor this large codebase"
  • "Split this file, it's too big"

๐Ÿ“– Documentation

Full docs on the Wiki:

Page Description
Game Architecture H5 game standards + WeChat compatibility
Tool Architecture Data tools, dashboards, API services
SDK Architecture Libraries with build step
Config Pattern Universal config.json pattern
Admin Dashboard Admin panel standards
Token Savings Detailed savings analysis

๐Ÿ”— Part of the AI Dev Quality Suite

Skill Purpose Install
bug-audit Dynamic bug hunting, 200+ pitfall patterns clawhub install bug-audit
codex-review Three-tier code review with adversarial testing clawhub install codex-review
debug-methodology Root-cause debugging, prevents patch-chaining clawhub install debug-methodology
nodejs-project-arch (this) AI-friendly architecture, 70-93% token savings clawhub install nodejs-project-arch
game-quality-gates 12 universal game dev quality checks clawhub install game-quality-gates

๐Ÿค Works With

  • OpenClaw โ€” AI agent framework
  • ClawHub โ€” Skill marketplace
  • Any AI coding agent (Claude, GPT, Codex, Gemini...)

๐Ÿ“„ License

MIT โ€” use it, fork it, improve it.


If this saves you tokens, give it a โญ

About

๐Ÿ—๏ธ AI-friendly Node.js project architecture standards. Keep files <400 lines for AI agents. Covers H5 games, data tools, APIs, SDKs. 70-93% token savings. OpenClaw skill.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors