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,8 +1,8 @@
# MCP Module Exploration - GoodGo Platform
# Khám Phá Module MCP - Nền Tảng GoodGo
## 1. MODULE STRUCTURE & SOURCE FILES
## 1. CẤU TRÚC MODULE VÀ TỆP NGUỒN
### Directory Structure
### Cấu Trúc Thư Mục
```
apps/api/src/modules/mcp/
├── index.ts
@@ -13,93 +13,93 @@ apps/api/src/modules/mcp/
└── mcp-transport.controller.spec.ts
```
### All Source Files (4 files)
### Tất Cả Tệp Nguồn (4 tệp)
#### 1. **apps/api/src/modules/mcp/index.ts**
- **Type**: Module entry point (exports)
- **Lines**: 1
- **Purpose**: Exports the McpIntegrationModule
- **Exports**: `{ McpIntegrationModule }`
- **Loại**: Điểm vào module (xuất khẩu)
- **Số dòng**: 1
- **Mục đích**: Xuất khẩu McpIntegrationModule
- **Xuất khẩu**: `{ McpIntegrationModule }`
#### 2. **apps/api/src/modules/mcp/mcp.module.ts**
- **Type**: NestJS Module configuration (22 lines)
- **Key Class**: `McpIntegrationModule implements OnModuleInit`
- **Responsibility**:
- Sets up MCP core module with configuration
- Initializes TypesenseClient for MCP registry
- Logs initialized server names on module init
- **Dependencies Injected**:
- `TypesenseClientService` (from SearchModule)
- `McpRegistryService` (from @goodgo/mcp-servers)
- `LoggerService` (from SharedModule)
- **Imports**: SearchModule, AuthModule, McpCoreModule.forRoot()
- **Loại**: Cấu hình Module NestJS (22 dòng)
- **Lớp chính**: `McpIntegrationModule implements OnModuleInit`
- **Trách nhiệm**:
- Thiết lập module MCP cốt lõi với cấu hình
- Khởi tạo TypesenseClient cho registry MCP
- Ghi nhật ký tên máy chủ đã khởi tạo khi module khởi động
- **Các phụ thuộc được tiêm**:
- `TypesenseClientService` (từ SearchModule)
- `McpRegistryService` (từ @goodgo/mcp-servers)
- `LoggerService` (từ SharedModule)
- **Nhập khẩu**: SearchModule, AuthModule, McpCoreModule.forRoot()
- **Controllers**: McpTransportController
- **Lifecycle**: Implements `onModuleInit()`
- **Vòng đời**: Triển khai `onModuleInit()`
#### 3. **apps/api/src/modules/mcp/presentation/mcp-transport.controller.ts**
- **Type**: NestJS Controller (102 lines)
- **Key Class**: `McpTransportController`
- **Responsibility**: HTTP transport layer for MCP SSE connections
- **Decorators**: @ApiTags, @ApiBearerAuth, @Controller, @UseGuards(JwtAuthGuard)
- **Properties**: `transports: Map<string, SSEServerTransport>` (session management)
- **Injected**: `registry: McpRegistryService`
- **Loại**: Controller NestJS (102 dòng)
- **Lớp chính**: `McpTransportController`
- **Trách nhiệm**: Lớp truyền tải HTTP cho các kết nối SSE của MCP
- **Decorator**: @ApiTags, @ApiBearerAuth, @Controller, @UseGuards(JwtAuthGuard)
- **Thuộc tính**: `transports: Map<string, SSEServerTransport>` (quản lý phiên)
- **Được tiêm**: `registry: McpRegistryService`
**Endpoints:**
1. **GET /mcp/servers** - List available MCP servers (Throttle: 30/60s)
2. **GET /mcp/:serverName/sse** - Open SSE connection (Throttle: 5/60s, stricter)
3. **POST /mcp/:serverName/messages** - Send message to session (Throttle: 30/60s)
**Các endpoint:**
1. **GET /mcp/servers** - Lit kê các máy chủ MCP khả dụng (Throttle: 30/60 giây)
2. **GET /mcp/:serverName/sse** - Mở kết nối SSE (Throttle: 5/60 giây, giới hạn chặt hơn)
3. **POST /mcp/:serverName/messages** - Gửi tin nhắn tới phiên (Throttle: 30/60 giây)
#### 4. **apps/api/src/modules/mcp/presentation/__tests__/mcp-transport.controller.spec.ts**
- **Type**: Unit Test Suite (174 lines)
- **Loại**: Bộ kiểm thử đơn vị (174 dòng)
- **Framework**: Vitest
- **Tests**: 11 total in 4 describe blocks
- **Coverage**: Security decorators, listServers, handleSse, handleMessage
- **Kiểm thử**: 11 tổng cộng trong 4 khối describe
- **Phạm vi bao phủ**: Decorator bảo mật, listServers, handleSse, handleMessage
## 2. TEST FILES SUMMARY
## 2. TÓM TẮT CÁC TỆP KIỂM THỬ
### Total: 1 test file (174 lines)
### Tổng cộng: 1 tệp kiểm thử (174 dòng)
**File**: `mcp-transport.controller.spec.ts`
- **Suites**: 4 describe blocks
- **Total Tests**: 11
- **Status**: ✅ Well tested
- **Coverage**: Controller endpoints, security, error handling
**Tệp**: `mcp-transport.controller.spec.ts`
- **Bộ kiểm thử**: 4 khối describe
- **Tổng số kiểm thử**: 11
- **Trạng thái**: ✅ Được kiểm thử đầy đủ
- **Phạm vi bao phủ**: Các endpoint controller, bảo mật, xử lý lỗi
## 3. DDD LAYER STRUCTURE
## 3. CẤU TRÚC LỚP DDD
**Current Status**: SIMPLIFIED (Presentation-only)
**Trạng thái hiện tại**: ĐƠN GIẢN HÓA (chỉ có lớp Presentation)
### ✅ What EXISTS:
- **Presentation Layer**
- `presentation/mcp-transport.controller.ts` (102 lines)
- `presentation/__tests__/mcp-transport.controller.spec.ts` (174 lines)
### ✅ Những gì TỒN TẠI:
- **Lớp Presentation**
- `presentation/mcp-transport.controller.ts` (102 dòng)
- `presentation/__tests__/mcp-transport.controller.spec.ts` (174 dòng)
### ❌ What DOES NOT EXIST:
- **Domain Layer** - No entities, value objects, events
- **Application Layer** - No handlers, commands, queries
- **Infrastructure Layer** - No repositories, adapters
### ❌ Những gì KHÔNG TỒN TẠI:
- **Lớp Domain** - Không có entity, value object, event
- **Lớp Application** - Không có handler, command, query
- **Lớp Infrastructure** - Không có repository, adapter
### Architecture Notes:
- Acts as integration wrapper for @goodgo/mcp-servers
- Simple HTTP-to-SSE bridge
- In-memory session tracking via Map
- No business logic or persistence
### Ghi chú kiến trúc:
- Hoạt động như lớp bọc tích hợp cho @goodgo/mcp-servers
- Cầu nối HTTP-to-SSE đơn giản
- Theo dõi phiên trong bộ nhớ thông qua Map
- Không có logic nghiệp vụ hay lưu trữ dữ liệu
## 4. KEY CLASSES/HANDLERS
## 4. CÁC LỚP/HANDLER CHÍNH
### McpIntegrationModule
- **Status**: ⚠️ Partially tested
- **Methods**: constructor, onModuleInit()
- **Tests Needed**: Module initialization, service integration
- **Trạng thái**: ⚠️ Được kiểm thử một phần
- **Phương thức**: constructor, onModuleInit()
- **Kiểm thử cần thêm**: Khởi tạo module, tích hợp service
### McpTransportController
- **Status**: ✅ Well tested
- **Methods**: listServers(), handleSse(), handleMessage()
- **Tests**: 11 comprehensive tests covering all methods
- **Trạng thái**: ✅ Được kiểm thử đầy đủ
- **Phương thức**: listServers(), handleSse(), handleMessage()
- **Kiểm thử**: 11 bài kiểm thử toàn diện bao phủ tất cả phương thức
## 5. TESTING PATTERNS FROM OTHER MODULES
## 5. MẪU KIỂM THỬ TỪ CÁC MODULE KHÁC
### Pattern 1: Auth Module (Simple Handler)
### Mẫu 1: Module Auth (Handler đơn giản)
```typescript
describe('LoginUserHandler', () => {
let handler: LoginUserHandler;
@@ -117,7 +117,7 @@ describe('LoginUserHandler', () => {
});
```
### Pattern 2: Payments Module (Complex Handler)
### Mẫu 2: Module Payments (Handler phức tạp)
```typescript
describe('CreatePaymentHandler', () => {
let handler: CreatePaymentHandler;
@@ -140,7 +140,7 @@ describe('CreatePaymentHandler', () => {
});
```
### Pattern 3: Domain Entity Testing
### Mẫu 3: Kiểm thử Domain Entity
```typescript
import { describe, it, expect } from 'vitest';
@@ -154,7 +154,7 @@ describe('PaymentEntity', () => {
});
```
### Pattern 4: Infrastructure Service Testing
### Mẫu 4: Kiểm thử Service Infrastructure
```typescript
describe('ZalopayService', () => {
let service: ZalopayService;
@@ -175,21 +175,21 @@ describe('ZalopayService', () => {
});
```
## 6. TESTING CONVENTIONS SUMMARY
## 6. TÓM TẮT QUY ƯỚC KIỂM THỬ
### Framework & Setup
### Framework và Thiết lập
- **Framework**: Vitest
- **Environment**: Node.js
- **Globals**: Enabled
- **File Pattern**: `*.spec.ts`
- **Test Organization**: `__tests__/` subdirectory
- **Môi trường**: Node.js
- **Globals**: Được bật
- **Mẫu tệp**: `*.spec.ts`
- **Tổ chức kiểm thử**: Thư mục con `__tests__/`
### Mocking Patterns
1. **Service Mocks**: `mockService = { method: vi.fn().mockResolvedValue(value) }`
2. **Module Mocks**: `vi.mock('@goodgo/mcp-servers', () => ({ ... }))`
3. **Configuration Mocks**: `get: vi.fn((key) => env[key])`
### Mẫu Mock
1. **Service Mock**: `mockService = { method: vi.fn().mockResolvedValue(value) }`
2. **Module Mock**: `vi.mock('@goodgo/mcp-servers', () => ({ ... }))`
3. **Configuration Mock**: `get: vi.fn((key) => env[key])`
### Test Structure
### Cấu Trúc Kiểm Thử
```typescript
describe('ClassName', () => {
let instance: ClassName;
@@ -210,27 +210,27 @@ describe('ClassName', () => {
});
```
### Test Commands
### Lệnh Kiểm Thử
```bash
# Run MCP tests
# Chạy kiểm thử MCP
pnpm test -- src/modules/mcp
# Watch mode
# Chế độ theo dõi
pnpm test -- --watch src/modules/mcp
# With coverage
# Với độ bao phủ
pnpm test -- --coverage src/modules/mcp
```
## 7. RECOMMENDATIONS
## 7. KHUYẾN NGHỊ
### Immediate
-Maintain controller test coverage
- 📝 Add tests for McpIntegrationModule.onModuleInit()
- 📝 Test module dependency injection
### Tức thì
-Duy trì độ bao phủ kiểm thử controller
- 📝 Thêm kiểm thử cho McpIntegrationModule.onModuleInit()
- 📝 Kiểm thử tiêm phụ thuộc module
### Future
- 🏗️ Add integration tests for full SSE lifecycle
- 🏗️ If domain logic added, follow payments module pattern
- 🏗️ If handlers added, use CQRS patterns from auth/payments modules
### Tương lai
- 🏗️ Thêm kiểm thử tích hợp cho vòng đời SSE đầy đủ
- 🏗️ Nếu thêm logic domain, tuân theo mẫu module payments
- 🏗️ Nếu thêm handler, sử dụng mẫu CQRS từ các module auth/payments