Bỏ qua đến nội dung

Từ điển prompt thực chiến cho AI Coding Agent: Nói sao cho chuẩn tech?

Bộ từ điển tra cứu thực chiến giúp bạn chuyển hóa các câu lệnh đời thường thành thuật ngữ kiến trúc chuẩn xác khi làm việc với AI Coding Agent.

Hoang Yell
Hoang Yell
14 phút đọc
English
Từ điển prompt thực chiến cho AI Coding Agent: Nói sao cho chuẩn tech?

Phần 1: Những thuật ngữ thượng đẳng để coding với AI Agent sướng hơn, chúng ta đã giải mã bản chất toán học của cơ chế lái vector trong không gian tiềm ẩn (Latent Vector Steering): AI Coding Agent không hiểu tiếng người theo nghĩa triết học, nó chỉ phản ứng với các xung chú ý (attention spikes) được kích hoạt bởi các thuật ngữ kỹ thuật mang tính quy chuẩn cao.

Nhưng trong nhịp làm việc hối hả hàng ngày, vấn đề lớn nhất của anh em lập trình viên không phải là lười gõ, mà là không nhớ nổi hoặc không biết cái vấn đề mình đang gặp phải thì giới kiến trúc sư gọi nó bằng cái tên khoa học gì.

Bạn chỉ biết hệ thống đang bị lỗi “click 2 lần trừ tiền 2 lần”, “2 người cùng bấm lưu đè mất dữ liệu của nhau”, hay “biến state boolean đá nhau làm màn hình vừa xoay vòng vừa báo lỗi”. Nếu bạn ném nguyên văn những câu than thở đó vào AI Agent, bạn sẽ nhận lại một mớ code chắp vá đầy lỗ hổng logic.

Phần 2 này được tinh gọn tối đa thành một cuốn từ điển tra cứu nhanh (The Master Dictionary): Phân loại 28 bài toán kinh điển nhất trong kỹ thuật phần mềm thành bảng đối chiếu: Cách nói đời thường vs Thuật ngữ chuẩn Tech, kèm mẫu Prompt copy-paste dùng được ngay cho Cursor, Claude Code, GitHub Copilot hay Antigravity.

TL;DR

  • Mục đích: Cung cấp sổ tay tra cứu 28 tình huống thực chiến (Database, API, Frontend State, Refactoring, Testing & Security) từ văn phong đời thường sang thuật ngữ đòn bẩy cao.
  • Tại sao cần: Loại bỏ hoàn toàn code phỏng đoán ngây thơ (naive code) của AI, triệt tiêu race condition, memory leak, dual-write anomalies và impossible states.
  • Cách dùng: Mở bảng tra cứu tương ứng với bài toán của bạn, copy mẫu prompt chuẩn Senior, thay tên biến/module và paste vào AI Agent.

Bộ từ điển tra cứu thực chiến (The Master Dictionary)

1. Cơ sở dữ liệu, Đồng thời & Giao dịch (Database & Concurrency)

Vấn đề đời thường (Nhu cầu / Nỗi đau) Thuật ngữ chuẩn Tech (Senior Jargon) Mẫu Prompt thực chiến (Copy-Paste)
Click đúp trừ tiền 2 lần
Khách bấm nút mua 2 lần liên tiếp bị trừ tiền 2 lần.
Idempotent Consumer, Idempotency-Key, Distributed Lock (Redis SETNX with TTL) "Implement this payment endpoint as an Idempotent Consumer. Extract 'Idempotency-Key' and acquire a Redis lock via SETNX with 60s lease. Store and return cached response on replay."
2 người sửa đè mất bài
2 người cùng mở 1 bài ra sửa, người bấm Save sau đè mất bài người trước.
Optimistic Concurrency Control (OCC), Atomic Compare-And-Swap (CAS), Version Column "Implement OCC on post updates using atomic CAS: 'UPDATE posts SET content = $1, version = version + 1 WHERE id = $2 AND version = $3'. Throw ConcurrencyConflictException if 0 rows affected."
Lưu DB xong bắn Kafka bị lỗi
Đơn hàng đã lưu vào DB nhưng bắn Kafka/Email bị fail làm lệch dữ liệu.
Transactional Outbox Pattern, Change Data Capture (CDC), Guaranteed Delivery "Implement Transactional Outbox Pattern. Insert event into 'outbox' table in the same DB transaction as Order. Create a background poller with retries to publish events to Kafka."
Xóa bài nhưng vẫn muốn khôi phục
Xóa bài chỉ ẩn đi thôi để sau này lỡ bấm nhầm còn lấy lại được.
Soft Delete via deleted_at timestamp, Partial Unique Indexes "Implement soft deletion using a nullable 'deleted_at' timestamp. Add a Partial Unique Index: 'CREATE UNIQUE INDEX idx_posts_slug ON posts(slug) WHERE deleted_at IS NULL'."
Bảng hàng chục triệu dòng query đơ
Query phân trang OFFSET/LIMIT lớn làm database bị đơ cứng luồng.
Keyset Pagination (Seek Method), Composite Covering Index "Replace OFFSET pagination with Keyset Pagination: 'WHERE (created_at, id) < ($1, $2) ORDER BY created_at DESC, id DESC LIMIT 20'. Add composite covering index on (created_at, id)."
Đếm COUNT(*) quá chậm
Hàm SELECT COUNT(*) trên bảng 50 triệu dòng chạy mất 10 giây.
Counter Cache pattern, PostgreSQL System Rel-tuples Estimation "Replace slow SELECT COUNT(*) with an atomic counter cache in Redis (INCR/DECR) or query PostgreSQL 'pg_class.reltuples' for instantaneous count approximations."
Deadlock khi update nhiều dòng
Nhiều transaction update cùng lúc bị lỗi deadlock văng tùm lum.
Deterministic Lock Ordering, Row-Level Lock (SELECT FOR UPDATE) "Prevent transaction deadlocks by sorting resource IDs in deterministic ascending order before acquiring row-level locks via 'SELECT ... FOR UPDATE'."

2. Giao tiếp mạng, API & Hệ thống phân tán (Network & Distributed Systems)

Vấn đề đời thường (Nhu cầu / Nỗi đau) Thuật ngữ chuẩn Tech (Senior Jargon) Mẫu Prompt thực chiến (Copy-Paste)
Chặn spam request liên tục
User/bot bấm liên tục làm sập server đăng nhập hoặc tìm kiếm.
Sliding Window Rate Limiter with Redis Atomic Sorted Sets (ZADD/ZCARD) "Implement distributed sliding window rate limiter middleware in Redis enforcing 10 req/min per IP. Return HTTP 429 Too Many Requests with RFC 'Retry-After' header."
Service bên thứ 3 chết làm đơ cả web
API thanh toán/giao hàng bên thứ 3 nghẽn làm treo connection server mình.
Circuit Breaker Pattern (Closed/Open/Half-Open), Fallback Degradation "Wrap third-party shipping client with Circuit Breaker. Trip OPEN on 50% failures over 10 calls, timeout at 3s, and return cached fallback estimates without downstream calls."
Upload file vài GB sợ sập RAM
Khách upload video nặng làm RAM server vọt lên hàng chục GB bị OOMKilled.
Zero-Copy Streaming Pipeline, Pass-through Stream with Backpressure "Pipe incoming multipart HTTP stream directly to S3 via '@aws-sdk/lib-storage' using Node.js stream backpressure. Do not buffer chunks in memory or write to local disk."
Không biết request lỗi ở service nào
Request đi qua 5 microservice khác nhau, khi có lỗi tìm log như mò kim đáy bể.
Distributed Tracing with W3C TraceContext (traceparent), OpenTelemetry Spans "Add OpenTelemetry tracing middleware. Extract and propagate W3C 'traceparent' headers across outgoing HTTP requests and message queues to correlate logs by Trace ID."
Frontend gọi quá nhiều API nhỏ
Mobile app phải gọi 10 API khác nhau rồi tự ghép giao diện gây lag mạng.
Backend For Frontend (BFF) Pattern, Request Aggregator / ViewModel "Implement a BFF aggregation endpoint. Parallelize internal microservice requests via Promise.allSettled and transform results into a single client-tailored ViewModel."
Webhook gọi lại nhiều lần gây trừ tiền
Cổng thanh toán bắn webhook nhiều lần làm hệ thống cộng tiền nhiều lần.
Idempotent Webhook Consumer with Constant-Time HMAC Signature Verification "Verify incoming webhook HMAC-SHA256 signature using 'crypto.timingSafeEqual', then process payload as an Idempotent Consumer backed by unique event ID database locks."

3. Quản lý trạng thái & Frontend (State Management & Frontend)

Vấn đề đời thường (Nhu cầu / Nỗi đau) Thuật ngữ chuẩn Tech (Senior Jargon) Mẫu Prompt thực chiến (Copy-Paste)
Cờ boolean đá nhau loạn xạ
Biến isLoading, isError đá nhau làm màn hình vừa xoay vừa báo lỗi đỏ.
Finite State Machine (FSM) using TypeScript Discriminated Unions "Model state as an explicit FSM using discriminated unions: 'type State = { status: 'idle' } | { status: 'loading' } | { status: 'success'; data: T } | { status: 'error'; error: Error }'. Eliminate boolean flags."
Gõ ô input làm cả trang re-render
Gõ phím tìm kiếm mà cả trang web render lại từ đầu làm màn hình bị giật lag.
Referential Equality, Selector Memoization, Component Colocation "Isolate high-frequency input state into a colocated leaf component. Use Reselect selector memoization with structural sharing to preserve referential equality of table data."
Bảng 20,000 dòng treo đơ browser
Hiển thị danh sách khách hàng lớn làm trình duyệt đơ mất 5 giây mới bấm được.
Virtual Windowing, DOM Node Recycling (@tanstack/react-virtual) "Implement virtual list windowing with '@tanstack/react-virtual' for this 20,000-row table. Render only intersecting viewport nodes with an overscan buffer of 5 items."
Form validate mỗi nơi một kiểu
Kiểm tra dữ liệu form rải rác trong code làm sót case và sai lệch kiểu dữ liệu.
Schema-First Validation with Runtime Type Inference (Zod / Valibot) "Implement schema-first form validation using Zod. Infer form types directly from the schema ('z.infer<typeof schema>') and validate at input blur and submit boundaries."
Client cache hiển thị dữ liệu cũ
Sửa thông tin xong back lại trang trước vẫn thấy thông tin cũ chưa cập nhật.
Optimistic UI Mutation Updates with Query Key Cache Invalidation "Implement optimistic UI mutation updates with TanStack Query. Immediately update local cache on click, roll back on server error, and invalidate query key ['profile'] on success."

4. Tái cấu trúc & Thiết kế hệ thống (Refactoring & Architecture)

Vấn đề đời thường (Nhu cầu / Nỗi đau) Thuật ngữ chuẩn Tech (Senior Jargon) Mẫu Prompt thực chiến (Copy-Paste)
Đổi tên hàm ở 200 file sợ nhầm
Đổi tên function ở 200 file, sợ replace bằng regex nhầm vào comment hay string.
AST Codemod (Abstract Syntax Tree) via jscodeshift or ast-grep "Write an AST Codemod script with jscodeshift targeting CallExpression nodes where 'callee.name === oldFn'. Rename to 'newFn' and wrap args into an object without touching comments."
Kim tự tháp if-else 10 tầng
Hàm tính chiết khấu có 10 tầng if-else lồng nhau nhìn rối mắt không bảo trì nổi.
Strategy Pattern with Typed Dispatch Map, Result Monad Pipeline "Refactor nested if-else branching using the Strategy Pattern with a typed lookup dispatch map. Chain rule evaluations through a Railway-Oriented Result monad pipeline."
Đổi DB sau này không đập code
Code sao cho sau này đổi từ MongoDB sang Postgres không phải viết lại từ đầu.
Hexagonal Architecture (Ports & Adapters) with Dependency Inversion (DIP) "Structure this module using Hexagonal Architecture. The domain core must contain pure business entities with zero ORM dependencies. Define Repository Ports returning domain models."
Truyền prop qua 8 tầng component
Truyền biến từ component cha xuống component con qua 8 tầng trung gian (prop drilling).
Component Composition (passing JSX children) or Context Selector "Eliminate prop drilling by using Component Composition (passing JSX children) or a fine-grained Context selector to subscribe leaf nodes directly to state slices."
Chuỗi string nguyên thủy dễ lọt rác
Email và phone number chỉ là string thông thường, dễ bị truyền chuỗi rác vào hàm.
Domain Value Objects & TypeScript Branded Types (Parse Don’t Validate) "Model EmailAddress and PhoneNumber as immutable Domain Value Objects using TypeScript Branded Types ('type Email = string & { readonly __brand: unique symbol }')."

5. Kiểm thử, Bảo mật & Vận hành (Testing & Security)

Vấn đề đời thường (Nhu cầu / Nỗi đau) Thuật ngữ chuẩn Tech (Senior Jargon) Mẫu Prompt thực chiến (Copy-Paste)
Test hàm tính toán sợ sai số thực
Viết test cho hàm tính thuế xem có bao giờ bị sai số thực (0.1 + 0.2 !== 0.3) không.
Property-Based Testing with fast-check asserting Algebraic Invariants "Write property-based invariant tests using fast-check. Assert that 'applyTax(amount, rate) >= amount' across 2,000 randomly generated arbitrary float inputs."
Test API ngoài sợ tốn tiền thật
Test luồng thanh toán nhưng không muốn gọi sang cổng thật làm phát sinh tiền thật.
Mock Service Worker (MSW) Network-Level Contract Isolation "Isolate third-party API integration tests using Mock Service Worker (MSW) at the network layer. Intercept HTTP requests and simulate 200, 400, and 504 timeout scenarios."
Chạy test làm bẩn database dev
Chạy test tích hợp làm sinh ra hàng nghìn dữ liệu rác trong database phát triển.
Ephemeral Test Containers (Testcontainers) with Isolated Lifecycle "Configure integration tests using Testcontainers to spin up a disposable Docker PostgreSQL container for each test suite, running fresh migrations and tearing down on exit."
Sợ lộ secret token ra ngoài client
Sợ lỡ tay import nhầm API secret key ra ngoài code client cho người dùng thấy.
Environment Variable Boundary Isolation (Public vs Secret Env scoping) "Enforce server-only environment variable boundaries. Restrict private API tokens to server runtime handlers and validate all process.env values with a type-safe env schema."
So sánh chuỗi token sợ timing attack
So sánh token hoặc mật khẩu bằng toán tử === bình thường sợ hacker dò thời gian.
Constant-Time String Comparison via crypto.timingSafeEqual "Replace standard '===' string equality checks on authentication tokens with 'crypto.timingSafeEqual' to mitigate side-channel timing attacks."

Final Take

Giao tiếp với AI Coding Agent cũng giống như việc bạn biên dịch (compile) ý tưởng trong đầu thành mã nguồn thực thi:

  • Nếu đầu vào của bạn là văn phong đời thường cảm tính, AI buộc phải đoán mò, và mọi sự phỏng đoán trong lập trình đều kết thúc bằng nợ kỹ thuật và outage trên production.
  • Nhưng khi bạn nạp vào đầu vào những thuật ngữ kiến trúc chuẩn xác, bạn đang kích hoạt các mạng nơ-ron chuyên sâu nhất của mô hình - nơi lưu giữ tinh hoa thiết kế của các kỹ sư trưởng, các tài liệu RFC và những hệ thống phân tán bền vững nhất hành tinh.

Hãy lưu lại cuốn từ điển này làm sổ tay tra cứu hàng ngày. Mỗi khi chuẩn bị gõ một câu lệnh diễn giải dài 3 đoạn, hãy dừng lại 2 giây, tìm xem từ khóa tương ứng trong bảng là gì. Bạn sẽ thấy AI Agent của mình thông minh lên trông thấy chỉ sau một lần gõ phím!

Bài viết liên quan