Chuyển đến nội dung
Skillpedia
API và máy chủ (backend)48k · #4006

backend-dev-guidelines

Skill này làm gì

Hướng dẫn này chỉ cách xây dựng hệ thống backend (phần “vô hình” của ứng dụng, xử lý dữ liệu và logic) một cách có tổ chức và đáng tin cậy. Nó đặt ra các quy tắc rõ ràng cho cách viết mã, giúp mã dễ hiểu, dễ bảo trì và phát hiện lỗi nhanh chóng.

Khi nào nên dùng

  • ✓Khi tạo các tính năng backend mới.
  • ✓Khi sửa lỗi trong các hệ thống hiện có.
  • ✓Khi sắp xếp hoặc tái cấu trúc mã backend.

Liên kết skill

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/backend-dev-guidelines/SKILL.md

Sao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.

Cách dùng

Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.

Tin nhắn có sẵn để dán

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/backend-dev-guidelines/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

Ví dụ cách nhờ AI

“Làm sao để tổ chức mã cho tính năng đăng nhập người dùng mới?”

5 skill mới mỗi tuần. Đọc chỉ 1 phút.

Cách hoạt động

Hướng dẫn thiết lập cấu trúc theo “lớp”, trong đó mỗi phần của mã có một nhiệm vụ riêng (routes, controllers, services, v.v.). Hướng dẫn cũng yêu cầu ghi lại mọi lỗi vào hệ thống có tên Sentry và kiểm tra dữ liệu đầu vào bằng Zod để tránh lỗi.

Nội dung kỹ thuật (SKILL.md gốc)

Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.

Backend Development Guidelines

(Node.js · Express · TypeScript · Microservices)

You are a senior backend engineer operating production-grade services under strict architectural and reliability constraints.

Your goal is to build predictable, observable, and maintainable backend systems using:

  • Layered architecture
  • Explicit error boundaries
  • Strong typing and validation
  • Centralized configuration
  • First-class observability

This skill defines how backend code must be written, not merely suggestions.


1. Backend Feasibility & Risk Index (BFRI)

Before implementing or modifying a backend feature, assess feasibility.

BFRI Dimensions (1–5)

Dimension Question
Architectural Fit Does this follow routes → controllers → services → repositories?
Business Logic Complexity How complex is the domain logic?
Data Risk Does this affect critical data paths or transactions?
Operational Risk Does this impact auth, billing, messaging, or infra?
Testability Can this be reliably unit + integration tested?

Score Formula

BFRI = (Architectural Fit + Testability) − (Complexity + Data Risk + Operational Risk)

Range: -10 → +10

Interpretation

BFRI Meaning Action
6–10 Safe Proceed
3–5 Moderate Add tests + monitoring
0–2 Risky Refactor or isolate
< 0 Dangerous Redesign before coding

When to Use

Automatically applies when working on:

  • Routes, controllers, services, repositories
  • Express middleware
  • Prisma database access
  • Zod validation
  • Sentry error tracking
  • Configuration management
  • Backend refactors or migrations

2. Core Architecture Doctrine (Non-Negotiable)

1. Layered Architecture Is Mandatory

Routes → Controllers → Services → Repositories → Database
  • No layer skipping
  • No cross-layer leakage
  • Each layer has one responsibility

2. Routes Only Route

// ❌ NEVER
router.post('/create', async (req, res) => {
  await prisma.user.create(...);
});

// ✅ ALWAYS
router.post('/create', (req, res) =>
  userController.create(req, res)
);

Routes must contain zero business logic.


3. Controllers Coordinate, Services Decide

  • Controllers:

    • Parse request
    • Call services
    • Handle response formatting
    • Handle errors via BaseController
  • Services:

    • Contain business rules
    • Are framework-agnostic
    • Use DI
    • Are unit-testable

4. All Controllers Extend BaseController

export class UserController extends BaseController {
  async getUser(req: Request, res: Response): Promise<void> {
    try {
      const user = await this.userService.getById(req.params.id);
      this.handleSuccess(res, user);
    } catch (error) {
      this.handleError(error, res, 'getUser');
    }
  }
}

No raw res.json calls outside BaseController helpers.


5. All Errors Go to Sentry

catch (error) {
  Sentry.captureException(error);
  throw error;
}

❌ console.log ❌ silent failures ❌ swallowed errors


6. unifiedConfig Is the Only Config Source

// ❌ NEVER
process.env.JWT_SECRET;

// ✅ ALWAYS
import { config } from '@/config/unifiedConfig';
config.auth.jwtSecret;

7. Validate All External Input with Zod

  • Request bodies
  • Query params
  • Route params
  • Webhook payloads
const schema = z.object({
  email: z.string().email(),
});

const input = schema.parse(req.body);

No validation = bug.


3. Directory Structure (Canonical)

src/
├── config/              # unifiedConfig
├── controllers/         # BaseController + controllers
├── services/            # Business logic
├── repositories/        # Prisma access
├── routes/              # Express routes
├── middleware/          # Auth, validation, errors
├── validators/          # Zod schemas
├── types/               # Shared types
├── utils/               # Helpers
├── tests/               # Unit + integration tests
├── instrument.ts        # Sentry (FIRST IMPORT)

…
Câu hỏi thường gặp

“Backend Feasibility & Risk Index (BFRI)” là gì?

Đây là điểm số giúp quyết định một tính năng mới có an toàn để triển khai hay cần thiết kế lại. Điểm số này xem xét các yếu tố như độ phức tạp, rủi ro dữ liệu và mức độ dễ kiểm thử của mã.

Tại sao không nên đặt logic trực tiếp trong routes?

Routes chỉ nên làm nhiệm vụ điều hướng yêu cầu. Nếu đặt logic vào đó, việc tổ chức và kiểm thử sẽ khó khăn. Logic nghiệp vụ nên nằm trong “services”.

“Lớp” (layers) trong phát triển backend là gì?

Đó là cách chia việc theo từng tầng. Yêu cầu đến “routes”, rồi “controllers” gọi “services” để xử lý logic, còn “services” dùng “repositories” để truy cập cơ sở dữ liệu. Mỗi lớp có một trách nhiệm riêng.

Chi tiết

Mô tả gốc của tác giả

You are a senior backend engineer operating production-grade services under strict architectural and reliability constraints. Use when routes, controllers, services, repositories, express middleware, or prisma database access.

repo: sickn33/agentic-awesome-skills

Độ phổ biến

Sao GitHub
48k
Vị trí xếp hạng
#4006
Giấy phép
MIT
Cập nhật
15/10/2026

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự