AgentSkillsCN

backend-dev-guidelines

Node.js/Express/TypeScript 后端服务的常见模式(分层、校验、配置、监控、测试)。关键词:后端、API、Express、Node、TypeScript、服务模式。

SKILL.md
--- frontmatter
name: backend-dev-guidelines
description: "Backend service patterns for Node.js/Express/TypeScript (layering, validation, config, monitoring, testing). Keywords: backend, api, express, node, typescript, service patterns."

Backend Development Guidelines (Node.js / Express / TypeScript)

This skill collects reusable backend patterns for services built with Node.js, Express, and TypeScript.


Purpose

  • Establish a consistent structure for backend services.
  • Reduce bugs by separating concerns (routing vs business logic vs data access).
  • Make failures observable (error tracking + structured logs).
  • Make changes testable (clear boundaries, predictable inputs/outputs).

When to Use

Use this skill when working on:

  • Routes / controllers / request handlers
  • Service-layer business logic
  • Repository/data-access patterns (e.g., Prisma)
  • Middleware (auth, validation, error boundaries)
  • Configuration management
  • Monitoring/error tracking and performance spans
  • Testing and refactoring backend code

Quick Start

New endpoint checklist

  • Route: defines HTTP method + path + middleware only
  • Controller: parses input, validates, calls service, formats response
  • Service: implements business logic; no HTTP knowledge
  • Repository: encapsulates DB access and query construction (when non-trivial)
  • Validation: schema-validated inputs (e.g., Zod)
  • Monitoring: capture exceptions and add key spans
  • Tests: unit tests for service/repo; integration tests for route

New service checklist

  • src/config/ centralized config loading/validation
  • src/middleware/ includes auth + request context + error boundary
  • src/routes/ delegates to controllers
  • src/controllers/ follows a consistent error-handling pattern
  • Monitoring is initialized early in process startup

Core principles (high signal)

  1. Routes only route (no business logic in routes)
  2. Controllers handle HTTP, services handle business rules
  3. Validate all external inputs (params/body/query)
  4. Centralize configuration (avoid scattered process.env access in app code)
  5. Capture and contextualize errors (monitoring + structured logs)
  6. Repositories for complex DB access (avoid scattered queries)
  7. Test at the right layer (fast unit tests + targeted integration tests)

Related Skills

Need to…Skill
Understand layered architecturearchitecture-overview
Build routes + controllersrouting-and-controllers
Structure services + repositoriesservices-and-repositories
Validate inputsvalidation-patterns
Add monitoring / error trackingsentry-and-monitoring
Create middlewaremiddleware-guide
Database access patternsdatabase-patterns
Configuration patternsconfiguration
Async + error patternsasync-and-errors
Testing strategytesting-guide
End-to-end examplescomplete-examples