[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M7ABJ6PE34YFCRF1FQTP45BY":3,"skill-same:01M7ABJ6PE34YFCRF1FQTP45BY":54},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":26,"commitSha":27,"skillDirectory":28,"forksCount":14,"repositoryHtmlUrl":29,"repositoryHomepageUrl":30,"ownerHtmlUrl":31,"ownerBlogUrl":32,"ownerDescription":6,"updatedAt":33,"install":34,"resources":47},"01M7ABJ6PE34YFCRF1FQTP45BY","nodejs-backend-patterns",null,"Node.js backend architecture: use when building or refactoring Fastify\u002FExpress services that need fail-fast schema validation, layered controller\u002Fservice\u002Frepository separation, pooled transactional data access, a single error envelope, or drain-based shutdown.","j0hanz\u002Fj0hanz-marketplace","j0hanz","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F159924955?v=4","01M7ABFK415CKHXYV9GZRJ16T7","Linus Johansson","01M7ABFK52FCPP2PNBH1YR7ZPA",0,"MIT","https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fnodejs\u002Fskills\u002Fnodejs-backend-patterns\u002FSKILL.md",[],[],"2026-11-15 14:19:17",false,"---\nname: nodejs-backend-patterns\ndescription: 'Node.js backend architecture: use when building or refactoring Fastify\u002FExpress services that need fail-fast schema validation, layered controller\u002Fservice\u002Frepository separation, pooled transactional data access, a single error envelope, or drain-based shutdown.'\nmetadata:\n  category: reference\n---\n\n# Node.js Backend Patterns\n\nOperational architecture guide for Node.js backends: `fail-fast` contracts, `layered` responsibilities, `pooled` data access, one `envelope`, graceful `drain`.\n\n## Stack Defaults\n\n- **Default**: Fastify + TypeScript + PostgreSQL (`pg`) + Zod + Pino.\n- **Express**: Use when integrating into existing Express middleware pipelines.\n- **MongoDB**: Use when document datastores are mandated by existing schema design.\n\n## Core Steps\n\n### 1. Define Boundary Contracts (`fail-fast`)\n\n- Type every public route with explicit schemas for params, query, body, and responses.\n- Validate at the HTTP layer; schema failures return 400 before reaching service logic.\n- **Completion criterion**: Every public route defines strict schemas and returns 400 on schema failure.\n\n### 2. Isolate Responsibilities (`layered`)\n\n- **Controller**: Parse HTTP requests, delegate to service, return HTTP response codes.\n- **Service**: Domain and business logic, authorization checks, transaction orchestration.\n- **Repository**: Raw SQL\u002Fqueries, data mapping, direct database pool interactions.\n- Wire components using constructor-based dependency injection.\n- **Completion criterion**: Every controller handles transport only (no SQL\u002FDB imports); every service handles domain logic only (no HTTP request\u002Fresponse imports).\n\n### 3. Manage Connections & Transactions (`pooled`)\n\n- Configure database connection pools with explicit max connections, idle timeouts, and connection timeouts.\n- Wrap multi-operation writes in atomic transactions (`BEGIN` \u002F `COMMIT` \u002F `ROLLBACK`).\n- Release checked-out pool clients in `finally` blocks.\n- **Completion criterion**: Every multi-statement write runs in a transaction that rolls back on error; every checked-out pool client is released on all execution paths.\n\n### 4. Standardize Responses & Errors (`envelope`)\n\n- Use a single top-level error handler mapping typed `AppError` subclasses to status codes.\n- Return one JSON envelope for success (`{ status: \"success\", data }`) and failure (`{ status: \"error\", code, message }`); sanitize messages in production.\n- **Completion criterion**: Every request-scoped error passes through the global error handler and returns the failure envelope with a sanitized message.\n\n### 5. Wire Process Lifecycle (`drain`)\n\n- Bind `SIGTERM` and `SIGINT` to a coordinated shutdown handler.\n- Stop accepting new HTTP requests, drain in-flight requests within a grace timeout (e.g., 10s), then close DB pools and cache connections.\n- Keep the force-exit timer unref'd so it never holds the event loop open.\n- **Completion criterion**: Application exits with code 0 on termination signal after in-flight connections drain and pools close.\n\n## Disclosed Reference\n\nImplementation blueprints — schema definitions, DI container, pool configuration, transaction helper, error handler, shutdown handler — in [`resources\u002Fimplementation-playbook.md`](resources\u002Fimplementation-playbook.md). Load when implementing any step.\n","# Node.js Backend Patterns\n\nOperational architecture guide for Node.js backends: `fail-fast` contracts, `layered` responsibilities, `pooled` data access, one `envelope`, graceful `drain`.\n\n## Stack Defaults\n\n- **Default**: Fastify + TypeScript + PostgreSQL (`pg`) + Zod + Pino.\n- **Express**: Use when integrating into existing Express middleware pipelines.\n- **MongoDB**: Use when document datastores are mandated by existing schema design.\n\n## Core Steps\n\n### 1. Define Boundary Contracts (`fail-fast`)\n\n- Type every public route with explicit schemas for params, query, body, and responses.\n- Validate at the HTTP layer; schema failures return 400 before reaching service logic.\n- **Completion criterion**: Every public route defines strict schemas and returns 400 on schema failure.\n\n### 2. Isolate Responsibilities (`layered`)\n\n- **Controller**: Parse HTTP requests, delegate to service, return HTTP response codes.\n- **Service**: Domain and business logic, authorization checks, transaction orchestration.\n- **Repository**: Raw SQL\u002Fqueries, data mapping, direct database pool interactions.\n- Wire components using constructor-based dependency injection.\n- **Completion criterion**: Every controller handles transport only (no SQL\u002FDB imports); every service handles domain logic only (no HTTP request\u002Fresponse imports).\n\n### 3. Manage Connections & Transactions (`pooled`)\n\n- Configure database connection pools with explicit max connections, idle timeouts, and connection timeouts.\n- Wrap multi-operation writes in atomic transactions (`BEGIN` \u002F `COMMIT` \u002F `ROLLBACK`).\n- Release checked-out pool clients in `finally` blocks.\n- **Completion criterion**: Every multi-statement write runs in a transaction that rolls back on error; every checked-out pool client is released on all execution paths.\n\n### 4. Standardize Responses & Errors (`envelope`)\n\n- Use a single top-level error handler mapping typed `AppError` subclasses to status codes.\n- Return one JSON envelope for success (`{ status: \"success\", data }`) and failure (`{ status: \"error\", code, message }`); sanitize messages in production.\n- **Completion criterion**: Every request-scoped error passes through the global error handler and returns the failure envelope with a sanitized message.\n\n### 5. Wire Process Lifecycle (`drain`)\n\n- Bind `SIGTERM` and `SIGINT` to a coordinated shutdown handler.\n- Stop accepting new HTTP requests, drain in-flight requests within a grace timeout (e.g., 10s), then close DB pools and cache connections.\n- Keep the force-exit timer unref'd so it never holds the event loop open.\n- **Completion criterion**: Application exits with code 0 on termination signal after in-flight connections drain and pools close.\n\n## Disclosed Reference\n\nImplementation blueprints — schema definitions, DI container, pool configuration, transaction helper, error handler, shutdown handler — in [`resources\u002Fimplementation-playbook.md`](resources\u002Fimplementation-playbook.md). Load when implementing any step.\n",{"name":5,"metadata":24,"description":7},{"category":25},"reference","main","534498267dccbe415f22f31fceac9da6771c195f","plugins\u002Fnodejs\u002Fskills\u002Fnodejs-backend-patterns","https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace","https:\u002F\u002Fj0hanz-marketplace.vercel.app","https:\u002F\u002Fgithub.com\u002Fj0hanz","linus-johansson-cv-d308be9b73e1.herokuapp.com","2026-11-15 02:42:07",{"source":8,"skillName":5,"commands":35,"prompt":45,"zipAvailable":46},[36,39,42],{"tool":37,"command":38},"npx","npx skills add j0hanz\u002Fj0hanz-marketplace --skill nodejs-backend-patterns",{"tool":40,"command":41},"bunx","bunx skills add j0hanz\u002Fj0hanz-marketplace --skill nodejs-backend-patterns",{"tool":43,"command":44},"pnpm","pnpm dlx skills add j0hanz\u002Fj0hanz-marketplace --skill nodejs-backend-patterns","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fnodejs\u002Fskills\u002Fnodejs-backend-patterns\u002FSKILL.md",true,[48],{"path":49,"resourceType":50,"resourceTypeDesc":51,"sizeBytes":52,"sourceHtmlUrl":53},"resources\u002Fimplementation-playbook.md","REFERENCE","参考文档",8465,"https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fnodejs\u002Fskills\u002Fnodejs-backend-patterns\u002Fresources\u002Fimplementation-playbook.md",[55,62,69,76,83,90],{"skillNo":56,"name":57,"nameZh":6,"description":58,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":59,"categories":60,"keywords":61,"publishedAt":19},"01M7ABP78JFYBMCXJ9GMETCYZM","unslop","Use when writing or editing prose a person will read, or when text sounds AI-generated.","https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fwriteup\u002Fskills\u002Funslop\u002FSKILL.md",[],[],{"skillNo":63,"name":64,"nameZh":6,"description":65,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":66,"categories":67,"keywords":68,"publishedAt":19},"01M7ABP52BNV7NRPNBR6PCNZWC","show-me","Use when asked to show, diagram, or walk through how code fits together or what a change does, or before explaining a multi-file flow in prose.","https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fwriteup\u002Fskills\u002Fshow-me\u002FSKILL.md",[],[],{"skillNo":70,"name":71,"nameZh":6,"description":72,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":73,"categories":74,"keywords":75,"publishedAt":19},"01M7ABP3EPN4KFB4HPJNMY31NR","pr","Use when writing or updating a pull request description, or before running `gh pr create`.","https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fwriteup\u002Fskills\u002Fpr\u002FSKILL.md",[],[],{"skillNo":77,"name":78,"nameZh":6,"description":79,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":19},"01M7ABP08MXTHPZYTG4HKEP7WQ","commit","Use when writing a commit message, or before running `git commit`.","https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fwriteup\u002Fskills\u002Fcommit\u002FSKILL.md",[],[],{"skillNo":84,"name":85,"nameZh":6,"description":86,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":87,"categories":88,"keywords":89,"publishedAt":19},"01M7ABNV9J7DN1AFRBGDBHVBY2","write-specs","Spec a feature's observable behavior. Use when asked for requirements, when a request says what the system should do but not how, or to capture what a built system already guarantees. Not for how to build it (write-plan).","https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fworkbench\u002Fskills\u002Fwrite-specs\u002FSKILL.md",[],[],{"skillNo":91,"name":92,"nameZh":6,"description":93,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":94,"categories":95,"keywords":96,"publishedAt":19},"01M7ABNPK2GVG8EB3SSEAMK4FZ","write-skills","Write, fix, or audit a skill's frontmatter, trigger description, and body. Use when a skill is asked for, never fires, or fires at the wrong moment. Not for a hook (write-hooks) or the plugin manifest and catalog.","https:\u002F\u002Fgithub.com\u002Fj0hanz\u002Fj0hanz-marketplace\u002Fblob\u002Fmain\u002Fplugins\u002Fworkbench\u002Fskills\u002Fwrite-skills\u002FSKILL.md",[],[]]