I. Giới thiệu
Các dự án vibe code của chúng ta, nên lưu trữ như nào để khi tôi đưa sang model mới, nền tảng mới, chúng vẫn xuyên suốt update sản phẩm như ở model cũ?
Với các dự án vibe code, đừng để “trí nhớ của sản phẩm” nằm trong conversation của Claude, ChatGPT, Cursor, Codex. Hãy coi Git repository là bộ nhớ dài hạn, còn model chỉ là một engineer tạm thời đọc bộ nhớ đó rồi tiếp tục làm.
Trong đó 5 file quan trọng nhất là:
| File | Model mới cần biết gì |
|---|---|
README.md | Project là gì, chạy thế nào |
PRODUCT.md | User, problem, use case, feature |
ARCHITECTURE.md | Component, data flow, integration |
AGENTS.md | Luật cho AI khi sửa code |
DECISIONS.md | Tại sao trước đây thiết kế như vậy |
Ví dụ PRODUCT.md không cần dài, nhưng phải trả lời được:
# Product## ProblemProduct Security team cần quản lý knowledge của ~100 hệ thống.## Users- Product Security Officer- Product Security Lead- Security Architect## Core capabilities1. Asset inventory2. Security posture3. Architecture knowledge4. Risk tracking5. AI Q&A6. ASM validation## Key questions system must answer- Hệ thống này làm gì?- Business owner là ai?- Có bao nhiêu web/mobile/API?- Authentication/authorization thế nào?- Sensitive data là gì?- Inbound/outbound integration?- Risk hiện tại?
Đặc biệt với vibe coding, tôi sẽ thêm một file AGENTS.md rất quan trọng:
# AI Engineering InstructionsBefore modifying code:1. Read PRODUCT.md2. Read ARCHITECTURE.md3. Read DECISIONS.md4. Inspect existing implementation5. Do not redesign architecture unless necessaryEngineering rules:- Do not hardcode secrets- New API must have authentication- Validate all external input- Add tests for new functionality- Database changes require migration- Existing API compatibility must be preservedBefore finishing:- Run tests- Update documentation if architecture changes- Update CHANGELOG.md- Add architectural decisions to DECISIONS.md
Như vậy ta chuyển từ:
ChatGPT → Claude → Gemini → Cursor → Codex → model local
thì prompt đầu tiên gần như chỉ cần:
Read
AGENTS.md,PRODUCT.md,ARCHITECTURE.mdandDECISIONS.md.
Understand the current project before making changes.
Then implement issue #123.
Model nào cũng có thể tiếp tục tương đối mượt.
Một thứ nữa cần làm đó là làm là DECISIONS.md, hoặc bài bản hơn dùng ADR (Architecture Decision Record):
docs/adr/├── 001-use-postgresql.md├── 002-use-vector-search.md├── 003-use-keycloak.md├── 004-multi-tenant-design.md└── 005-asm-integration.md
Ví dụ:
# ADR-004 Multi Tenant ArchitectureStatus: Accepted## ContextASM platform cần phục vụ nhiều business unit.## DecisionUse tenant_id at application and DB layer.## Reason- simpler operation- lower infrastructure cost- easier centralized management## Rejected alternativesSeparate DB per tenant.Reason:Operational overhead too high.
Cái này cực kỳ có giá trị với AI.
Nếu không có nó, vài tháng sau model mới nhìn code và nói: Thiết kế này không tối ưu, tôi sẽ refactor 😀
Nhưng thực tế chúng ta đã cố tình thiết kế như vậy vì một constraint mà model không biết :<
II. Prompt hỗ trợ tạo Project Memory Pack
Dùng prompt này để AI tự rà soát repo hiện tại và sinh ra bộ Project Memory Pack chuẩn, phục vụ chuyển qua model, nền tảng khác mà không mất context.
Bạn đang đóng vai **Senior Software Architect + Product Engineer + Technical Documentation Owner**.Tôi đang phát triển một sản phẩm theo phương pháp vibe coding. Tôi muốn toàn bộ kiến thức quan trọng của sản phẩm được lưu trong Git repository, thay vì phụ thuộc vào lịch sử conversation với AI.Mục tiêu là:- Tôi có thể chuyển dự án giữa ChatGPT, Claude, Gemini, Cursor, Codex hoặc local model.- AI mới có thể đọc repository và nhanh chóng hiểu được sản phẩm.- Kiến thức, quyết định kiến trúc, roadmap và trạng thái hiện tại của sản phẩm không bị mất.- Conversation với AI KHÔNG được xem là source of truth.- Repository phải là source of truth.Hãy thực hiện các bước sau.## 1. Phân tích toàn bộ repositoryĐọc và phân tích:- source code- README hiện tại- cấu trúc thư mục- database schema- migration- API- config- Docker / deployment- CI/CD- test- dependency- authentication / authorization- integration với hệ thống bên ngoài- các file documentation hiện cóKhông được giả định nếu có thể xác minh từ source code.Nếu có điểm chưa xác định được, ghi rõ:`UNKNOWN / NEED CONFIRMATION`Không tự bịa thông tin.---## 2. Tạo Project Memory PackTạo hoặc cập nhật cấu trúc:```text/├── README.md├── AI_CONTEXT.md├── AGENTS.md│├── docs/│ ├── PRODUCT.md│ ├── ARCHITECTURE.md│ ├── SECURITY.md│ ├── DATA_MODEL.md│ ├── API.md│ ├── DEPLOYMENT.md│ ├── ROADMAP.md│ ├── DECISIONS.md│ └── CHANGELOG.md│└── docs/adr/```Không tạo tài liệu cho có. Nội dung phải phản ánh đúng implementation thực tế.---# 3. Nội dung từng file## AI_CONTEXT.mdĐây là entry point cho mọi AI model mới.AI_CONTEXT.md phải giúp một AI chưa từng biết dự án có thể hiểu nhanh:### Product- sản phẩm là gì- giải quyết vấn đề gì- user chính- use case chính### Current State- version hiện tại- feature đã hoàn thành- feature đang phát triển- limitation hiện tại- technical debt quan trọng### Architecture- technology stack- các component chính- data flow chính- authentication- authorization- database- external integration### Important DecisionsTóm tắt các quyết định kiến trúc quan trọng và link tới ADR tương ứng.### Current Roadmap- Now- Next- Later### AI InstructionsKhi AI làm việc với repository này:1. đọc AI_CONTEXT.md2. đọc PRODUCT.md3. đọc ARCHITECTURE.md4. đọc các ADR liên quan5. đọc AGENTS.md6. kiểm tra implementation thực tế trước khi sửa codeAI_CONTEXT.md nên ngắn gọn, khoảng 2–5 phút đọc.---## PRODUCT.mdMô tả sản phẩm từ góc nhìn Product.Bao gồm:- Product Vision- Problem Statement- Target Users- Personas- Core Use Cases- Core Features- Business Rules- Out of Scope- Product Constraints- Success Metrics nếu xác định đượcPhân biệt rõ:- EXISTING- PLANNED- IDEAKhông mô tả planned feature như thể đã tồn tại.---## ARCHITECTURE.mdMô tả kiến trúc hiện tại.Bao gồm:- System Context- Technology Stack- Components- Component responsibilities- Request flow- Authentication flow- Authorization model- Data flow- External integrations- Background jobs- Storage- Cache- Queue nếu có- Deployment architecture- Network boundaries- Trust boundariesTạo Mermaid diagram nếu phù hợp.Ví dụ:```mermaidflowchart LR User --> Frontend Frontend --> API API --> Database API --> ExternalService```Architecture phải phản ánh implementation hiện tại, không phải kiến trúc lý tưởng.---## SECURITY.mdMô tả security architecture và security requirements.Bao gồm:- Authentication- Authorization- Session management- Secret management- Input validation- API security- Data protection- Encryption- Logging- Audit logging- Dependency security- CI/CD security- Security assumptions- Trust boundaries- Known security risks- Security technical debtPhân biệt:- Implemented- Partially Implemented- Missing- PlannedKhông tuyên bố một security control tồn tại nếu source code không chứng minh được.---## DATA_MODEL.mdMô tả:- entities- tables- relationships- important fields- identifiers- tenant model nếu có- lifecycle của dữ liệu- sensitive dataTạo Mermaid ER diagram nếu phù hợp.---## API.mdTổng hợp API hiện tại:- method- endpoint- purpose- authentication- authorization- input- output- important validation- error handlingKhông cần copy toàn bộ OpenAPI nếu đã tồn tại.Link tới OpenAPI nếu có.---## DEPLOYMENT.mdBao gồm:- local development- environment- build- deployment- Docker- infrastructure- database migration- rollback- required environment variables- observability- backup nếu cóKhông đưa secret thực vào tài liệu.---## ROADMAP.mdSử dụng format:# NOWNhững việc đang thực hiện.# NEXTNhững việc dự kiến tiếp theo.# LATERÝ tưởng / enhancement dài hạn.Mỗi item nên có:- mục tiêu- trạng thái- dependency- technical impact nếu đáng kểKhông suy diễn roadmap nếu repository không đủ thông tin.---## DECISIONS.mdTạo danh sách các quyết định quan trọng:| ID | Decision | Status | ADR ||---|---|---|---|Ví dụ:```textADR-001 PostgreSQL as primary databaseADR-002 JWT authenticationADR-003 Multi-tenant architecture```---## docs/adr/Với những quyết định kiến trúc quan trọng có thể suy ra rõ ràng từ hệ thống, tạo ADR.Format:```markdown# ADR-XXX: Decision titleStatus: Accepted## ContextVấn đề / constraint cần giải quyết.## DecisionQuyết định đã được lựa chọn.## RationaleTại sao lựa chọn này hợp lý.## Consequences### Positive### Negative## AlternativesCác phương án khác nếu có bằng chứng.## EvidenceCác file/source code chứng minh quyết định này.```Không bịa lý do lịch sử nếu không tìm thấy bằng chứng.Nếu biết WHAT nhưng không biết WHY, ghi:`Rationale: UNKNOWN – historical context not available.`---## AGENTS.mdĐây là instruction cho tất cả AI coding agent.Bao gồm ít nhất:```markdown# AI Engineering Instructions## Before making changes1. Read AI_CONTEXT.md.2. Read PRODUCT.md.3. Read ARCHITECTURE.md.4. Read relevant ADRs.5. Inspect the existing implementation.6. Do not assume documentation is newer than code.7. If documentation and implementation conflict, identify the conflict before modifying the system.## Engineering Principles- Preserve existing architecture unless change is justified.- Prefer incremental changes over unnecessary rewrites.- Do not introduce new dependencies without a reason.- Preserve backward compatibility unless explicitly instructed otherwise.- Never hardcode secrets.- Validate untrusted input.- Follow existing authentication and authorization patterns.- Database changes require migrations.- New behavior should have tests where practical.## Security- Treat all external input as untrusted.- Enforce authorization server-side.- Do not expose secrets or sensitive information in logs.- Do not weaken security controls merely to make implementation easier.## Before finishing a task1. Run relevant tests.2. Review security impact.3. Review backward compatibility.4. Update documentation if behavior or architecture changed.5. Update CHANGELOG.md.6. Create/update ADR when an architectural decision is introduced.7. Update AI_CONTEXT.md if the current state of the product changed materially.```Bổ sung các rule đặc thù của repository mà bạn phát hiện.---# 4. CHANGELOG.mdKhông cố gắng dựng lại toàn bộ lịch sử nếu không đủ dữ liệu.Tạo section:```markdown# Unreleased## Added## Changed## Fixed## Security```Nếu Git history cho phép xác định chính xác các thay đổi lớn trước đây thì có thể bổ sung.---# 5. Kiểm tra consistencySau khi tạo documentation, kiểm tra chéo:- Documentation vs source code- Architecture vs deployment- API vs implementation- Database vs migration- Security documentation vs actual controls- README vs cách chạy thực tếLiệt kê các inconsistency phát hiện được.Không âm thầm sửa implementation chỉ để khớp documentation.---# 6. Tạo Project SnapshotTrong AI_CONTEXT.md thêm:```markdown## Project SnapshotLast reviewed:Current version:Current branch:Production status:### Working-### In Progress-### Known Issues-### Technical Debt-### Next Recommended Work-```Điền dựa trên bằng chứng tìm được.---# 7. Quy tắc chống hallucinationRất quan trọng:Không được biến suy đoán thành fact.Sử dụng các nhãn:- `CONFIRMED` — xác minh được từ repository- `INFERRED` — suy ra hợp lý từ implementation- `UNKNOWN` — chưa đủ thông tin- `PLANNED` — dự kiến nhưng chưa implementĐối với quyết định Product/Business không thể suy ra từ code, để UNKNOWN.---# 8. Sau khi hoàn thànhCho tôi báo cáo ngắn:### Repository understandingTóm tắt hệ thống trong tối đa 10 dòng.### Files createdDanh sách file đã tạo.### Files updatedDanh sách file đã cập nhật.### Important findingsNhững phát hiện quan trọng.### Documentation gapsNhững thông tin cần tôi xác nhận.### Architecture risksNhững điểm kiến trúc đáng chú ý.### Security risksNhững vấn đề security đáng chú ý.### Recommended next actionsTối đa 10 việc ưu tiên tiếp theo.Sau đó dừng lại.Không tự redesign hoặc refactor sản phẩm trừ khi tôi yêu cầu.