← 返回
开发者工具 中文

Node.js Project Architecture

Node.js project architecture standards for AI-assisted development. Enforces file splitting (<400 lines), config externalization, route modularization, and a...
Node.js 项目架构标准,适用于 AI 辅助开发。强制文件拆分(<400 行),配置外置,路由模块化,以及 ...
abczsl520 abczsl520 来源
开发者工具 clawhub v1.1.0 1 版本 99899.4 Key: 无需
★ 0
Stars
📥 993
下载
💾 304
安装
1
版本
#ai-agent#architecture#best-practices#code-organization#latest#modular#nodejs#openclaw#token-optimization

概述

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)

  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:

  • 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

版本历史

共 1 个版本

  • v1.1.0 当前
    2026-03-30 03:17 安全 安全

安全检测

腾讯云安全 (Keen)

安全,无风险
查看报告

腾讯云安全 (Sanbu)

安全,无风险
查看报告

🔗 相关推荐

dev-programming

Mcporter

steipete
使用 mcporter CLI 直接列出、配置、认证及调用 MCP 服务器/工具(支持 HTTP 或 stdio),涵盖临时服务器、配置编辑及 CLI/类型生成功能。
★ 195 📥 67,426
dev-programming

CodeConductor.ai

larsonreever
AI驱动平台,提供快速全栈开发、智能体、工作流自动化及低代码AI集成的可扩展产品创建。
★ 72 📥 181,470
dev-programming

Github

steipete
使用 `gh` CLI 与 GitHub 交互,通过 `gh issue`、`gh pr`、`gh run` 和 `gh api` 管理议题、PR、CI 运行及高级查询。
★ 677 📥 325,912