chore: update project documentation, audit reports, and initialize IDE configuration files
Some checks failed
CI / Lint → Typecheck → Test → Build (22) (push) Failing after 29s
CI / E2E Tests (push) Has been skipped
CodeQL Analysis / CodeQL (javascript-typescript) (push) Failing after 2m42s
Deploy / Build Web Image (push) Failing after 27s
Deploy / Build AI Services Image (push) Failing after 29s
E2E Tests / Playwright E2E (push) Failing after 43s
Deploy / Build API Image (push) Failing after 1m31s
Security Scanning / Dependency Audit (pnpm) (push) Failing after 6s
Security Scanning / Trivy Scan — API Image (push) Failing after 5m35s
Security Scanning / Trivy Scan — AI Services Image (push) Failing after 3m45s
Deploy / Deploy to Staging (push) Has been skipped
Deploy / Smoke Test Staging (push) Has been skipped
Deploy / Deploy to Production (push) Has been skipped
Deploy / Smoke Test Production (push) Has been skipped
Deploy / Rollback Staging (push) Has been skipped
Deploy / Rollback Production (push) Has been skipped
Security Scanning / Trivy Scan — Web Image (push) Failing after 13m51s
Security Scanning / Trivy Filesystem Scan (push) Failing after 14m46s
Security Scanning / Security Gate (push) Has been cancelled

This commit is contained in:
Ho Ngoc Hai
2026-04-19 03:12:54 +07:00
parent 3be106074d
commit 11f2bf26e6
101 changed files with 21312 additions and 20672 deletions

View File

@@ -1,97 +1,97 @@
# 📚 Inquiries Module - Complete Exploration Documentation
# 📚 Mô-đun Inquiries - Tài Liệu Khám Phá Toàn Diện
**Generated:** April 11, 2026
**Module:** `apps/api/src/modules/inquiries/`
**Status:** ✅ Complete & Thorough Analysis
**Ngày tạo:** 11 tháng 4, 2026
**Mô-đun:** `apps/api/src/modules/inquiries/`
**Trạng thái:** ✅ Phân tích Đầy đủ & Kỹ lưỡng
---
## 📖 DOCUMENTATION FILES
## 📖 CÁC TỆP TÀI LIỆU
This exploration includes **3 comprehensive documentation files** designed for different use cases:
Bộ khám phá này bao gồm **3 tệp tài liệu toàn diện** được thiết kế cho các trường hợp sử dụng khác nhau:
### 1. **INQUIRIES_MODULE_EXPLORATION.md** (23 KB)
**Purpose:** In-depth reference guide
**Best for:** Understanding architecture, patterns, and complete file descriptions
**Mục đích:** Tài liệu tham khảo chuyên sâu
**Phù hợp nhất:** Hiểu kiến trúc, các mẫu thiết kế và mô tả tệp đầy đủ
Contains:
- 📁 Complete directory structure
- 📄 Full file listing with descriptions
- 🏗️ Module architecture diagrams
- 🔑 Key classes & handlers breakdown
- 🎯 DDD layer analysis
- 📊 Test file summary
- 🛠️ Dependencies & security
- 📝 API contracts
Nội dung:
- 📁 Cấu trúc thư mục đầy đủ
- 📄 Danh sách tệp hoàn chỉnh kèm mô tả
- 🏗️ Sơ đồ kiến trúc mô-đun
- 🔑 Phân tích các lớp và trình xử lý chính
- 🎯 Phân tích tầng DDD
- 📊 Tóm tắt tệp kiểm thử
- 🛠️ Phụ thuộc và bảo mật
- 📝 Hợp đồng API
**Read this when:** You need complete understanding of the module
**Đọc khi:** Bạn cần hiểu toàn diện về mô-đun
---
### 2. **INQUIRIES_MODULE_QUICK_REFERENCE.md** (9.3 KB)
**Purpose:** Quick lookup guide
**Best for:** Getting up to speed quickly, finding specific information
**Mục đích:** Tài liệu tra cứu nhanh
**Phù hợp nhất:** Nắm bắt nhanh, tìm thông tin cụ thể
Contains:
- 📊 Module at a glance
- 📁 Files by layer overview
- 🔄 Request flow diagrams
- 🔑 Key classes table
- 📝 Key interfaces
- 🧪 Test statistics
- 🔐 Authorization matrix
- 🎯 DDD principles
- 📌 Common patterns
- 🔍 Where to look for X guide
Nội dung:
- 📊 Tổng quan mô-đun
- 📁 Các tệp theo tầng tổng quan
- 🔄 Sơ đồ luồng yêu cầu
- 🔑 Bảng các lớp chính
- 📝 Các giao diện chính
- 🧪 Thống kê kiểm thử
- 🔐 Ma trận phân quyền
- 🎯 Nguyên tắc DDD
- 📌 Các mẫu phổ biến
- 🔍 Hướng dẫn tìm kiếm theo chủ đề
**Read this when:** You need quick answers or are new to the module
**Đọc khi:** Bạn cần câu trả lời nhanh hoặc mới làm quen với mô-đun
---
### 3. **INQUIRIES_COMPLETE_FILE_INDEX.md** (23 KB)
**Purpose:** Exhaustive file reference
**Best for:** Finding specific files, understanding dependencies, planning modifications
**Mục đích:** Tài liệu tham chiếu tệp đầy đủ
**Phù hợp nhất:** Tìm các tệp cụ thể, hiểu phụ thuộc, lập kế hoạch sửa đổi
Contains:
- 📋 Complete file listing by path
- 📊 File statistics tables
- 🔍 File discovery guide
- 🔗 Dependency graph
- 📝 File cross-references
- 🎯 Entry points for modifications
- Line count for each file
- Detailed method descriptions
Nội dung:
- 📋 Danh sách tệp đầy đủ theo đường dẫn
- 📊 Bảng thống kê tệp
- 🔍 Hướng dẫn khám phá tệp
- 🔗 Đồ thị phụ thuộc
- 📝 Tham chiếu chéo tệp
- 🎯 Điểm vào để sửa đổi
- Số dòng của từng tệp
- Mô tả phương thức chi tiết
**Read this when:** You need file-by-file details or planning changes
**Đọc khi:** Bạn cần chi tiết từng tệp hoặc đang lập kế hoạch thay đổi
---
## 🎯 QUICK START BY USE CASE
## 🎯 KHỞI ĐẦU NHANH THEO TRƯỜNG HỢP SỬ DỤNG
### I want to understand the overall architecture
Start with **Quick Reference**Dive into **Exploration**
### Tôi muốn hiểu kiến trúc tổng thể
Bắt đầu với **Quick Reference**Đi sâu vào **Exploration**
### I'm new to this module
Start with **Quick Reference**Browse **File Index** as needed
### Tôi mới làm quen với mô-đun này
Bắt đầu với **Quick Reference**Duyệt **File Index** khi cần
### I need to add a new endpoint
Check **File Index** → Entry Points section → Follow the guide
### Tôi cần thêm một endpoint mới
Xem **File Index** Mục Entry Points → Làm theo hướng dẫn
### I need to understand a specific layer
Search **Quick Reference** for layer → Read full details in **Exploration**
### Tôi cần hiểu một tầng cụ thể
Tìm kiếm trong **Quick Reference** theo tầng → Đọc chi tiết đầy đủ trong **Exploration**
### I'm looking for a specific class or method
Use **File Index** → File Discovery Guide section
### Tôi đang tìm một lớp hoặc phương thức cụ thể
Dùng **File Index** Mục File Discovery Guide
### I need to understand data flow
**Quick Reference** → Request Flows section
### Tôi cần hiểu luồng dữ liệu
**Quick Reference** Mục Request Flows
### I'm fixing a bug or refactoring
### Tôi đang sửa lỗi hoặc tái cấu trúc
**File Index** → Dependency Graph & Cross-References
---
## 📊 MODULE SNAPSHOT
## 📊 TỔNG QUAN MÔ-ĐUN
```
Location: apps/api/src/modules/inquiries/
@@ -102,19 +102,19 @@ Tests: 24 test cases across 6 suites
Endpoints: 4 HTTP endpoints
```
### Layer Breakdown
### Phân Tích Theo Tầng
| Layer | Files | Purpose |
|-------|-------|---------|
| **Presentation** | 5 | HTTP endpoints + validation |
| **Application** | 8 | Commands/Queries + orchestration |
| **Domain** | 6 | Business logic + contracts |
| **Infrastructure** | 1 | Prisma persistence |
| **Module** | 2 | Configuration + exports |
| Tầng | Tệp | Mục đích |
|------|-----|----------|
| **Presentation** | 5 | Điểm cuối HTTP + xác thực |
| **Application** | 8 | Lệnh/Truy vấn + điều phối |
| **Domain** | 6 | Logic nghiệp vụ + hợp đồng |
| **Infrastructure** | 1 | Lưu trữ Prisma |
| **Module** | 2 | Cấu hình + xuất |
---
## 🗂️ FILE TREE
## 🗂️ CÂY TỆP
```
inquiries/
@@ -170,100 +170,100 @@ inquiries/
---
## 🔄 REQUEST FLOWS
## 🔄 LUỒNG YÊU CẦU
### Create Inquiry
### Tạo Yêu Cầu
```
POST /inquiries
→ Controller validates JWT
→ CreateInquiryCommand dispatched
→ CreateInquiryHandler executes:
Validate listing exists
Create InquiryEntity
Save to repository
• Publish InquiryCreatedEvent
→ Controller xác thực JWT
→ CreateInquiryCommand được gửi đi
→ CreateInquiryHandler thực thi:
Xác thực listing tồn tại
Tạo InquiryEntity
Lưu vào repository
• Phát hành InquiryCreatedEvent
→ Response: { id, listingId, createdAt }
```
### Mark as Read
### Đánh Dấu Đã Đọc
```
PATCH /inquiries/:id/read (AGENT only)
→ Controller validates JWT + AGENT role
→ MarkInquiryReadCommand dispatched
→ MarkInquiryReadHandler executes:
Load inquiry entity
Verify agent owns listing
Update entity state
Persist change
• Publish InquiryReadEvent
PATCH /inquiries/:id/read (chỉ AGENT)
→ Controller xác thực JWT + vai trò AGENT
→ MarkInquiryReadCommand được gửi đi
→ MarkInquiryReadHandler thực thi:
Tải entity yêu cầu
Xác minh agent sở hữu listing
Cập nhật trạng thái entity
Lưu thay đổi
• Phát hành InquiryReadEvent
→ Response: { success: true }
```
### List Inquiries
### Lit Kê Yêu Cầu
```
GET /inquiries/listing/:id or /agent/me
→ Controller validates JWT (+ AGENT for /agent/me)
Query dispatched
→ Handler resolves pagination
→ Repository executes paginated query
→ Controller xác thực JWT (+ AGENT cho /agent/me)
Truy vấn được gửi đi
→ Handler xử lý phân trang
→ Repository thực thi truy vấn phân trang
→ Response: PaginatedResult<InquiryReadDto>
```
---
## 🔑 KEY CONCEPTS
## 🔑 CÁC KHÁI NIỆM CHÍNH
### DDD (Domain-Driven Design)
- **Domain Entity:** `InquiryEntity` encapsulates inquiry logic
### DDD (Thiết Kế Hướng Miền)
- **Domain Entity:** `InquiryEntity` đóng gói logic yêu cầu
- **Domain Events:** `InquiryCreatedEvent`, `InquiryReadEvent`
- **Repository Pattern:** Interface in domain, implementation in infrastructure
- **Aggregate Root:** InquiryEntity manages state transitions
- **Repository Pattern:** Giao diện ở tầng domain, triển khai ở tầng infrastructure
- **Aggregate Root:** InquiryEntity quản lý các chuyển đổi trạng thái
### CQRS (Command Query Responsibility Segregation)
- **Commands:** CreateInquiryCommand, MarkInquiryReadCommand (write operations)
- **Queries:** GetInquiriesByListingQuery, GetInquiriesByAgentQuery (read operations)
- **Handlers:** Separate classes for each command/query
### CQRS (Phân Tách Trách Nhiệm Lệnh - Truy Vấn)
- **Commands:** CreateInquiryCommand, MarkInquiryReadCommand (thao tác ghi)
- **Queries:** GetInquiriesByListingQuery, GetInquiriesByAgentQuery (thao tác đọc)
- **Handlers:** Các lớp riêng biệt cho từng lệnh/truy vấn
### Clean Architecture Layers
1. **Presentation:** HTTP endpoints, DTOs, decorators
2. **Application:** Commands/Queries, handlers, coordination
3. **Domain:** Business logic, entities, events, interfaces
4. **Infrastructure:** Database, persistence implementation
### Các Tầng Clean Architecture
1. **Presentation:** Điểm cuối HTTP, DTO, decorator
2. **Application:** Lệnh/Truy vấn, trình xử lý, điều phối
3. **Domain:** Logic nghiệp vụ, entity, sự kiện, giao diện
4. **Infrastructure:** Cơ sở dữ liệu, triển khai lưu trữ
---
## 🧪 TEST COVERAGE
## 🧪 ĐỘ PHỦ KIỂM THỬ
**Total:** 24 tests across 6 test suites
**Tổng cộng:** 24 kiểm thử trên 6 bộ kiểm thử
| Test Suite | Tests | Focus |
|-----------|-------|-------|
| Domain Entity | 5 | Aggregate behavior, events |
| CreateInquiryHandler | 4 | Happy path, validation, events |
| MarkInquiryReadHandler | 5 | Happy path, auth, errors |
| GetInquiriesByListingHandler | 2 | Pagination, empty results |
| GetInquiriesByAgentHandler | 2 | Results, agent lookup |
| InquiriesController | 6 | All endpoints, defaults |
| Bộ kiểm thử | Kiểm thử | Trọng tâm |
|-------------|----------|-----------|
| Domain Entity | 5 | Hành vi aggregate, sự kiện |
| CreateInquiryHandler | 4 | Luồng thành công, xác thực, sự kiện |
| MarkInquiryReadHandler | 5 | Luồng thành công, xác thực, lỗi |
| GetInquiriesByListingHandler | 2 | Phân trang, kết quả rỗng |
| GetInquiriesByAgentHandler | 2 | Kết quả, tra cứu agent |
| InquiriesController | 6 | Tất cả endpoint, giá trị mặc định |
---
## 🔐 Security
## 🔐 Bảo Mật
**Authentication:** All endpoints require JWT token
**Authorization:** RBAC with AGENT role for certain endpoints
**Xác thực:** Tất cả endpoint yêu cầu token JWT
**Phân quyền:** RBAC với vai trò AGENT cho các endpoint nhất định
### Endpoint Security Matrix
### Ma Trận Bảo Mật Endpoint
| Endpoint | Auth | Role | Extra Checks |
|----------|------|------|--------------|
| POST /inquiries | JWT | Any | Listing exists |
| GET /listing/:id | JWT | Any | - |
| Endpoint | Xác thực | Vai trò | Kiểm tra thêm |
|----------|----------|---------|---------------|
| POST /inquiries | JWT | Bất kỳ | Listing tồn tại |
| GET /listing/:id | JWT | Bất kỳ | - |
| GET /agent/me | JWT | AGENT | - |
| PATCH /:id/read | JWT | AGENT | Agent owns listing |
| PATCH /:id/read | JWT | AGENT | Agent sở hữu listing |
---
## 📡 API CONTRACTS
## 📡 HỢP ĐỒNG API
### POST /inquiries
```
@@ -294,137 +294,137 @@ Status: 200 | 401 | 403 | 404
---
## 🚀 GETTING STARTED
## 🚀 BẮT ĐẦU
### For Understanding the Code
1. Read **Quick Reference** (5 min)
2. Review **Request Flows** (5 min)
3. Explore specific layers in **Exploration** as needed
### Để Hiểu Mã Nguồn
1. Đọc **Quick Reference** (5 phút)
2. Xem lại **Request Flows** (5 phút)
3. Khám phá các tầng cụ thể trong **Exploration** khi cần
### For Adding Features
1. Check **File Index** → Entry Points (2 min)
2. Follow the modification guide (varies)
3. Check existing tests for patterns
### Để Thêm Tính Năng
1. Xem **File Index** Mục Entry Points (2 phút)
2. Làm theo hướng dẫn sửa đổi (thời gian khác nhau)
3. Kiểm tra các kiểm thử hiện có để học theo mẫu
### For Debugging
1. Identify the layer (presentation/application/domain/infrastructure)
2. Find the file in **File Index**
3. Check tests for expected behavior
### Để Gỡ Lỗi
1. Xác định tầng (presentation/application/domain/infrastructure)
2. Tìm tệp trong **File Index**
3. Kiểm tra kiểm thử để biết hành vi mong đợi
---
## 📋 COMMON PATTERNS
## 📋 CÁC MẪU PHỔ BIẾN
### Adding a Command
1. Create `application/commands/[name]/[name].command.ts`
2. Create `application/commands/[name]/[name].handler.ts`
3. Implement `ICommandHandler<YourCommand>`
4. Register in `inquiries.module.ts` CommandHandlers array
5. Add tests in `application/__tests__/`
### Thêm một Command
1. Tạo `application/commands/[name]/[name].command.ts`
2. Tạo `application/commands/[name]/[name].handler.ts`
3. Triển khai `ICommandHandler<YourCommand>`
4. Đăng ký trong mảng CommandHandlers của `inquiries.module.ts`
5. Thêm kiểm thử vào `application/__tests__/`
### Adding a Query
1. Create `application/queries/[name]/[name].query.ts`
2. Create `application/queries/[name]/[name].handler.ts`
3. Implement `IQueryHandler<YourQuery>`
4. Register in `inquiries.module.ts` QueryHandlers array
5. Add tests in `application/__tests__/`
### Thêm một Query
1. Tạo `application/queries/[name]/[name].query.ts`
2. Tạo `application/queries/[name]/[name].handler.ts`
3. Triển khai `IQueryHandler<YourQuery>`
4. Đăng ký trong mảng QueryHandlers của `inquiries.module.ts`
5. Thêm kiểm thử vào `application/__tests__/`
### Adding an Endpoint
1. Add method to `InquiriesController`
2. Add DTOs if needed to `presentation/dto/`
3. Dispatch command/query via bus
4. Add tests to `presentation/__tests__/`
### Thêm một Endpoint
1. Thêm phương thức vào `InquiriesController`
2. Thêm DTO nếu cần vào `presentation/dto/`
3. Gửi command/query qua bus
4. Thêm kiểm thử vào `presentation/__tests__/`
---
## 🔗 EXTERNAL DEPENDENCIES
## 🔗 PHỤ THUỘC BÊN NGOÀI
**Core:**
**Cốt lõi:**
- `@nestjs/common` - Framework
- `@nestjs/cqrs` - CQRS bus
- `@prisma/client` - ORM
**Validation:**
- `class-validator` - DTO validation
- `class-transformer` - Type transformation
**Xác thực:**
- `class-validator` - Xác thực DTO
- `class-transformer` - Chuyển đổi kiểu
**Documentation:**
- `@nestjs/swagger` - OpenAPI docs
**Tài liệu:**
- `@nestjs/swagger` - Tài liệu OpenAPI
**Internal:**
**Nội bộ:**
- `@modules/shared` - AggregateRoot, exceptions
- `@modules/auth` - JWT guards, decorators
---
## 📈 QUALITY METRICS
## 📈 CHỈ SỐ CHẤT LƯỢNG
| Aspect | Rating | Notes |
|--------|--------|-------|
| Architecture | ⭐⭐⭐⭐⭐ | Clean DDD + CQRS |
| Organization | ⭐⭐⭐⭐⭐ | Clear layer separation |
| Type Safety | ⭐⭐⭐⭐⭐ | Full TypeScript |
| Tests | ⭐⭐⭐⭐☆ | 24 tests, good depth |
| Auth | ⭐⭐⭐⭐⭐ | Proper RBAC |
| Maintainability | ⭐⭐⭐⭐⭐ | Easy to extend |
| Khía cạnh | Đánh giá | Ghi chú |
|-----------|----------|---------|
| Kiến trúc | ⭐⭐⭐⭐⭐ | DDD + CQRS sạch |
| Tổ chức | ⭐⭐⭐⭐⭐ | Phân tách tầng rõ ràng |
| An toàn kiểu | ⭐⭐⭐⭐⭐ | TypeScript đầy đủ |
| Kiểm thử | ⭐⭐⭐⭐☆ | 24 kiểm thử, chiều sâu tốt |
| Xác thực | ⭐⭐⭐⭐⭐ | RBAC đúng chuẩn |
| Khả năng bảo trì | ⭐⭐⭐⭐⭐ | Dễ mở rộng |
---
## 💡 ARCHITECTURAL HIGHLIGHTS
## 💡 ĐIỂM NỔI BẬT VỀ KIẾN TRÚC
**Separation of Concerns** - Each layer has single responsibility
**Dependency Inversion** - Depend on abstractions, not concrete implementations
**Event-Driven** - Domain events for business significance
**CQRS** - Read/write paths separate and optimizable
**Type Safety** - Full TypeScript with no any types
**Testability** - All layers independently testable
**Extensibility** - Easy to add new commands/queries
**Phân tách mối quan tâm** - Mỗi tầng có trách nhiệm đơn lẻ
**Đảo ngược phụ thuộc** - Phụ thuộc vào trừu tượng, không phải triển khai cụ thể
**Hướng sự kiện** - Sự kiện miền cho ý nghĩa nghiệp vụ
**CQRS** - Luồng đọc/ghi tách biệt và có thể tối ưu hóa
**An toàn kiểu** - TypeScript đầy đủ, không có kiểu `any`
**Khả năng kiểm thử** - Tất cả tầng có thể kiểm thử độc lập
**Khả năng mở rộng** - Dễ thêm command/query mới
---
## 🎓 LEARNING PATH
## 🎓 LỘ TRÌNH HỌC TẬP
**Beginner:** Read Quick Reference → Understand layers → Look at controller
**Intermediate:** Study handlersReview entities → Examine tests
**Advanced:** Deep dive into event sourcing → Pagination → Optimization patterns
**Người mới bắt đầu:** Đọc Quick Reference → Hiểu các tầng → Xem controller
**Trung cấp:** Nghiên cứu các handler → Xem lại entity → Kiểm tra kiểm thử
**Nâng cao:** Đi sâu vào event sourcing → Phân trang → Các mẫu tối ưu hóa
---
## 📞 REFERENCE QUICK LINKS
## 📞 LIÊN KẾT THAM CHIẾU NHANH
Within documentation files:
Trong các tệp tài liệu:
**Quick Reference:**
- Files by layer
- Request flows
- Authorization matrix
- Entry points for changes
- Các tệp theo tầng
- Luồng yêu cầu
- Ma trận phân quyền
- Điểm vào để thay đổi
**File Index:**
- Complete file descriptions
- Dependency graph
- Cross-references
- Modification guide
- Mô tả tệp đầy đủ
- Đồ thị phụ thuộc
- Tham chiếu chéo
- Hướng dẫn sửa đổi
**Exploration:**
- Architecture diagrams
- Design patterns
- Security details
- Test coverage analysis
- Sơ đồ kiến trúc
- Các mẫu thiết kế
- Chi tiết bảo mật
- Phân tích độ phủ kiểm thử
---
## ✨ Next Steps
## ✨ Bước Tiếp Theo
1. **Read the Quick Reference** to get oriented
2. **Pick a documentation file** based on your need
3. **Use the discovery guides** to find specific information
4. **Follow the modification guides** when making changes
5. **Check tests** for expected behavior
1. **Đọc Quick Reference** để định hướng
2. **Chọn tệp tài liệu** phù hợp với nhu cầu của bạn
3. **Dùng hướng dẫn khám phá** để tìm thông tin cụ thể
4. **Làm theo hướng dẫn sửa đổi** khi thực hiện thay đổi
5. **Kiểm tra kiểm thử** để biết hành vi mong đợi
---
**Happy exploring! 🚀**
**Khám phá vui vẻ! 🚀**
Generated: April 11, 2026
Documentation Status: ✅ Complete
Ngày tạo: 11 tháng 4, 2026
Trạng thái tài liệu: ✅ Hoàn chỉnh