docs: dịch 22 file Markdown còn lại sang tiếng Việt có dấu (TEC-2881)
Some checks failed
CI / Lint → Typecheck → Test → Build (22) (push) Failing after 18s
CI / E2E Tests (push) Has been skipped
CodeQL Analysis / CodeQL (javascript-typescript) (push) Failing after 2m15s
Deploy / Build API Image (push) Failing after 28s
Deploy / Build Web Image (push) Failing after 16s
Deploy / Build AI Services Image (push) Failing after 17s
E2E Tests / Playwright E2E (push) Failing after 31s
Security Scanning / Dependency Audit (pnpm) (push) Failing after 3s
Security Scanning / Trivy Scan — API Image (push) Failing after 1m46s
Security Scanning / Trivy Scan — Web Image (push) Failing after 1m7s
Security Scanning / Trivy Scan — AI Services Image (push) Failing after 53s
Security Scanning / Trivy Filesystem Scan (push) Failing after 35s
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
Security Scanning / Security Gate (push) Failing after 0s
Deploy / Rollback Staging (push) Has been skipped
Deploy / Rollback Production (push) Has been skipped

Hoàn tất đợt cuối của nhiệm vụ chuyển toàn bộ tài liệu sang tiếng Việt.
Đã dịch 22 file `.md` còn sót (~9.7k dòng) — gồm RUNBOOK, audits,
docs/architecture, docs/load-testing, libs READMEs và các quick references.
Giữ nguyên code blocks, đường dẫn, identifier kỹ thuật, URL và biến môi trường.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-19 03:26:14 +07:00
parent 11f2bf26e6
commit d8b409a9ab
22 changed files with 3697 additions and 3703 deletions

View File

@@ -1,17 +1,17 @@
# GoodGo Platform API — K6 Load Testing Guide
# GoodGo Platform API — Hướng Dẫn K6 Load Testing
## 🎯 Quick Summary
## 🎯 Tóm Tắt Nhanh
**Base URL**: `http://localhost:3001/api/v1`
**Node Version**: >= 22.0.0
**Phiên bản Node**: >= 22.0.0
**Testing Framework**: Playwright (E2E), Vitest (Unit)
**No existing K6 or load testing setup found**
**Chưa có thiết lập K6 hoặc load testing nào tồn tại**
---
## 📋 Project Structure
## 📋 Cấu Trúc Dự Án
### Root Directory
### Thư Mục Gốc
```
goodgo-platform/
├── apps/api # NestJS backend (port 3001)
@@ -25,7 +25,7 @@ goodgo-platform/
└── playwright.config.ts # Playwright configuration
```
### Key Scripts (package.json)
### Các Script Chính (package.json)
```bash
pnpm dev # Start all apps (API :3001, Web :3000)
pnpm test # Unit tests via Vitest (API only)
@@ -39,11 +39,11 @@ pnpm typecheck # TypeScript checking
---
## 🏗️ API Module Structure
## 🏗️ Cấu Trúc Module API
### API Base Architecture: `apps/api/src/modules/`
### Kiến Trúc Cơ Sở API: `apps/api/src/modules/`
Each module follows DDD layers: `domain/``application/``infrastructure/``presentation/`
Mỗi module tuân theo các tầng DDD: `domain/``application/``infrastructure/``presentation/`
```
modules/
@@ -64,22 +64,22 @@ modules/
---
## 🔐 AUTH MODULE
## 🔐 MODULE AUTH
### Controllers & Endpoints
#### File: `apps/api/src/modules/auth/presentation/controllers/auth.controller.ts`
| Method | Endpoint | Rate Limit | Auth | Description |
| Method | Endpoint | Rate Limit | Auth | Mô tả |
|--------|----------|-----------|------|-------------|
| POST | `/auth/register` | 5/hour | No | Register new user |
| POST | `/auth/login` | 5/hour | LocalAuth | Login with phone + password |
| POST | `/auth/refresh` | 5/hour | No | Refresh access token |
| POST | `/auth/logout` | No limit | No | Clear auth cookies |
| POST | `/auth/exchange-token` | No limit | No | Exchange OAuth tokens for cookies |
| GET | `/auth/profile` | No limit | JWT | Get current user profile |
| GET | `/auth/profile/agent` | No limit | JWT | Get agent profile for user |
| PATCH | `/auth/kyc` | No limit | JWT+Admin | Verify user KYC (admin only) |
| POST | `/auth/register` | 5/giờ | Không | Đăng ký người dùng mới |
| POST | `/auth/login` | 5/giờ | LocalAuth | Đăng nhập bằng số điện thoại + mật khẩu |
| POST | `/auth/refresh` | 5/giờ | Không | Làm mới access token |
| POST | `/auth/logout` | Không giới hạn | Không | Xóa cookie xác thực |
| POST | `/auth/exchange-token` | Không giới hạn | Không | Đổi OAuth token lấy cookie |
| GET | `/auth/profile` | Không giới hạn | JWT | Lấy hồ sơ người dùng hiện tại |
| GET | `/auth/profile/agent` | Không giới hạn | JWT | Lấy hồ sơ agent của người dùng |
| PATCH | `/auth/kyc` | Không giới hạn | JWT+Admin | Xác minh KYC người dùng (chỉ admin) |
### DTOs
@@ -117,50 +117,50 @@ modules/
}
```
### Cookies & Authentication
### Cookies & Xác Thực
**Access Token**:
- Cookie: `access_token`
- Max Age: 15 minutes (900s)
- Max Age: 15 phút (900s)
- HttpOnly: true
- Secure: true (production only)
- Secure: true (chỉ production)
- SameSite: strict
- Path: /
**Refresh Token**:
- Cookie: `refresh_token`
- Max Age: 30 days
- Max Age: 30 ngày
- HttpOnly: true
- Secure: true (production only)
- Secure: true (chỉ production)
- SameSite: strict
- Path: `/auth`
**Session Indicator**:
**Chỉ Báo Phiên**:
- Cookie: `goodgo_authenticated` = "1"
- HttpOnly: false (visible to frontend)
- HttpOnly: false (frontend nhìn thấy được)
### OAuth Support
### Hỗ Trợ OAuth
- Google OAuth 2.0
- Zalo OAuth (Vietnamese platform)
- Zalo OAuth (nền tảng Việt Nam)
- Environment: `GOOGLE_CLIENT_ID`, `GOOGLE_CLIENT_SECRET`, `ZALO_APP_ID`, `ZALO_APP_SECRET`
---
## 🏠 LISTINGS MODULE
## 🏠 MODULE LISTINGS
### Controllers & Endpoints
#### File: `apps/api/src/modules/listings/presentation/controllers/listings.controller.ts`
| Method | Endpoint | Auth | Quota | Description |
| Method | Endpoint | Auth | Quota | Mô tả |
|--------|----------|------|-------|-------------|
| POST | `/listings` | JWT | Yes | Create new listing |
| GET | `/listings` | No | No | Search/filter listings (public) |
| GET | `/listings/:id` | No | No | Get listing detail |
| GET | `/listings/pending` | JWT+Admin | No | Get listings pending moderation |
| PATCH | `/listings/:id/status` | JWT | No | Update listing status |
| POST | `/listings/:id/media` | JWT | No | Upload photo/video |
| PATCH | `/listings/:id/moderate` | JWT+Admin | No | Moderate a listing (admin) |
| POST | `/listings` | JWT | Có | Tạo listing mới |
| GET | `/listings` | Không | Không | Tìm kiếm/lọc listing (công khai) |
| GET | `/listings/:id` | Không | Không | Lấy chi tiết listing |
| GET | `/listings/pending` | JWT+Admin | Không | Lấy listing đang chờ kiểm duyệt |
| PATCH | `/listings/:id/status` | JWT | Không | Cập nhật trạng thái listing |
| POST | `/listings/:id/media` | JWT | Không | Tải lên ảnh/video |
| PATCH | `/listings/:id/moderate` | JWT+Admin | Không | Kiểm duyệt listing (admin) |
### DTOs
@@ -233,10 +233,10 @@ modules/
}
```
### Response Structures
### Cấu Trúc Phản Hồi
#### ListingDetailData
Contains full listing information including:
Chứa thông tin đầy đủ về listing bao gồm:
- id, title, description
- propertyType, transactionType
- address, latitude, longitude, ward, district, city
@@ -244,7 +244,7 @@ Contains full listing information including:
- areaM2, usableAreaM2, bedrooms, bathrooms, floors
- amenities, nearbyPOIs
- legalStatus, yearBuilt, direction
- mediaUrls (photos/videos)
- mediaUrls (ảnh/video)
- agentInfo
- createdAt, updatedAt
@@ -261,19 +261,19 @@ Contains full listing information including:
---
## 💳 PAYMENTS MODULE
## 💳 MODULE PAYMENTS
### Controllers & Endpoints
#### File: `apps/api/src/modules/payments/presentation/controllers/payments.controller.ts`
| Method | Endpoint | Auth | Rate Limit | Description |
| Method | Endpoint | Auth | Rate Limit | Mô tả |
|--------|----------|------|-----------|-------------|
| POST | `/payments` | JWT | No | Create payment |
| GET | `/payments` | JWT | No | List user transactions |
| GET | `/payments/:id` | JWT | No | Get payment status |
| POST | `/payments/callback/:provider` | No | 20/min | Handle payment callback (webhook) |
| POST | `/payments/:id/refund` | JWT+Admin | No | Refund payment (admin) |
| POST | `/payments` | JWT | Không | Tạo thanh toán |
| GET | `/payments` | JWT | Không | Lit kê giao dịch của người dùng |
| GET | `/payments/:id` | JWT | Không | Lấy trạng thái thanh toán |
| POST | `/payments/callback/:provider` | Không | 20/phút | Xử lý callback thanh toán (webhook) |
| POST | `/payments/:id/refund` | JWT+Admin | Không | Hoàn tiền (admin) |
### DTOs
@@ -306,47 +306,47 @@ Contains full listing information including:
}
```
### Payment Providers
### Nhà Cung Cấp Thanh Toán
- **VNPay** (Primary for Vietnam)
- **VNPay** (Chính cho Việt Nam)
- Environment: `VNPAY_TMN_CODE`, `VNPAY_HASH_SECRET`
- Sandbox: `https://sandbox.vnpayment.vn/paymentv2/vpcpay.html`
- API: `https://sandbox.vnpayment.vn/merchant_webapi/api/transaction`
- **MoMo** (Mobile wallet)
- **MoMo** (Ví di động)
- Environment: `MOMO_PARTNER_CODE`, `MOMO_ACCESS_KEY`, `MOMO_SECRET_KEY`
- Endpoint: `https://test-payment.momo.vn/v2/gateway/api`
- **ZaloPay** (Zalo integrated)
- **ZaloPay** (Tích hợp Zalo)
- Environment: `ZALOPAY_APP_ID`, `ZALOPAY_KEY1`, `ZALOPAY_KEY2`
- Endpoint: `https://sb-openapi.zalopay.vn/v2`
### Callback Processing
### Xử Lý Callback
**Webhook URL Pattern**: `/payments/callback/{provider}`
**Mẫu URL Webhook**: `/payments/callback/{provider}`
Supports both:
Hỗ trợ cả:
- Query parameters (VNPay)
- Request body (MoMo, ZaloPay)
- Merged data handling internally
- Xử lý dữ liệu hợp nhất nội bộ
---
## 🔍 SEARCH MODULE
## 🔍 MODULE SEARCH
### Controllers & Endpoints
#### File: `apps/api/src/modules/search/presentation/controllers/search.controller.ts`
| Method | Endpoint | Auth | Description |
| Method | Endpoint | Auth | Mô tả |
|--------|----------|------|-------------|
| GET | `/search` | No | Full-text search (public) |
| GET | `/search/geo` | No | Geographic radius search (public) |
| POST | `/search/reindex` | JWT+Admin | Reindex all properties (admin) |
| GET | `/search` | Không | Tìm kiếm full-text (công khai) |
| GET | `/search/geo` | Không | Tìm kiếm theo bán kính địa lý (công khai) |
| POST | `/search/reindex` | JWT+Admin | Lập chỉ mục lại tất cả bất động sản (admin) |
### DTOs
#### SearchPropertiesDto (Full-text search)
#### SearchPropertiesDto (Tìm kiếm full-text)
```typescript
{
q?: string, // Free-text query, e.g., 'chung cu quan 7'
@@ -365,7 +365,7 @@ Supports both:
}
```
#### GeoSearchDto (Geographic search)
#### GeoSearchDto (Tìm kiếm địa lý)
```typescript
{
lat: number, // Latitude, -90 to 90
@@ -383,11 +383,11 @@ Supports both:
### Search Engine
**Typesense** integration for fast full-text & faceted search
Tích hợp **Typesense** cho tìm kiếm full-text & faceted nhanh
- Environment: `TYPESENSE_HOST`, `TYPESENSE_PORT`, `TYPESENSE_API_KEY`
- Default: `http://localhost:8108`
- Mặc định: `http://localhost:8108`
### Response Structure
### Cấu Trúc Phản Hồi
#### SearchResult
```typescript
@@ -409,7 +409,7 @@ Supports both:
## 🗄️ Database & Environment
### PostgreSQL with PostGIS
### PostgreSQL với PostGIS
```
DB_HOST=localhost
@@ -426,7 +426,7 @@ DATABASE_URL=postgresql://goodgo:password@localhost:5432/goodgo?schema=public
REDIS_URL=redis://localhost:6379
```
### Key Environment Variables
### Các Biến Môi Trường Chính
```bash
# JWT Secrets (REQUIRED)
@@ -472,9 +472,9 @@ LOG_LEVEL=info
---
## 🧪 Existing Test Setup
## 🧪 Thiết Lập Test Hiện Có
### Playwright Configuration
### Cấu Hình Playwright
**File**: `playwright.config.ts`
@@ -490,7 +490,7 @@ Projects:
baseURL: http://localhost:3000
```
### Playwright Scripts
### Các Script Playwright
```bash
pnpm test:e2e # Run all E2E tests
@@ -499,14 +499,14 @@ pnpm test:e2e:web # Web tests only
pnpm test:e2e:report # Show HTML report
```
### Test Database
### Database Test
- CI uses `goodgo_test` database
- Local uses `.env.test` for test database URL
- Migrations & seed run in `global-setup.ts`
- Cleanup in `global-teardown.ts`
- CI sử dụng database `goodgo_test`
- Local sử dụng `.env.test` cho URL database test
- Migration & seed chạy trong `global-setup.ts`
- Dọn dẹp trong `global-teardown.ts`
### Example E2E Test
### Ví Dụ E2E Test
**File**: `e2e/api/auth-register.spec.ts`
@@ -536,51 +536,51 @@ pnpm test:integration # Integration tests
---
## 🔄 CI/CD Setup
## 🔄 Thiết Lập CI/CD
### GitHub Actions Workflows
### Workflow GitHub Actions
#### `ci.yml` - Lint → Typecheck → Test → Build
- Runs on: `push main` and `pull_request`
- Chạy khi: `push main` `pull_request`
- Services: PostgreSQL 16 + PostGIS
- Steps: lint → typecheck → test → build
- Các bước: lint → typecheck → test → build
#### `e2e.yml` - Playwright E2E Tests
- Runs on: `push main` and `pull_request`
- Chạy khi: `push main` `pull_request`
- Services:
- PostgreSQL 16 + PostGIS
- Redis 7
- Typesense 27.1
- MinIO (S3-compatible storage)
- MinIO (lưu trữ tương thích S3)
- Artifacts: HTML report + traces
#### `security.yml` - Code Security
- Dependency scanning
- SAST analysis
#### `security.yml` - Bảo Mật Mã Nguồn
- Quét dependency
- Phân tích SAST
#### `deploy.yml` - Production Deployment
- Docker builds
- Registry push
- Deployment orchestration
#### `deploy.yml` - Triển Khai Production
- Build Docker
- Push registry
- Điều phối triển khai
---
## 📊 Architecture Patterns
## 📊 Mẫu Kiến Trúc
### NestJS CQRS Pattern
### Mẫu CQRS NestJS
Each module uses:
- **Commands** (Write operations)
Mỗi module sử dụng:
- **Commands** (Thao tác ghi)
- `CommandBus.execute(command)`
- Located in `application/commands/`
- Handlers in `application/commands/{command}/`
- Đặt trong `application/commands/`
- Handlers trong `application/commands/{command}/`
- **Queries** (Read operations)
- **Queries** (Thao tác đọc)
- `QueryBus.execute(query)`
- Located in `application/queries/`
- Handlers in `application/queries/{query}/`
- Đặt trong `application/queries/`
- Handlers trong `application/queries/{query}/`
Example:
Ví dụ:
```typescript
// In controller
const result = await this.commandBus.execute(
@@ -594,17 +594,17 @@ const profile = await this.queryBus.execute(
### Guards & Interceptors
- `JwtAuthGuard` - Validates JWT token
- `LocalAuthGuard` - Email/password validation
- `RolesGuard` - Role-based access control
- `QuotaGuard` - Subscription quota enforcement
- `FileValidationPipe` - File upload validation
- `JwtAuthGuard` - Xác thực JWT token
- `LocalAuthGuard` - Xác thực email/mật khẩu
- `RolesGuard` - Kiểm soát truy cập dựa trên vai trò
- `QuotaGuard` - Thi hành hạn ngạch subscription
- `FileValidationPipe` - Xác thực file upload
---
## 🚀 Starting the API
## 🚀 Khởi Động API
### Local Development
### Phát Triển Cục Bộ
```bash
# Install dependencies
@@ -627,7 +627,7 @@ pnpm dev
# Swagger UI: http://localhost:3001/api/v1/docs
```
### With Docker
### Với Docker
```bash
docker-compose up
@@ -636,37 +636,37 @@ docker-compose up
---
## 🎯 K6 Load Testing Recommendations
## 🎯 Khuyến Nghị K6 Load Testing
### Key Endpoints to Test
### Các Endpoint Chính Cần Test
1. **Authentication** (High priority)
1. **Authentication** (Ưu tiên cao)
- Register: `POST /auth/register`
- Login: `POST /auth/login`
- Refresh: `POST /auth/refresh`
- Profile: `GET /auth/profile` (authenticated)
- Profile: `GET /auth/profile` (đã xác thực)
2. **Listings** (High priority)
- Create: `POST /listings` (quota-gated)
- Search: `GET /listings` (public, high volume)
- Detail: `GET /listings/:id` (public, high volume)
2. **Listings** (Ưu tiên cao)
- Create: `POST /listings` (giới hạn quota)
- Search: `GET /listings` (công khai, lưu lượng cao)
- Detail: `GET /listings/:id` (công khai, lưu lượng cao)
3. **Search** (High priority)
- Full-text: `GET /search?q=...` (public, high volume)
- Geo: `GET /search/geo?lat=...&lng=...` (public, high volume)
3. **Search** (Ưu tiên cao)
- Full-text: `GET /search?q=...` (công khai, lưu lượng cao)
- Geo: `GET /search/geo?lat=...&lng=...` (công khai, lưu lượng cao)
4. **Payments** (Medium priority)
- Create: `POST /payments` (authenticated)
- List: `GET /payments` (authenticated)
- Webhook: `POST /payments/callback/:provider` (unthrottled)
4. **Payments** (Ưu tiên trung bình)
- Create: `POST /payments` (đã xác thực)
- List: `GET /payments` (đã xác thực)
- Webhook: `POST /payments/callback/:provider` (không giới hạn throttle)
5. **Admin Endpoints** (Medium priority, restricted)
- Moderate listings: `PATCH /listings/:id/moderate`
- List pending: `GET /listings/pending`
- Verify KYC: `PATCH /auth/kyc`
5. **Endpoint Admin** (Ưu tiên trung bình, hạn chế)
- Kiểm duyệt listing: `PATCH /listings/:id/moderate`
- Liệt kê pending: `GET /listings/pending`
- Xác minh KYC: `PATCH /auth/kyc`
- Reindex: `POST /search/reindex`
### K6 Script Structure
### Cấu Trúc Script K6
```javascript
import http from 'k6/http';
@@ -692,16 +692,16 @@ export default function() {
}
```
### Data Generation Tips
### Mẹo Tạo Dữ Liệu
- Use test fixture users from Playwright tests
- Leverage Prisma seed data (districts, property types)
- Generate realistic search queries
- Test with various geo coordinates (Ho Chi Minh City: ~10.77°N, 106.70°E)
- Sử dụng test fixture user từ Playwright tests
- Tận dụng dữ liệu Prisma seed (quận, loại bất động sản)
- Tạo các truy vấn tìm kiếm thực tế
- Test với các tọa độ địa lý khác nhau (TP.HCM: ~10.77°N, 106.70°E)
---
## 📁 File Locations Quick Reference
## 📁 Tham Khảo Nhanh Vị Trí File
```
apps/api/
@@ -768,38 +768,37 @@ playwright.config.ts # Playwright config
---
## 🔗 Useful Links & References
## 🔗 Liên Kết & Tham Khảo Hữu Ích
- **API Swagger Docs**: `http://localhost:3001/api/v1/docs`
- **Project Root Docs**: `CLAUDE.md`
- **Existing Analysis**: `CODEBASE_ANALYSIS.md`, `EXPLORATION_REPORT.md`
- **Frontend Docs**: `docs/audits/FRONTEND_EXPLORATION.md`
- **Tài Liệu Gốc Dự Án**: `CLAUDE.md`
- **Phân Tích Hiện Có**: `CODEBASE_ANALYSIS.md`, `EXPLORATION_REPORT.md`
- **Tài Liệu Frontend**: `docs/audits/FRONTEND_EXPLORATION.md`
---
## ✅ Summary for K6 Implementation
## ✅ Tóm Tắt Triển Khai K6
**No existing K6 setup** — you have a clean slate!
**Chưa có thiết lập K6 nào** — bạn có một khởi đầu hoàn toàn mới!
**Key endpoints** identified across:
**Các endpoint chính** được xác định trên các module:
- Auth (register, login, refresh, profile)
- Listings (create, search, detail, moderate)
- Search (full-text, geo)
- Payments (create, callback, list, refund)
- Admin (moderate, KYC, reindex)
**Rate limits** to consider:
- Auth: 5/hour per endpoint
- Payments callback: 20/min
- Others: No limit (except quota guards on create operations)
**Rate limit** cần xem xét:
- Auth: 5/giờ mỗi endpoint
- Payments callback: 20/phút
- Khác: Không giới hạn (trừ quota guard cho thao tác create)
**Infrastructure ready**:
- Turbo monorepo for dependency management
- PostgreSQL + PostGIS for spatial data
- Typesense for search indexing
- Redis for caching
- MinIO for media storage
- Prometheus metrics endpoint
**Tests can be integrated** into CI/CD pipeline via `.github/workflows/` (suggested: new `load-test.yml`)
**Hạ tầng sẵn sàng**:
- Turbo monorepo cho quản lý dependency
- PostgreSQL + PostGIS cho dữ liệu không gian
- Typesense cho lập chỉ mục tìm kiếm
- Redis cho caching
- MinIO cho lưu trữ media
- Endpoint Prometheus metrics
**Tests có thể được tích hợp** vào CI/CD pipeline qua `.github/workflows/` (đề xuất: `load-test.yml` mới)

View File

@@ -1,10 +1,10 @@
# K6 Load Testing — Quick Start Guide
# K6 Load Testing — Hướng Dẫn Bắt Đầu Nhanh
Get started with K6 load tests for GoodGo Platform API in minutes.
Bắt đầu với K6 load tests cho GoodGo Platform API trong vài phút.
---
## 1Installation
## 1Cài Đặt
### macOS
```bash
@@ -21,16 +21,16 @@ apt-get install k6
docker pull grafana/k6:latest
```
### Verify Installation
### Xác Minh Cài Đặt
```bash
k6 version
```
---
## 2Setup Test Environment
## 2Thiết Lập Môi Trường Test
### Start API & Database
### Khởi Động API & Database
```bash
# Terminal 1: Start all services
pnpm dev
@@ -39,7 +39,7 @@ pnpm dev
pnpm db:seed
```
### Verify API is Running
### Xác Minh API Đang Chạy
```bash
curl http://localhost:3001/api/v1/docs
# Should return Swagger UI
@@ -47,11 +47,11 @@ curl http://localhost:3001/api/v1/docs
---
## 3Create Your First K6 Test
## 3Tạo Test K6 Đầu Tiên
### Simple Search Load Test
### Search Load Test Đơn Giản
Create file: `load-tests/search.k6.js`
Tạo file: `load-tests/search.k6.js`
```javascript
import http from 'k6/http';
@@ -101,19 +101,19 @@ export default function() {
---
## 4Run Your First Test
## 4Chạy Test Đầu Tiên
### Local Development
### Phát Triển Cục Bộ
```bash
k6 run load-tests/search.k6.js
```
### With Custom Base URL
### Với Base URL Tùy Chỉnh
```bash
BASE_URL=http://localhost:3001/api/v1 k6 run load-tests/search.k6.js
```
### With Docker
### Với Docker
```bash
docker run -i grafana/k6 run - < load-tests/search.k6.js
```
@@ -145,9 +145,9 @@ docker run -i grafana/k6 run - < load-tests/search.k6.js
---
## 5⃣ Authentication Test
## 5 Test Authentication
Create file: `load-tests/auth.k6.js`
Tạo file: `load-tests/auth.k6.js`
```javascript
import http from 'k6/http';
@@ -212,16 +212,16 @@ export default function() {
}
```
### Run Auth Test
### Chạy Auth Test
```bash
k6 run load-tests/auth.k6.js
```
---
## 6Listing Creation Test (Authenticated)
## 6Test Tạo Listing (Đã Xác Thực)
Create file: `load-tests/listings.k6.js`
Tạo file: `load-tests/listings.k6.js`
```javascript
import http from 'k6/http';
@@ -319,16 +319,16 @@ export default function() {
}
```
### Run Listing Test
### Chạy Listing Test
```bash
k6 run load-tests/listings.k6.js
```
---
## 7⃣ Payment Test
## 7 Test Payment
Create file: `load-tests/payments.k6.js`
Tạo file: `load-tests/payments.k6.js`
```javascript
import http from 'k6/http';
@@ -404,16 +404,16 @@ export default function() {
}
```
### Run Payment Test
### Chạy Payment Test
```bash
k6 run load-tests/payments.k6.js
```
---
## 8Run All Tests with Results
## 8Chạy Tất Cả Tests Với Kết Quả
Create file: `load-tests/all-scenarios.k6.js`
Tạo file: `load-tests/all-scenarios.k6.js`
```javascript
import http from 'k6/http';
@@ -472,7 +472,7 @@ export default function() {
}
```
### Run with Summary
### Chạy Với Tóm Tắt
```bash
k6 run load-tests/all-scenarios.k6.js \
--vus=50 \
@@ -482,21 +482,21 @@ k6 run load-tests/all-scenarios.k6.js \
---
## 9Generate Reports
## 9Tạo Báo Cáo
### JSON Report
### Báo Cáo JSON
```bash
k6 run load-tests/search.k6.js --summary-export=report.json
```
### Upload to Grafana Cloud
### Tải Lên Grafana Cloud
```bash
k6 run load-tests/search.k6.js \
--out cloud
# Requires: k6 login or K6_CLOUD_TOKEN env var
```
### Generate HTML Report (with extension)
### Tạo Báo Cáo HTML (với extension)
```bash
k6 run load-tests/search.k6.js \
--out csv=results.csv
@@ -504,9 +504,9 @@ k6 run load-tests/search.k6.js \
---
## 🔟 CI Integration
## 🔟 Tích Hợp CI
Create: `.github/workflows/load-test.yml`
Tạo: `.github/workflows/load-test.yml`
```yaml
name: Load Tests
@@ -576,7 +576,7 @@ jobs:
---
## 📊 Common K6 Checks
## 📊 Các Check K6 Phổ Biến
```javascript
// HTTP Status
@@ -605,55 +605,55 @@ check(res, {
---
## 🛠️ Debugging
## 🛠️ Debug
### Verbose Output
### Output Chi Tiết
```bash
k6 run -v load-tests/search.k6.js
```
### Show Request/Response
### Hiển Thị Request/Response
```bash
k6 run --http-debug=full load-tests/search.k6.js
```
### Limit to Single VU
### Giới Hạn Một VU
```bash
k6 run --vus=1 --iterations=1 load-tests/search.k6.js
```
---
## 📚 Next Steps
## 📚 Bước Tiếp Theo
1. **Read Full Guide**: `K6_LOAD_TESTING_GUIDE.md`
2. **Check Endpoints**: `K6_ENDPOINTS_SUMMARY.md`
3. **Explore K6 Docs**: https://k6.io/docs
4. **Community Scripts**: https://github.com/grafana/k6-templates
1. **Đọc Hướng Dẫn Đầy Đủ**: `K6_LOAD_TESTING_GUIDE.md`
2. **Kiểm Tra Endpoint**: `K6_ENDPOINTS_SUMMARY.md`
3. **Khám Phá Tài Liệu K6**: https://k6.io/docs
4. **Script Cộng Đồng**: https://github.com/grafana/k6-templates
---
## ✅ Troubleshooting
## ✅ Xử Lý Sự Cố
### "connection refused"
- Ensure API is running: `pnpm dev`
- Check port: 3001
- Verify BASE_URL: `http://localhost:3001/api/v1`
- Đảm bảo API đang chạy: `pnpm dev`
- Kiểm tra port: 3001
- Xác minh BASE_URL: `http://localhost:3001/api/v1`
### "rate limit exceeded"
- Auth endpoints: 5/hour limit
- Spread requests or use different test data
- Check test database has seed data
- Endpoint auth: giới hạn 5/giờ
- Phân tán request hoặc dùng dữ liệu test khác
- Kiểm tra database test có dữ liệu seed
### "insufficient credits" (payments)
- Payments require authenticated user
- Create user session first in test
- Use test provider credentials
- Payment yêu cầu người dùng đã xác thực
- Tạo phiên người dùng trước trong test
- Sử dụng thông tin xác thực provider test
### "timeout"
- Increase K6 timeout in options
- Check API logs for errors
- Reduce number of VUs initially
- Tăng K6 timeout trong options
- Kiểm tra log API để tìm lỗi
- Giảm số lượng VU ban đầu
---

View File

@@ -1,75 +1,75 @@
# K6 Load Testing Documentation for GoodGo Platform
# Tài Liệu K6 Load Testing cho GoodGo Platform
Complete guide to understanding and implementing K6 load tests for the GoodGo Platform API.
Hướng dẫn đầy đủ để hiểu và triển khai K6 load tests cho GoodGo Platform API.
---
## 📚 Documentation Files
## 📚 Các File Tài Liệu
This directory contains three comprehensive guides for K6 load testing:
Thư mục này chứa ba hướng dẫn toàn diện về K6 load testing:
### 1. **K6_LOAD_TESTING_GUIDE.md** (Primary Reference)
Comprehensive exploration of the GoodGo Platform API structure for load testing.
### 1. **K6_LOAD_TESTING_GUIDE.md** (Tham Khảo Chính)
Khám phá toàn diện cấu trúc GoodGo Platform API cho load testing.
**Contents:**
- API module structure (auth, listings, payments, search)
- Detailed endpoint documentation with HTTP methods, rate limits, and auth requirements
- Complete DTO specifications with request/response body shapes
- Database and environment configuration reference
- Existing test setup (Playwright, Vitest, CI/CD)
- Architecture patterns (CQRS, DDD)
- File location quick reference
- K6 implementation recommendations
**Nội dung:**
- Cấu trúc module API (auth, listings, payments, search)
- Tài liệu endpoint chi tiết với HTTP method, rate limit và yêu cầu auth
- Đặc tả DTO đầy đủ với hình dạng request/response body
- Tham khảo cấu hình database environment
- Thiết lập test hiện có (Playwright, Vitest, CI/CD)
- Mẫu kiến trúc (CQRS, DDD)
- Tham khảo nhanh vị trí file
- Khuyến nghị triển khai K6
**When to use:** Deep dives into specific endpoints, understanding authentication flows, checking environment variables
**Khi nào sử dụng:** Khi cần đào sâu vào các endpoint cụ thể, hiểu luồng xác thực, kiểm tra biến môi trường
### 2. **K6_ENDPOINTS_SUMMARY.md** (Quick Reference)
Condensed endpoint reference with data shapes for immediate lookup.
### 2. **K6_ENDPOINTS_SUMMARY.md** (Tham Khảo Nhanh)
Tham khảo endpoint cô đọng với hình dạng dữ liệu để tra cứu ngay lập tức.
**Contents:**
- All endpoints in table format (method, path, auth, rate limit)
- Authentication module (register, login, refresh, profile)
- Listings module (CRUD, moderation, media upload)
- Payments module (create, list, callbacks, refund)
- Search module (full-text, geo)
- Request/response body examples (JSON)
- K6 test scenarios (search, auth, listings, payments, webhooks)
- Rate limits summary
- Authentication flow examples (cookies vs tokens)
**Nội dung:**
- Tất cả endpoint dưới dạng bảng (method, path, auth, rate limit)
- Module Authentication (register, login, refresh, profile)
- Module Listings (CRUD, kiểm duyệt, upload media)
- Module Payments (create, list, callback, refund)
- Module Search (full-text, geo)
- Ví dụ request/response body (JSON)
- Các kịch bản test K6 (search, auth, listings, payments, webhook)
- Tóm tắt rate limit
- Ví dụ luồng xác thực (cookies vs tokens)
**When to use:** Quick lookup of endpoint details, copy-paste example payloads, understanding rate limits
**Khi nào sử dụng:** Tra cứu nhanh chi tiết endpoint, sao chép payload mẫu, hiểu rate limit
### 3. **K6_QUICK_START.md** (Executable Examples)
Step-by-step guide with ready-to-run K6 scripts and setup instructions.
### 3. **K6_QUICK_START.md** (Ví Dụ Chạy Được)
Hướng dẫn từng bước với script K6 sẵn sàng chạy và hướng dẫn thiết lập.
**Contents:**
- Installation instructions (macOS, Linux, Docker)
- Environment setup (starting API, seeding database)
- Five runnable K6 scripts:
- Search load test (public, high volume)
- Auth load test (rate-limited registration)
- Listing creation (authenticated, quota-gated)
- Payment processing (authenticated)
- All scenarios combined
- CI integration with GitHub Actions
- Report generation options (JSON, Grafana Cloud, CSV)
- Common K6 checks and patterns
- Debugging and troubleshooting
**Nội dung:**
- Hướng dẫn cài đặt (macOS, Linux, Docker)
- Thiết lập môi trường (khởi động API, seed database)
- Năm script K6 chạy được:
- Search load test (công khai, lưu lượng cao)
- Auth load test (đăng ký bị giới hạn rate)
- Tạo listing (đã xác thực, giới hạn quota)
- Xử lý payment (đã xác thực)
- Tất cả kịch bản kết hợp
- Tích hợp CI với GitHub Actions
- Tùy chọn tạo báo cáo (JSON, Grafana Cloud, CSV)
- Các check K6 và mẫu phổ biến
- Debug và xử lý sự cố
**When to use:** Getting started quickly, running tests immediately, setting up CI/CD
**Khi nào sử dụng:** Bắt đầu nhanh, chạy test ngay, thiết lập CI/CD
---
## 🚀 Quick Start (3 Minutes)
## 🚀 Bắt Đầu Nhanh (3 Phút)
### 1. Install K6
### 1. Cài Đặt K6
```bash
brew install k6 # macOS
# or
apt-get install k6 # Linux
```
### 2. Start API & Database
### 2. Khởi Động API & Database
```bash
pnpm install
pnpm db:generate
@@ -78,39 +78,39 @@ pnpm db:seed
pnpm dev
```
### 3. Run a Load Test
### 3. Chạy Load Test
```bash
# Copy this from K6_QUICK_START.md Step 3
k6 run load-tests/search.k6.js
```
### 4. View Results
K6 prints a summary to console. For more detailed reports, see K6_QUICK_START.md section on report generation.
### 4. Xem Kết Quả
K6 in tóm tắt ra console. Để xem báo cáo chi tiết hơn, xem mục tạo báo cáo trong K6_QUICK_START.md.
---
## 📊 Test Scenarios Implemented
## 📊 Các Kịch Bản Test Đã Triển Khai
| Scenario | File | Focus | VUs | Duration | Key Endpoints |
| Kịch Bản | File | Trọng Tâm | VUs | Thời Lượng | Endpoint Chính |
|----------|------|-------|-----|----------|--------------|
| Search Load | `load-tests/search.k6.js` | Public search performance | 50 | 4m | `GET /search`, `GET /search/geo` |
| Authentication | `load-tests/auth.k6.js` | Auth throughput & rate limits | 10 | 2m | `POST /auth/register`, `POST /auth/login` |
| Listing Creation | `load-tests/listings.k6.js` | Authenticated listing CRUD | 5 | 2m | `POST /listings`, `GET /listings/:id` |
| Payments | `load-tests/payments.k6.js` | Payment initiation & status | 10 | 2m | `POST /payments`, `GET /payments/:id` |
| Combined | `load-tests/all-scenarios.k6.js` | Realistic mixed load | 50 | 5m | Multiple endpoints |
| Search Load | `load-tests/search.k6.js` | Hiệu suất tìm kiếm công khai | 50 | 4m | `GET /search`, `GET /search/geo` |
| Authentication | `load-tests/auth.k6.js` | Throughput auth & rate limit | 10 | 2m | `POST /auth/register`, `POST /auth/login` |
| Tạo Listing | `load-tests/listings.k6.js` | CRUD listing đã xác thực | 5 | 2m | `POST /listings`, `GET /listings/:id` |
| Payments | `load-tests/payments.k6.js` | Khởi tạo & trạng thái thanh toán | 10 | 2m | `POST /payments`, `GET /payments/:id` |
| Combined | `load-tests/all-scenarios.k6.js` | Tải hỗn hợp thực tế | 50 | 5m | Nhiều endpoint |
---
## 🔐 Authentication Methods
## 🔐 Phương Thức Xác Thực
### Option 1: Cookie-Based (Recommended for Browser-Like Tests)
### Tùy Chọn 1: Dựa Trên Cookie (Khuyến nghị cho test giống trình duyệt)
```javascript
const loginRes = http.post(`${BASE_URL}/auth/login`, { phone, password });
// Cookies automatically managed by K6
const profileRes = http.get(`${BASE_URL}/auth/profile`);
```
### Option 2: Bearer Token (Recommended for API-Only Tests)
### Tùy Chọn 2: Bearer Token (Khuyến nghị cho test chỉ API)
```javascript
const loginRes = http.post(`${BASE_URL}/auth/login`, { phone, password });
const { accessToken } = loginRes.json();
@@ -118,40 +118,40 @@ const headers = { Authorization: `Bearer ${accessToken}` };
const profileRes = http.get(`${BASE_URL}/auth/profile`, { headers });
```
See K6_ENDPOINTS_SUMMARY.md for full examples.
Xem K6_ENDPOINTS_SUMMARY.md để xem ví dụ đầy đủ.
---
## 🎯 Key Endpoints by Priority
## 🎯 Endpoint Chính Theo Mức Ưu Tiên
### High Priority (Core Functionality)
| Endpoint | Priority | Why |
### Ưu Tiên Cao (Chức Năng Cốt Lõi)
| Endpoint | Ưu Tiên | Tại sao |
|----------|----------|-----|
| `GET /search` | ⭐⭐⭐ | Public, high-volume query |
| `GET /search/geo` | ⭐⭐⭐ | Geospatial, frequently used |
| `GET /listings` | ⭐⭐⭐ | Public search/filter |
| `GET /listings/:id` | ⭐⭐⭐ | Detail page load |
| `POST /auth/login` | ⭐⭐ | User session creation |
| `POST /auth/register` | ⭐⭐ | Rate-limited, important |
| `GET /search` | ⭐⭐⭐ | Công khai, truy vấn lưu lượng cao |
| `GET /search/geo` | ⭐⭐⭐ | Địa không gian, dùng thường xuyên |
| `GET /listings` | ⭐⭐⭐ | Tìm/lọc công khai |
| `GET /listings/:id` | ⭐⭐⭐ | Tải trang chi tiết |
| `POST /auth/login` | ⭐⭐ | Tạo phiên người dùng |
| `POST /auth/register` | ⭐⭐ | Bị giới hạn rate, quan trọng |
### Medium Priority (Feature-Specific)
| Endpoint | Priority | Why |
### Ưu Tiên Trung Bình (Tính Năng Cụ Thể)
| Endpoint | Ưu Tiên | Tại sao |
|----------|----------|-----|
| `POST /listings` | ⭐⭐ | Quota-gated, authenticated |
| `POST /payments` | ⭐⭐ | External integrations |
| `GET /payments` | ⭐⭐ | User transaction history |
| `POST /payments/callback/:provider` | ⭐⭐ | Webhook handler, critical |
| `POST /listings` | ⭐⭐ | Bị giới hạn quota, đã xác thực |
| `POST /payments` | ⭐⭐ | Tích hợp bên ngoài |
| `GET /payments` | ⭐⭐ | Lịch sử giao dịch người dùng |
| `POST /payments/callback/:provider` | ⭐⭐ | Webhook handler, then chốt |
### Low Priority (Admin/Specialized)
| Endpoint | Priority | Why |
### Ưu Tiên Thấp (Admin/Chuyên Biệt)
| Endpoint | Ưu Tiên | Tại sao |
|----------|----------|-----|
| `PATCH /listings/:id/moderate` | ⭐ | Admin-only |
| `GET /listings/pending` | ⭐ | Admin-only |
| `POST /search/reindex` | ⭐ | Admin-only, scheduled |
| `PATCH /listings/:id/moderate` | ⭐ | Chỉ admin |
| `GET /listings/pending` | ⭐ | Chỉ admin |
| `POST /search/reindex` | ⭐ | Chỉ admin, có lịch |
---
## 📍 API Structure at a Glance
## 📍 Tổng Quan Cấu Trúc API
```
API Base: http://localhost:3001/api/v1
@@ -168,9 +168,9 @@ Modules:
---
## 🗄️ Database Configuration
## 🗄️ Cấu Hình Database
### Local Development
### Phát Triển Cục Bộ
```bash
DATABASE_URL=postgresql://goodgo:password@localhost:5432/goodgo
REDIS_URL=redis://localhost:6379
@@ -178,7 +178,7 @@ TYPESENSE_HOST=localhost
TYPESENSE_PORT=8108
```
### Test Environment (CI)
### Môi Trường Test (CI)
```bash
DATABASE_URL=postgresql://goodgo:goodgo_test_secret@localhost:5432/goodgo_test
REDIS_URL=redis://localhost:6379
@@ -186,23 +186,23 @@ TYPESENSE_HOST=localhost
TYPESENSE_PORT=8108
```
See K6_LOAD_TESTING_GUIDE.md for full environment variables.
Xem K6_LOAD_TESTING_GUIDE.md để biết đầy đủ biến môi trường.
---
## ⚡ Rate Limits
## ⚡ Rate Limit
Respect these limits in your load tests:
Tôn trọng các giới hạn này trong load test của bạn:
| Endpoint | Limit | Window | Action on Exceeded |
| Endpoint | Limit | Cửa Sổ | Hành Động Khi Vượt |
|----------|-------|--------|-------------------|
| `/auth/register` | 5 | per hour | Returns 429 |
| `/auth/login` | 5 | per hour | Returns 429 |
| `/auth/refresh` | 5 | per hour | Returns 429 |
| `/payments/callback/*` | 20 | per minute | Returns 429 |
| All others | None | N/A | Quota gates apply for writes |
| `/auth/register` | 5 | mỗi giờ | Trả về 429 |
| `/auth/login` | 5 | mỗi giờ | Trả về 429 |
| `/auth/refresh` | 5 | mỗi giờ | Trả về 429 |
| `/payments/callback/*` | 20 | mỗi phút | Trả về 429 |
| Tất cả khác | Không có | N/A | Quota gate áp dụng cho thao tác ghi |
**K6 Handling:**
**Xử Lý K6:**
```javascript
check(res, {
'status not rate limited': (r) => r.status !== 429,
@@ -212,7 +212,7 @@ check(res, {
---
## 🏗️ Recommended Test Structure
## 🏗️ Cấu Trúc Test Đề Xuất
```
load-tests/
@@ -228,24 +228,24 @@ load-tests/
└── config.js # Base URL, env, thresholds
```
Example helper structure provided in K6_QUICK_START.md.
Cấu trúc helper mẫu được cung cấp trong K6_QUICK_START.md.
---
## 🧪 Integration with Existing Tests
## 🧪 Tích Hợp Với Các Test Hiện Có
### Complement, Don't Replace
### Bổ Sung, Không Thay Thế
K6 is for **load testing** (performance under concurrent load).
Existing tests serve different purposes:
K6 dành cho **load testing** (hiệu suất dưới tải đồng thời).
Các test hiện có phục vụ các mục đích khác:
| Test Type | Tool | Purpose | When |
| Loại Test | Công Cụ | Mục Đích | Khi Nào |
|-----------|------|---------|------|
| Unit Tests | Vitest | Verify function logic | During development |
| E2E Tests | Playwright | Verify user flows work | Before deployment |
| Load Tests | K6 | Verify performance at scale | Scheduled, on-demand |
| Unit Tests | Vitest | Xác minh logic hàm | Trong quá trình phát triển |
| E2E Tests | Playwright | Xác minh luồng người dùng hoạt động | Trước khi triển khai |
| Load Tests | K6 | Xác minh hiệu suất ở quy mô lớn | Theo lịch, theo yêu cầu |
### Running All Tests
### Chạy Tất Cả Test
```bash
# Unit tests (API only)
@@ -263,11 +263,11 @@ pnpm test && pnpm test:e2e && k6 run load-tests/all-scenarios.k6.js
---
## 📈 CI/CD Integration
## 📈 Tích Hợp CI/CD
### GitHub Actions Workflow
### Workflow GitHub Actions
Create `.github/workflows/load-test.yml` (template in K6_QUICK_START.md section 🔟):
Tạo `.github/workflows/load-test.yml` (mẫu trong K6_QUICK_START.md mục 🔟):
```bash
# Runs on schedule (daily at 2 AM)
@@ -275,7 +275,7 @@ Create `.github/workflows/load-test.yml` (template in K6_QUICK_START.md section
# Reports results as artifacts
```
### Manual Reporting
### Báo Cáo Thủ Công
```bash
# Export JSON
@@ -290,74 +290,74 @@ K6_CLOUD_TOKEN=xxx k6 run load-tests/search.k6.js --out cloud
---
## 🔗 Cross-Reference Guide
## 🔗 Hướng Dẫn Tham Chiếu Chéo
### Looking for...?
### Đang tìm kiếm...?
| Need | Find in |
| Cần | Tìm trong |
|------|----------|
| All endpoint URLs & methods | K6_ENDPOINTS_SUMMARY.md |
| Request/response JSON shapes | K6_ENDPOINTS_SUMMARY.md (📊 Key Data Shapes) |
| DTOs & validation rules | K6_LOAD_TESTING_GUIDE.md (Controllers & DTOs) |
| Rate limit specifics | K6_ENDPOINTS_SUMMARY.md (📌 Important Rate Limits) |
| Authentication flows | K6_ENDPOINTS_SUMMARY.md (🔗 Authentication Flow for K6) |
| Database variables | K6_LOAD_TESTING_GUIDE.md (🗄️ Database & Environment) |
| Ready-to-run scripts | K6_QUICK_START.md (Steps 3-8⃣) |
| CI/CD setup | K6_QUICK_START.md (Step 🔟) |
| Troubleshooting | K6_QUICK_START.md (✅ Troubleshooting) |
| Architecture details | K6_LOAD_TESTING_GUIDE.md (📊 Architecture Patterns) |
| File locations | K6_LOAD_TESTING_GUIDE.md (📁 File Locations Quick Reference) |
| Tất cả URL & method endpoint | K6_ENDPOINTS_SUMMARY.md |
| Hình dạng JSON request/response | K6_ENDPOINTS_SUMMARY.md (📊 Key Data Shapes) |
| DTO & quy tắc validation | K6_LOAD_TESTING_GUIDE.md (Controllers & DTOs) |
| Chi tiết rate limit | K6_ENDPOINTS_SUMMARY.md (📌 Important Rate Limits) |
| Luồng xác thực | K6_ENDPOINTS_SUMMARY.md (🔗 Authentication Flow for K6) |
| Biến database | K6_LOAD_TESTING_GUIDE.md (🗄️ Database & Environment) |
| Script sẵn sàng chạy | K6_QUICK_START.md (Steps 3-8⃣) |
| Thiết lập CI/CD | K6_QUICK_START.md (Step 🔟) |
| Xử lý sự cố | K6_QUICK_START.md (✅ Troubleshooting) |
| Chi tiết kiến trúc | K6_LOAD_TESTING_GUIDE.md (📊 Architecture Patterns) |
| Vị trí file | K6_LOAD_TESTING_GUIDE.md (📁 File Locations Quick Reference) |
---
## 🛠️ Common Tasks
## 🛠️ Công Việc Phổ Biến
### Task: Load Test Search Endpoint
1. Read: K6_ENDPOINTS_SUMMARY.md (🔍 Search section)
2. Use: K6_QUICK_START.md (Step 3⃣ - Search Load Test)
3. Run: `k6 run load-tests/search.k6.js`
### Công Việc: Load Test Endpoint Search
1. Đọc: K6_ENDPOINTS_SUMMARY.md (mục 🔍 Search)
2. Sử dụng: K6_QUICK_START.md (Bước 3⃣ - Search Load Test)
3. Chạy: `k6 run load-tests/search.k6.js`
### Task: Understand Payment Flow
1. Read: K6_LOAD_TESTING_GUIDE.md (💳 PAYMENTS MODULE)
2. Check: K6_ENDPOINTS_SUMMARY.md (💳 Payments section)
3. Use: K6_QUICK_START.md (Step 7⃣ - Payment Test)
### Công Việc: Hiểu Luồng Payment
1. Đọc: K6_LOAD_TESTING_GUIDE.md (💳 PAYMENTS MODULE)
2. Kiểm tra: K6_ENDPOINTS_SUMMARY.md (mục 💳 Payments)
3. Sử dụng: K6_QUICK_START.md (Bước 7⃣ - Payment Test)
### Task: Add New Endpoint to Load Tests
1. Find endpoint in: K6_LOAD_TESTING_GUIDE.md or K6_ENDPOINTS_SUMMARY.md
2. Get data shape from: K6_ENDPOINTS_SUMMARY.md (📊 Key Data Shapes)
3. Check auth from: K6_LOAD_TESTING_GUIDE.md (each module section)
4. Implement using examples in: K6_QUICK_START.md
### Công Việc: Thêm Endpoint Mới Vào Load Tests
1. Tìm endpoint trong: K6_LOAD_TESTING_GUIDE.md hoặc K6_ENDPOINTS_SUMMARY.md
2. Lấy hình dạng dữ liệu từ: K6_ENDPOINTS_SUMMARY.md (📊 Key Data Shapes)
3. Kiểm tra auth từ: K6_LOAD_TESTING_GUIDE.md (mỗi mục module)
4. Triển khai sử dụng ví dụ trong: K6_QUICK_START.md
---
## ✅ Verification Checklist
## ✅ Danh Sách Kiểm Tra Xác Minh
Before running load tests, verify:
Trước khi chạy load test, hãy xác minh:
- [ ] API running: `pnpm dev` (port 3001)
- [ ] Database seeded: `pnpm db:seed`
- [ ] K6 installed: `k6 version`
- [ ] Can reach API: `curl http://localhost:3001/api/v1/docs`
- [ ] ENV variables set: `JWT_SECRET`, `CORS_ORIGINS`, etc.
- [ ] Load test file exists: `load-tests/*.k6.js`
- [ ] Test data available: Check seed in `prisma/seed.ts`
- [ ] API đang chạy: `pnpm dev` (port 3001)
- [ ] Database đã seed: `pnpm db:seed`
- [ ] K6 đã cài đặt: `k6 version`
- [ ] Có thể truy cập API: `curl http://localhost:3001/api/v1/docs`
- [ ] Biến ENV đã set: `JWT_SECRET`, `CORS_ORIGINS`, v.v.
- [ ] File load test tồn tại: `load-tests/*.k6.js`
- [ ] Có sẵn dữ liệu test: Kiểm tra seed trong `prisma/seed.ts`
---
## 📞 Support & References
## 📞 Hỗ Trợ & Tham Khảo
### Internal Documentation
- **Full Architecture**: K6_LOAD_TESTING_GUIDE.md
- **Endpoint Reference**: K6_ENDPOINTS_SUMMARY.md
- **Getting Started**: K6_QUICK_START.md
### Tài Liệu Nội Bộ
- **Kiến Trúc Đầy Đủ**: K6_LOAD_TESTING_GUIDE.md
- **Tham Khảo Endpoint**: K6_ENDPOINTS_SUMMARY.md
- **Bắt Đầu**: K6_QUICK_START.md
### External Resources
- **K6 Official Docs**: https://k6.io/docs
- **K6 API Reference**: https://k6.io/docs/javascript-api
- **K6 Community**: https://community.k6.io
- **K6 Examples**: https://github.com/grafana/k6-templates
### Tài Nguyên Bên Ngoài
- **Tài Liệu Chính Thức K6**: https://k6.io/docs
- **Tham Khảo K6 API**: https://k6.io/docs/javascript-api
- **Cộng Đồng K6**: https://community.k6.io
- **Ví Dụ K6**: https://github.com/grafana/k6-templates
### Project Files
### File Dự Án
- **API Controllers**: `apps/api/src/modules/*/presentation/controllers/`
- **DTOs**: `apps/api/src/modules/*/presentation/dto/`
- **E2E Tests**: `e2e/api/`
@@ -365,40 +365,39 @@ Before running load tests, verify:
---
## 🎓 Learning Path
## 🎓 Lộ Trình Học
### Beginner (30 minutes)
1. Read K6_QUICK_START.md (Steps 1-4)
2. Install K6
3. Run: `k6 run load-tests/search.k6.js`
### Người Mới Bắt Đầu (30 phút)
1. Đọc K6_QUICK_START.md (Bước 1-4)
2. Cài đặt K6
3. Chạy: `k6 run load-tests/search.k6.js`
### Intermediate (1-2 hours)
1. Read K6_ENDPOINTS_SUMMARY.md
2. Understand auth flows
3. Run auth test: `k6 run load-tests/auth.k6.js`
4. Run listing test: `k6 run load-tests/listings.k6.js`
### Trung Cấp (1-2 giờ)
1. Đọc K6_ENDPOINTS_SUMMARY.md
2. Hiểu luồng auth
3. Chạy test auth: `k6 run load-tests/auth.k6.js`
4. Chạy test listing: `k6 run load-tests/listings.k6.js`
### Advanced (2-4 hours)
1. Read K6_LOAD_TESTING_GUIDE.md completely
2. Review controller implementations in source
3. Create custom load test script
4. Set up CI/CD with GitHub Actions (K6_QUICK_START.md Step 🔟)
5. Generate and analyze reports
### Nâng Cao (2-4 giờ)
1. Đọc K6_LOAD_TESTING_GUIDE.md đầy đủ
2. Xem xét triển khai controller trong source
3. Tạo script load test tùy chỉnh
4. Thiết lập CI/CD với GitHub Actions (K6_QUICK_START.md Bước 🔟)
5. Tạo và phân tích báo cáo
---
## 📝 Notes
## 📝 Ghi Chú
- **No existing K6 setup** — These docs provide complete guidance
- **Three complementary docs** — Explore different docs for different needs
- **Executable examples** — K6_QUICK_START.md scripts work as-is
- **Rate limits matter** — Consider them in test design
- **Quota gates** — Some operations (listings, payments) are gated by subscription
- **Test data** — Use seed data or generate unique test users per VU
- **Production ready** — Guides follow K6 best practices
- **Chưa có thiết lập K6 nào** — Tài liệu này cung cấp hướng dẫn đầy đủ
- **Ba tài liệu bổ sung cho nhau** — Khám phá các tài liệu khác nhau cho các nhu cầu khác nhau
- **Ví dụ chạy được** — Script K6_QUICK_START.md hoạt động ngay
- **Rate limit quan trọng** — Hãy xem xét chúng trong thiết kế test
- **Quota gate** — Một số thao tác (listings, payments) bị giới hạn theo subscription
- **Dữ liệu test** — Sử dụng dữ liệu seed hoặc tạo người dùng test duy nhất cho mỗi VU
- **Sẵn sàng cho production** — Hướng dẫn tuân theo các thực hành tốt nhất của K6
---
Generated: 2026-04-09
Last Updated: K6_QUICK_START.md latest
Đã tạo: 2026-04-09
Cập nhật lần cuối: K6_QUICK_START.md mới nhất