8.0 KiB
Quy Trình Phát Triển Microservices (Microservices Development Process)
Standard development process for creating and maintaining microservices in GoodGo platform. Use when creating new services, migrating services, refactoring services, or planning service implementations.
Quy trình phát triển chuẩn để tạo và duy trì microservices trong nền tảng GoodGo. Sử dụng khi tạo services mới, migrate services, refactor services, hoặc lập kế hoạch implement services.
Tổng Quan
The microservices development process provides a structured 8-phase approach to building services, ensuring comprehensive coverage from planning to deployment.
Quy trình phát triển microservices cung cấp cách tiếp cận có cấu trúc 8 giai đoạn để xây dựng services, đảm bảo bao phủ toàn diện từ lập kế hoạch đến triển khai.
Khi Nào Sử Dụng
Use this skill when:
- Creating a new microservice from scratch
- Migrating or refactoring an existing service
- Planning service implementation with multiple phases
- Ensuring comprehensive coverage of all development aspects
Sử dụng skill này khi:
- Tạo microservice mới từ đầu
- Migrate hoặc refactor service hiện có
- Lập kế hoạch implement service với nhiều giai đoạn
- Đảm bảo bao phủ toàn diện tất cả các khía cạnh phát triển
Quy Trình 8 Giai Đoạn
The microservices development process follows these phases: Quy trình phát triển microservices theo các giai đoạn sau:
- Planning & Impact Analysis - Define scope, impact, dependencies / Định nghĩa scope, impact, dependencies
- Foundation Setup - Service structure, configs, infrastructure / Cấu trúc service, configs, infrastructure
- Core Implementation - Business logic, APIs, data layer / Business logic, APIs, data layer
- Integration - Routes, middleware, external services / Routes, middleware, external services
- Testing - Unit, integration, E2E tests / Unit, integration, E2E tests
- Documentation - API docs, README, guides / API docs, README, guides
- Cleanup & Verification - Remove temporary files, verify completeness / Xóa file tạm, xác minh hoàn chỉnh
- Deployment - Staging deployment, production deployment / Staging deployment, production deployment
Các Giai Đoạn Chính
Phase 1: Planning & Impact Analysis / Giai Đoạn 1: Lập Kế Hoạch & Phân Tích Tác Động
Scope Definition / Định Nghĩa Scope:
- Service Purpose: What business capability does it provide? / Mục đích service: Cung cấp khả năng kinh doanh gì?
- API Surface: What endpoints are needed? / API Surface: Cần endpoints nào?
- Data Models: What data structures are required? / Data Models: Cần cấu trúc dữ liệu nào?
- Dependencies: What services/packages does it depend on? / Dependencies: Phụ thuộc vào services/packages nào?
Impact Analysis Checklist / Checklist Phân Tích Tác Động:
- Service directory:
services/service-name/ - Prisma schema:
services/service-name/prisma/schema.prisma - Dockerfile:
services/service-name/Dockerfile - Update
deployments/local/docker-compose.yml - Update
infra/traefik/dynamic/routes.yml
Phase 2: Foundation Setup / Giai Đoạn 2: Thiết Lập Nền Tảng
Service Structure / Cấu Trúc Service:
# EN: Copy template
# VI: Copy template
cp -r services/_template services/new-service-name
cd services/new-service-name
Acceptance Criteria / Tiêu Chí Chấp Nhận:
- Service starts:
pnpm dev(health check passes) / Service khởi động:pnpm dev(health check pass) - Docker build succeeds / Docker build thành công
- Service accessible via Traefik / Service có thể truy cập qua Traefik
Phase 3: Core Implementation / Giai Đoạn 3: Implementation Cốt Lõi
Implementation Order / Thứ Tự Implementation:
- DTOs - Zod schemas for validation / Zod schemas cho validation
- Repository - Prisma-based data access / Data access dựa trên Prisma
- Service - Business logic / Business logic
- Controller - HTTP request handling / Xử lý HTTP requests
- Module - Wire up components / Kết nối các components
Phase 4: Integration / Giai Đoạn 4: Tích Hợp
Required Middlewares / Middlewares Bắt Buộc:
- Correlation middleware
- Logging middleware
- Metrics middleware
- CORS middleware
- Rate limiting middleware
- Authentication middleware (if needed) / (nếu cần)
- Error middleware (always last) / (luôn cuối cùng)
Phase 5: Testing / Giai Đoạn 5: Kiểm Thử
Test Coverage Targets / Mục Tiêu Test Coverage:
- Minimum: 70% coverage / Tối thiểu: 70% coverage
- Critical paths: 90%+ coverage / Đường dẫn quan trọng: 90%+ coverage
- Repositories: 80%+ coverage
- Services: 80%+ coverage
Testing Checklist / Checklist Testing:
- Unit tests pass / Unit tests pass
- Integration tests pass / Integration tests pass
- E2E tests pass / E2E tests pass
- Coverage meets thresholds / Coverage đạt ngưỡng
Phase 6: Documentation / Giai Đoạn 6: Tài Liệu
Required Documentation / Tài Liệu Bắt Buộc:
- Service README (bilingual EN/VI) / README service (song ngữ EN/VI)
- Swagger/OpenAPI spec / Swagger/OpenAPI spec
- Architecture docs (if complex) / Tài liệu kiến trúc (nếu phức tạp)
Phase 7: Cleanup & Verification / Giai Đoạn 7: Dọn Dẹp & Xác Minh
Verification Steps / Các Bước Xác Minh:
- TypeScript check:
pnpm typecheck/ Kiểm tra TypeScript - Lint check:
pnpm lint/ Kiểm tra lint - Test check:
pnpm test/ Kiểm tra test - Build check:
pnpm build/ Kiểm tra build - Docker build succeeds / Docker build thành công
Phase 8: Deployment / Giai Đoạn 8: Triển Khai
Staging Deployment / Triển Khai Staging:
# EN: Build and push Docker image
# VI: Build và push Docker image
docker build -t goodgo/service-name:latest .
docker push goodgo/service-name:latest
# EN: Apply Kubernetes configs
# VI: Áp dụng configs Kubernetes
kubectl apply -f deployments/staging/kubernetes/service-name.yaml
Best Practices / Thực Hành Tốt
- Always Plan First: Complete impact analysis before coding / Luôn lập kế hoạch trước: Hoàn thành phân tích tác động trước khi code
- Follow Phases: Don't skip verification steps / Tuân theo các giai đoạn: Không bỏ qua các bước xác minh
- Test Early: Write tests alongside implementation / Test sớm: Viết tests cùng với implementation
- Document as You Go: Don't leave documentation for the end / Tài liệu khi làm: Không để tài liệu đến cuối
- Verify Comprehensively: Use checklists to ensure nothing is missed / Xác minh toàn diện: Sử dụng checklists để đảm bảo không bỏ sót
Common Pitfalls to Avoid / Các Lỗi Thường Gặp Cần Tránh
- Skipping Impact Analysis: Leads to missing updates / Bỏ qua phân tích tác động: Dẫn đến thiếu cập nhật
- No Verification Steps: Misses broken references / Không có bước xác minh: Bỏ sót references bị hỏng
- Incomplete Testing: Missing edge cases / Testing không đầy đủ: Thiếu edge cases
- Poor Documentation: Makes maintenance difficult / Tài liệu kém: Làm khó bảo trì
Skills Liên Quan
- Project Rules - Architecture and conventions / Kiến trúc và conventions
- API Design - API design patterns / Các patterns thiết kế API
- Testing Patterns - Testing best practices / Best practices về testing
- Documentation - Documentation guidelines / Hướng dẫn tài liệu
- Database Prisma - Prisma patterns / Các patterns Prisma
Tài Nguyên
- Service Template:
services/_template/- Template service - Skill Source:
.cursor/skills/microservices-development-process/SKILL.md- Source file đầy đủ