BackSpec
AGENTS.md1 starsChanged 45 days agoMITView on GitHub
Đọc theo thứ tự: CONSTITUTION.md → CLAUDE.md → file này → .sdd/specs/ Khi thêm hoặc chỉnh sửa endpoint API:
- Reads credentials
Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.
Of the AGENTS.md files we read, the 31,774 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository83 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- adopt-repoSkill
- agent-strict-guardSkill
- analyze-featureSkill
- backend-api-design-flowSkill
- clean-code-naming-conventionsSkill
- code-review-gateSkill
- dangerous-action-blockerSkill
- database-transaction-managementSkill
- db-interface-procedure-flowSkill
- db-migrationSkill
- defensive-troubleshooting-guideSkill
- git-workflowSkill
- human-authority-overrideSkill
- human-master-mapSkill
- implement-featureSkill
- jpa-n-plus-one-optimizationSkill
- knowledge-graphSkill
- multi-language-error-handlingSkill
- post-code-verificationSkill
- project-doctorSkill
- project-governance-dashboardSkill
- redis-cache-patternsSkill
- release-notesSkill
- safe-git-rebaseSkill
- security-secret-scannerSkill
- speckit-analyzeSkill
- speckit-auditSkill
- speckit-checklistSkill
- speckit-clarifySkill
- speckit-constitutionSkill
- speckit-helpSkill
- speckit-implementSkill
- speckit-ingestSkill
- speckit-planSkill
- speckit-specifySkill
- speckit-tasksSkill
- spec-writerSkill
- spring-middleware-pipelineSkill
- sql-repository-patternSkill
- system-dna-managerSkill
- test-featureSkill
- adopt-repoSkill
- agent-strict-guardSkill
- analyze-featureSkill
- backend-api-design-flowSkill
- clean-code-naming-conventionsSkill
- code-review-gateSkill
- dangerous-action-blockerSkill
- database-transaction-managementSkill
- db-interface-procedure-flowSkill
- db-migrationSkill
- defensive-troubleshooting-guideSkill
- git-workflowSkill
- human-authority-overrideSkill
- human-master-mapSkill
- implement-featureSkill
- jpa-n-plus-one-optimizationSkill
- knowledge-graphSkill
- multi-language-error-handlingSkill
- The first 60 shown.
The file
We split this AGENTS.md into the rules it gives an agent
1 rule. About 0 are common, 0 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 45
KHÔNG: commit trực tiếp vào branch bảo vệ (main, master, production).
≈ “Common” is an estimate: at least 1 in 5 of the 40,246 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
AGENTS.md — {{SERVICE_NAME}} (Backend Microservice)
Đọc theo thứ tự: CONSTITUTION.md → CLAUDE.md → file này → .sdd/specs/
1. PROJECT OVERVIEW
Service: {{SERVICE_NAME}} Domain: Backend Microservice (Distributed Systems) Mục tiêu chính: {{Mô tả ngắn gọn chức năng của microservice này trong toàn hệ thống}}
2. KIẾN TRÚC & NGUYÊN TẮC THIẾT KẾ
2.1. API & Event Standard
- REST API prefix
/api/v1/[resource]. - Response chuẩn:
{ "status": 200, "message": "...", "data": ... }. - Lỗi xử lý tập trung qua Global Exception Handler theo chuẩn RFC 7807.
- Event Message tuân theo định dạng CloudEvents tiêu chuẩn.
2.2. DTO Pattern (BẮT BUỘC)
Entity ──mapping──► DTO (Request/Response) ──► API / Kafka
│ ▲
└── Service Layer ◄─────┘2.3. Ranh giới Microservice & Trách nhiệm
| Trách nhiệm | Microservice Backend | Edge Gateway / Client |
| Business logic, tính toán nghiệp vụ | ✅ BẮT BUỘC | ❌ CẤM |
| Xác thực Token & Context | ✅ Validate & Authorize | ✅ Verify & Route |
| Transaction & Saga State | ✅ BẮT BUỘC | ❌ CẤM |
| Event Publishing & Consumer | ✅ BẮT BUỘC | ❌ CẤM |
3. PHẠM VI HOẠT ĐỘNG CỦA AGENT
✅ Được phép
- Đọc/sửa source code trong thư mục service.
- Chạy lệnh build/test/lint đã khai báo trong CONSTITUTION.
- Tạo branch theo pattern
spec/*,agent/*,feat/*,fix/*.
❌ Cấm tuyệt đối
- KHÔNG Hard Delete — luôn Soft Delete (
is_deleted = truehoặcstatus = INACTIVE). - KHÔNG bypass Auth/Security hoặc vô hiệu hóa phân quyền.
- KHÔNG sửa hoặc đọc file
.env, production secrets. - KHÔNG sửa file migration đã tồn tại — luôn tạo migration mới.
- KHÔNG commit trực tiếp vào branch bảo vệ (
main,master,production).
4. FORBIDDEN PATTERNS BẮT BUỘC TRÁNH
| # | Rule | Lý do |
| 1 | NEVER lưu secret/API key trong source control | Bảo mật |
| 2 | NEVER SELECT * trong query phức tạp hoặc JOIN | Hiệu năng & Rò rỉ dữ liệu |
| 3 | NEVER trả Entity trực tiếp ra API / Event | Vi phạm DTO Pattern |
| 4 | NEVER kết nối trực tiếp vào Database của service khác | Phá vỡ Bounded Context |
| 5 | NEVER gọi service ngoài mà không có timeout + circuit breaker | Sụp đổ dây chuyền |
| 6 | NEVER để TODO comment trong code đã merge | Nợ kỹ thuật |
5. CHUẨN MÃ LỖI HTTP STATUS
| Code | Ý nghĩa & Khi nào dùng |
| 200 / 201 | Thành công (GET, PUT) / Tạo mới thành công (POST) |
| 400 | Dữ liệu đầu vào sai định dạng (Format validation failed) |
| 401 | Chưa xác thực hoặc Token hết hạn |
| 403 | Không đủ quyền truy cập tài nguyên |
| 404 | Không tìm thấy tài nguyên |
| 409 | Conflict dữ liệu / Idempotency đang xử lý |
| 422 | Vi phạm quy tắc nghiệp vụ (Business validation failed) |
| 500 | Lỗi hệ thống nội bộ |
6. DEFINITION OF DONE (DOD)
- 100% Test suite pass (Unit + Integration tests đạt coverage >= 80% theo CONSTITUTION §5).
- 0 Lint / Compiler warning.
- DTO Pattern tuân thủ nghiêm ngặt (Zero Entity Leak).
- Soft delete được áp dụng cho toàn bộ bảng.
- Có migration file mới cho mọi thay đổi DB schema.
- Không có TODO comment trong code.
<!-- BEGIN GENERATED RULES — DO NOT EDIT BELOW THIS LINE --><!-- GENERATED FROM registry/rules/api-design.md — DO NOT EDIT DIRECTLY -->title: Microservice API Design Standard scope: backend severity: must tags: [api, rest, grpc, controller, dto]
Rule — API Design Standard
Khi thêm hoặc chỉnh sửa endpoint API:
- Path chuẩn RESTful: prefix
/api/v1/, tên tài nguyên dạng số nhiều kebab-case (vd:/api/v1/order-items). - Response chuẩn: Trả về đúng format
{ "status": 200, "message": "...", "data": { } }. - Controller mỏng (Thin Controller): Controller CHỈ nhận Request DTO, validate format, gọi đúng Service method, và map trả về Response DTO. KHÔNG viết business logic trong Controller.
- DTO Pattern bắt buộc: Tuyệt đối không bao giờ nhận hoặc trả Entity trực tiếp ra API.
- Validation ở Backend: Mọi Request DTO phải được validate chặt chẽ (not null, size, regex, bounds).
- HTTP Status Codes chuẩn:
200 OK/201 Created: Thành công400 Bad Request: Validation format thất bại401 Unauthorized: Thiếu hoặc sai Token403 Forbidden: Không đủ quyền truy cập404 Not Found: Không tìm thấy tài nguyên409 Conflict: Trùng lặp dữ liệu / Idempotency race condition422 Unprocessable Entity: Vi phạm luật nghiệp vụ500 Internal Server Error: Lỗi hệ thống ngoài ý muốn
- Idempotency Key: Bắt buộc hỗ trợ header
Idempotency-Keycho toàn bộ endpoint tạo/thanh toán/thay đổi trạng thái quan trọng.
<!-- GENERATED FROM registry/rules/async-integration.md — DO NOT EDIT DIRECTLY -->title: Async Integration & Messaging Rules scope: messaging severity: must tags: [messaging, kafka, rabbitmq, outbox, event]
Rule — Async Integration & Event Messaging
Khi gửi/nhận thông điệp qua Event Broker (Kafka/RabbitMQ) hoặc tác vụ nền:
- Transactional Outbox: Khi cần cập nhật DB và phát Event trong cùng một luồng nghiệp vụ, BẮT BUỘC sử dụng Transactional Outbox pattern để tránh mất message hoặc phát ghost message.
- Idempotent Consumers: Mọi Consumer nhận message phải kiểm tra tính trùng lặp qua
event_idhoặc bảngprocessed_events. - Dead Letter Queue (DLQ): Consumer gặp lỗi chỉ được retry tối đa 3 lần với exponential backoff, sau đó đẩy sang DLQ topic. Không throw exception vô hạn làm nghẽn partition.
- CloudEvents Standard: Cấu trúc payload của event phải tuân thủ chuẩn CloudEvents (id, source, type, time, datacontenttype, data).
<!-- GENERATED FROM registry/rules/backend-feature.md — DO NOT EDIT DIRECTLY -->title: Backend Feature & Domain Rules scope: backend severity: must tags: [backend, service, domain, transaction, soft-delete]
Rule — Backend Feature Implementation
Khi phát triển hoặc chỉnh sửa code backend:
- Transaction Boundary: Annotation
@Transactional(hoặc tương đương) CHỈ được đặt ở Service Layer. Không đặt ở Controller hoặc Repository. - Soft Delete toàn hệ thống: Không viết
DELETE FROMtrực tiếp. Mọi bảng chính phải dùngis_deleted = truehoặcstatus = INACTIVE/CANCELLED. - Không
SELECT *: Trong các câu truy vấn có JOIN, sub-query hoặc bảng nhiều cột, luôn chỉ định rõ các cột cần lấy hoặc dùng Projection DTO. - Bounded Context: Không inject Service của Domain khác nếu vi phạm ranh giới nghiệp vụ; sử dụng Event (Kafka/RabbitMQ) hoặc HTTP Client với DTO độc lập.
- Giới hạn kích thước code:
- Method <= 40 dòng
- File/Class <= 300 dòng
- Không chứa TODO comment khi merge vào main.
<!-- GENERATED FROM registry/rules/db-migration.md — DO NOT EDIT DIRECTLY -->title: Database Migration Rules scope: database severity: must tags: [database, migration, ddl, sql]
Rule — Database Migration
Khi tạo migration trong db/migration/** hoặc migrations/**:
- Migration là Bất biến: Tuyệt đối không sửa đổi file migration cũ đã tồn tại/đã chạy. Mọi thay đổi schema phải tạo file migration MỚI.
- Audit Columns: Mọi bảng nghiệp vụ mới bắt buộc có các cột:
created_at,updated_at,created_by, và cột soft delete (is_deletedhoặcstatus). - Charset & Collation: Khai báo rõ ràng hỗ trợ Unicode (vd
utf8mb4trên MySQL hoặcUTF8trên PostgreSQL). - Timezone chuẩn: Luôn lưu trữ thời gian ở chuẩn UTC /
TIMESTAMP WITH TIME ZONE. - Non-breaking DDL: Khi thêm cột mới vào bảng đang chạy production, cột phải là
NULLABLEhoặc có giá trịDEFAULThợp lệ.
<!-- GENERATED FROM registry/rules/microservice-resilience.md — DO NOT EDIT DIRECTLY -->title: Microservice Resilience & Fault Tolerance scope: universal severity: must tags: [resilience, circuit-breaker, timeout, retry, fallback]
Rule — Microservice Resilience
Khi thực hiện lời gọi mạng (HTTP/gRPC) sang microservice khác hoặc 3rd-party API:
- Timeout bắt buộc: Mọi network call phải có cấu hình timeout rõ ràng (thường 2s - 5s). Không bao giờ để timeout vô hạn (
timeout: 0). - Circuit Breaker: Cấu hình Circuit Breaker cho các service phụ thuộc quan trọng để ngắt mạch khi tỷ lệ lỗi vượt ngưỡng, tránh sụp đổ dây chuyền.
- Graceful Degradation (Fallback): Khi service ngoài bị sập, luôn có fallback trả về dữ liệu cache hoặc phản hồi nhẹ nhàng, không để crash ứng dụng.
- Correlation / Trace ID: Luôn truyền
X-Correlation-IDhoặctraceparent(W3C Trace Context) qua mọi lời gọi mạng để trace log xuyên suốt hệ thống.
<!-- GENERATED FROM registry/rules/security.md — DO NOT EDIT DIRECTLY -->title: Security & Authentication Rules scope: security severity: must tags: [security, auth, jwt, injection, secrets]
Rule — Security & Authentication
Khi viết code liên quan đến xác thực, phân quyền hoặc bảo mật dữ liệu:
- Zero Hardcoded Secrets: Tuyệt đối không commit password, API key, JWT secret, private key vào source code. Tất cả phải nạp từ biến môi trường.
- Fail-Fast Configuration: Khi thiếu biến môi trường bắt buộc (như
JWT_SECRET), ứng dụng phải báo lỗi và dừng khởi động ngay lập tức, không dùng secret mặc định. - SQL Injection Protection: ZERO TOLERANCE với việc cộng chuỗi SQL trực tiếp. Luôn sử dụng Parameterized Query hoặc ORM Parameter Binding.
- Phân quyền Đa cấp: Xác thực cả Token Role, Tenant ID, và quyền sở hữu tài nguyên (Resource Ownership).
- CORS chặt chẽ: Không bao giờ cấu hình
allowed_origins = ["*"]trong môi trường production.
<!-- GENERATED FROM registry/rules/testing.md — DO NOT EDIT DIRECTLY -->title: Backend Testing Rules scope: testing severity: must tags: [testing, unit-test, integration-test, coverage]
Rule — Testing Standard
Khi viết unit test hoặc integration test cho backend microservice:
- Ngưỡng Coverage tối thiểu: Phải đạt đúng ngưỡng khai báo trong
CONSTITUTION.md §5(mặc định >= 80% line coverage). - Assertion thật: Mỗi test case bắt buộc có ít nhất 1 assertion kiểm tra giá trị cụ thể. Không viết test chỉ gọi hàm để lấy độ phủ giả tạo.
- Test độc lập: Mỗi test case phải tự cô lập dữ liệu (không phụ thuộc vào thứ tự chạy hoặc dữ liệu của test khác).
- Happy Path & Error Path: Mọi endpoint/service method mới bắt buộc phải test cả luồng thành công và toàn bộ các trường hợp throw exception / validation error.
- Mock External Calls: Unit test phải mock toàn bộ HTTP Client / Kafka Producer gọi ra bên ngoài.
<!-- END GENERATED RULES -->Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

