Skip to content

Tiêu Chuẩn Code & Hướng Dẫn

Dự ÁnPTX Channel Manager (ptx-cm)
Phiên Bản2.0.0
Cập Nhật2026-02-20

1. Nguyên Tắc Dự Án

YAGNI - You Aren't Gonna Need It Không xây dựng tính năng trước khi cần. Tránh over-engineering.

KISS - Keep It Simple, Stupid Ưu tiên giải pháp đơn giản hơn các abstraction phức tạp.

DRY - Don't Repeat Yourself Trích xuất logic chung vào helper, service hoặc tiện ích.


2. Quy Ước Đặt Tên

File & Thư Mục

Ngữ CảnhMẫuVí Dụ
TypeScript/JavaScriptkebab-casecountry-scope.guard.ts, api-client.ts
Thư mụckebab-caseota-accounts/, room-mappings/
File testname.spec.tsauth.service.spec.ts
DTOPascalCase + hậu tố DtoCreatePropertyDto, ListBookingsDto
InterfacePascalCase + tiền tố I tùy chọnOtaAdapter hoặc IOtaAdapter
ClassPascalCaseAuthService, PropertyController
EnumPascalCaseUserRole, AlertSeverity
Hằng sốUPPER_SNAKE_CASEALLOWED_COUNTRIES, JWT_EXPIRY
Bảng databasesnake_case (Prisma)ota_accounts, refresh_tokens
Cột databasesnake_casepassword_hash, is_active

Hàm & Phương Thức

typescript
// ✓ Tốt: Động từ + danh từ, mô tả rõ ràng
async fetchBookingsFromOta(otaType: string): Promise<Booking[]>
function assertPropertyAccess(prisma, propertyId, countryScope?): Property
function validateSortByField(field: string, allowedFields: string[]): void

// ✗ Xấu: Viết tắt, mục đích không rõ
async getB(type: string): Promise<any>
function checkProp(id: string): void

Biến

typescript
// ✓ Tốt: Mô tả, không viết tắt không cần thiết
const refreshTokenExpiry = '7d';
const MAX_RETRY_ATTEMPTS = 3;
let availableRooms = totalRooms - bookedRooms;

// ✗ Xấu: Một chữ cái, viết tắt
const rt = '7d';
const max_retries = 3;
let avail = total - booked;

3. Tổ Chức File & Giới Hạn Kích Thước

File Code: Tối Đa 200 Dòng

Mục tiêu: Giữ file tập trung và dễ điều hướng.

Chiến lược chia tách:

  • 200-400 dòng: Cân nhắc chia thành 2-3 file tập trung
  • 400+ dòng: PHẢI chia tách ngay lập tức

Ví dụ chia tách service lớn:

ota-accounts/
├── ota-accounts.service.ts         # CRUD (150 dòng)
├── ota-accounts.controller.ts      # Endpoint
├── ota-account-discovery.service.ts # Logic discovery & import (120 dòng)
├── ota-credential.helper.ts        # Mã hóa/giải mã (80 dòng)
├── dto/
│   ├── create-ota-account.dto.ts
│   └── list-ota-accounts.dto.ts
└── ota-accounts.module.ts

File Tài Liệu: Tối Đa 800 Dòng

Mục tiêu: Giữ tài liệu dễ bảo trì và đọc.

Chiến lược chia tách:

  • 800-1200 dòng: Tạo thư mục chủ đề với index + phần
  • 1200+ dòng: PHẢI chia tách

4. Tài Liệu Liên Quan

Tài LiệuNội Dung
code-standards-backend.mdMẫu NestJS, bảo mật, xử lý lỗi, DB/Prisma, testing
code-standards-frontend.mdMẫu Next.js/React, API client, Git commit, hiệu suất
system-architecture.mdSơ đồ kiến trúc và luồng
codebase-summary.mdCấu trúc dự án và phụ thuộc
API_SPEC.mdTham khảo REST API endpoint
DB_DESIGN.mdSchema database và index

PTX Channel Manager — Tài Liệu Nội Bộ