Add Resources sections and cross-references, fix TypeScript types in skills
- Add Resources sections to all 26 skills (7 were missing) - Add cross-references between related skills (resilience-patterns, middleware-patterns) - Replace `any` with proper types/`unknown` in api-gateway-advanced, middleware-patterns - Add Common Mistakes section to comment-code skill - Add type definitions for API composition (CreateOrderInput, OrderWithPaymentResult) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -521,4 +521,13 @@ GET /v1/users/:id/orders # Sub-resource
|
||||
- `404` - Not Found
|
||||
- `409` - Conflict (duplicate)
|
||||
- `422` - Unprocessable (business rule)
|
||||
- `429` - Rate limited
|
||||
- `429` - Rate limited
|
||||
|
||||
## Resources
|
||||
|
||||
- [OpenAPI Specification](https://spec.openapis.org/oas/latest.html) - Official OpenAPI docs
|
||||
- [REST API Design](https://restfulapi.net/) - REST best practices
|
||||
- [API Versioning Strategy](../api-versioning-strategy/SKILL.md) - Versioning patterns
|
||||
- [API Gateway Advanced](../api-gateway-advanced/SKILL.md) - Gateway patterns
|
||||
- [Middleware Patterns](../middleware-patterns/SKILL.md) - Request handling
|
||||
- [Project Rules](../project-rules/SKILL.md) - GoodGo standards
|
||||
@@ -47,6 +47,22 @@ Use this skill when:
|
||||
import { ServiceClient } from '../../core/clients/service-client';
|
||||
import { logger } from '@goodgo/logger';
|
||||
|
||||
// EN: Type definitions for API composition
|
||||
// VI: Định nghĩa types cho API composition
|
||||
interface CreateOrderInput {
|
||||
userId: string;
|
||||
items: Array<{ productId: string; quantity: number }>;
|
||||
paymentMethod: string;
|
||||
}
|
||||
|
||||
interface OrderWithPaymentResult {
|
||||
success: boolean;
|
||||
data: {
|
||||
order: { id: string; total: number };
|
||||
payment: { id: string; status: string };
|
||||
};
|
||||
}
|
||||
|
||||
export class ApiCompositionService {
|
||||
private userClient: ServiceClient;
|
||||
private orderClient: ServiceClient;
|
||||
@@ -107,7 +123,7 @@ export class ApiCompositionService {
|
||||
* EN: Chain services: Create order then process payment
|
||||
* VI: Chain services: Tạo order rồi xử lý payment
|
||||
*/
|
||||
async createOrderWithPayment(orderData: any): Promise<any> {
|
||||
async createOrderWithPayment(orderData: CreateOrderInput): Promise<OrderWithPaymentResult> {
|
||||
// EN: Step 1: Create order
|
||||
// VI: Bước 1: Tạo order
|
||||
const order = await this.orderClient.post('/api/v1/orders', orderData);
|
||||
@@ -147,10 +163,10 @@ export class ApiCompositionService {
|
||||
import { Request, Response, NextFunction } from 'express';
|
||||
import { logger } from '@goodgo/logger';
|
||||
|
||||
export interface TransformRule {
|
||||
export interface TransformRule<T = unknown, R = unknown> {
|
||||
path: string;
|
||||
requestTransform?: (req: Request) => Request;
|
||||
responseTransform?: (res: Response, data: any) => any;
|
||||
responseTransform?: (res: Response, data: T) => R;
|
||||
}
|
||||
|
||||
export class GatewayTransformMiddleware {
|
||||
@@ -178,11 +194,12 @@ export class GatewayTransformMiddleware {
|
||||
|
||||
// EN: Override json to transform response
|
||||
// VI: Override json để transform response
|
||||
res.json = (data: any) => {
|
||||
res.json = (data: unknown) => {
|
||||
let transformedData = data;
|
||||
if (rule?.responseTransform) {
|
||||
data = rule.responseTransform(res, data);
|
||||
transformedData = rule.responseTransform(res, data);
|
||||
}
|
||||
return originalJson(data);
|
||||
return originalJson(transformedData);
|
||||
};
|
||||
|
||||
next();
|
||||
@@ -394,7 +411,7 @@ export function gatewayCache(ttl: number = 60) {
|
||||
|
||||
// EN: Override to cache response
|
||||
// VI: Override để cache response
|
||||
res.json = (data: any) => {
|
||||
res.json = (data: unknown) => {
|
||||
cacheService.set(cacheKey, data, ttl).catch((error) => {
|
||||
logger.warn('Gateway cache set failed', { error });
|
||||
});
|
||||
|
||||
@@ -342,6 +342,61 @@ When commenting code in this project:
|
||||
- Document according to the testing standards
|
||||
- Include security considerations where relevant
|
||||
|
||||
## Common Mistakes
|
||||
|
||||
1. **Stating the Obvious**: Comments that repeat what code says
|
||||
```typescript
|
||||
// ❌ BAD: States the obvious
|
||||
// EN: Set x to 5
|
||||
// VI: Gán x bằng 5
|
||||
const x = 5;
|
||||
|
||||
// ✅ GOOD: Explains why
|
||||
// EN: Default timeout in seconds for API calls
|
||||
// VI: Timeout mặc định (giây) cho các API call
|
||||
const x = 5;
|
||||
```
|
||||
|
||||
2. **Missing Translation**: Incomplete bilingual comments
|
||||
```typescript
|
||||
// ❌ BAD: Missing Vietnamese
|
||||
// EN: Calculate discount
|
||||
const discount = price * 0.1;
|
||||
|
||||
// ✅ GOOD: Both languages
|
||||
// EN: Calculate 10% discount for members
|
||||
// VI: Tính giảm giá 10% cho thành viên
|
||||
const discount = price * 0.1;
|
||||
```
|
||||
|
||||
3. **Outdated Comments**: Comments not matching code
|
||||
```typescript
|
||||
// ❌ BAD: Comment says email, code uses phone
|
||||
// EN: Validate email format
|
||||
// VI: Xác thực định dạng email
|
||||
validatePhone(phone);
|
||||
|
||||
// ✅ GOOD: Keep comments in sync with code
|
||||
// EN: Validate phone number format
|
||||
// VI: Xác thực định dạng số điện thoại
|
||||
validatePhone(phone);
|
||||
```
|
||||
|
||||
4. **No JSDoc for Public APIs**: Missing documentation for exports
|
||||
```typescript
|
||||
// ❌ BAD: Exported function without JSDoc
|
||||
export function processOrder(order: Order) { ... }
|
||||
|
||||
// ✅ GOOD: Full JSDoc for exported functions
|
||||
/**
|
||||
* EN: Process order and update inventory
|
||||
* VI: Xử lý đơn hàng và cập nhật kho
|
||||
* @param order - Order to process / Đơn hàng cần xử lý
|
||||
* @returns ProcessingResult / Kết quả xử lý
|
||||
*/
|
||||
export function processOrder(order: Order): ProcessingResult { ... }
|
||||
```
|
||||
|
||||
## Quick Reference
|
||||
|
||||
### Function Comment Template
|
||||
@@ -367,3 +422,10 @@ When commenting code in this project:
|
||||
// EN: Step N: [What this block does]
|
||||
// VI: Bước N: [Block này làm gì]
|
||||
```
|
||||
|
||||
## Resources
|
||||
|
||||
- [Project Rules](../project-rules/SKILL.md) - Code organization standards
|
||||
- [Documentation](../documentation/SKILL.md) - Documentation patterns
|
||||
- [API Design](../api-design/SKILL.md) - API documentation standards
|
||||
- [Testing Patterns](../testing-patterns/SKILL.md) - Test documentation
|
||||
|
||||
@@ -579,4 +579,13 @@ await prisma.$transaction(async (tx) => { /* operations */ });
|
||||
| `Float` | DOUBLE PRECISION | Floating point |
|
||||
| `Boolean` | BOOLEAN | True/false |
|
||||
| `DateTime` | TIMESTAMP | Date and time |
|
||||
| `Json` | JSONB | JSON data |
|
||||
| `Json` | JSONB | JSON data |
|
||||
|
||||
## Resources
|
||||
|
||||
- [Prisma Documentation](https://www.prisma.io/docs) - Official Prisma docs
|
||||
- [Prisma Schema Reference](https://www.prisma.io/docs/reference/api-reference/prisma-schema-reference) - Schema syntax
|
||||
- [Repository Pattern](../repository-pattern/SKILL.md) - Data access patterns
|
||||
- [Caching Patterns](../caching-patterns/SKILL.md) - Query caching
|
||||
- [Testing Patterns](../testing-patterns/SKILL.md) - Database mocking
|
||||
- [Project Rules](../project-rules/SKILL.md) - GoodGo standards
|
||||
@@ -568,4 +568,13 @@ readinessProbe:
|
||||
initialDelaySeconds: 5 # Start checking early
|
||||
periodSeconds: 5 # Check frequently
|
||||
failureThreshold: 3 # Remove from LB after 3 failures
|
||||
```
|
||||
```
|
||||
|
||||
## Resources
|
||||
|
||||
- [Kubernetes Documentation](https://kubernetes.io/docs/) - Official K8s docs
|
||||
- [Helm](https://helm.sh/docs/) - K8s package manager
|
||||
- [Infrastructure as Code](../infrastructure-as-code/SKILL.md) - Terraform patterns
|
||||
- [Observability & Monitoring](../observability-monitoring/SKILL.md) - Health checks
|
||||
- [Service Discovery](../service-discovery-registry/SKILL.md) - K8s DNS patterns
|
||||
- [Project Rules](../project-rules/SKILL.md) - GoodGo standards
|
||||
@@ -436,3 +436,10 @@ PORT=5000 # Server port / Cổng server
|
||||
# VI: Cài đặt dependencies
|
||||
pnpm install
|
||||
```
|
||||
|
||||
## Resources
|
||||
|
||||
- [Project Rules](../project-rules/SKILL.md) - Project structure and standards
|
||||
- [Comment Code](../comment-code/SKILL.md) - Code commenting standards
|
||||
- [API Design](../api-design/SKILL.md) - API documentation
|
||||
- [Testing Patterns](../testing-patterns/SKILL.md) - Test documentation
|
||||
|
||||
@@ -194,8 +194,8 @@ Transform request or response data:
|
||||
export const transformResponse = () => {
|
||||
return (req: Request, res: Response, next: NextFunction) => {
|
||||
const originalJson = res.json.bind(res);
|
||||
|
||||
res.json = function(data: any) {
|
||||
|
||||
res.json = function(data: unknown) {
|
||||
const transformed = {
|
||||
success: true,
|
||||
data,
|
||||
@@ -203,7 +203,7 @@ export const transformResponse = () => {
|
||||
};
|
||||
return originalJson(transformed);
|
||||
};
|
||||
|
||||
|
||||
next();
|
||||
};
|
||||
};
|
||||
@@ -307,7 +307,10 @@ import { logger } from '@goodgo/logger';
|
||||
|
||||
## Resources
|
||||
|
||||
- [Correlation Middleware](../../services/iam-service/src/middlewares/correlation.middleware.ts)
|
||||
- [Auth Middleware](../../services/iam-service/src/middlewares/auth.middleware.ts)
|
||||
- [Validation Middleware](../../services/iam-service/src/middlewares/validation.middleware.ts)
|
||||
- [Express Middleware](https://expressjs.com/en/guide/writing-middleware.html) - Express middleware guide
|
||||
- [Error Handling](../error-handling-patterns/SKILL.md) - Error middleware patterns
|
||||
- [Security](../security/SKILL.md) - Auth middleware patterns
|
||||
- [API Design](../api-design/SKILL.md) - Request/response patterns
|
||||
- [Resilience Patterns](../resilience-patterns/SKILL.md) - Circuit breaker middleware
|
||||
- [Observability & Monitoring](../observability-monitoring/SKILL.md) - Logging middleware
|
||||
- [Project Rules](../project-rules/SKILL.md) - GoodGo standards
|
||||
|
||||
@@ -582,4 +582,13 @@ active_connections
|
||||
import { logger } from '@goodgo/logger';
|
||||
import { Counter, Histogram, Gauge } from 'prom-client';
|
||||
import { trace, SpanStatusCode } from '@opentelemetry/api';
|
||||
```
|
||||
```
|
||||
|
||||
## Resources
|
||||
|
||||
- [OpenTelemetry](https://opentelemetry.io/docs/) - Distributed tracing standard
|
||||
- [Prometheus](https://prometheus.io/docs/) - Metrics and alerting
|
||||
- [Grafana](https://grafana.com/docs/) - Visualization
|
||||
- [Deployment Kubernetes](../deployment-kubernetes/SKILL.md) - K8s health probes
|
||||
- [Resilience Patterns](../resilience-patterns/SKILL.md) - Circuit breaker metrics
|
||||
- [Project Rules](../project-rules/SKILL.md) - GoodGo standards
|
||||
@@ -414,6 +414,10 @@ import { logger } from '@goodgo/logger';
|
||||
|
||||
## Resources
|
||||
|
||||
- [Circuit Breaker](../../services/iam-service/src/modules/common/circuit-breaker.ts) - Circuit breaker implementation
|
||||
- [Opossum Documentation](https://nodeshift.dev/opossum/)
|
||||
- [Opossum Documentation](https://nodeshift.dev/opossum/) - Circuit breaker library
|
||||
- [Microsoft Resilience Patterns](https://docs.microsoft.com/en-us/azure/architecture/patterns/category/resiliency)
|
||||
- [API Gateway Advanced](../api-gateway-advanced/SKILL.md) - Gateway circuit breaker
|
||||
- [Observability & Monitoring](../observability-monitoring/SKILL.md) - Health checks, metrics
|
||||
- [Event-Driven Architecture](../event-driven-architecture/SKILL.md) - Event retry patterns
|
||||
- [Error Handling Patterns](../error-handling-patterns/SKILL.md) - Error handling
|
||||
- [Project Rules](../project-rules/SKILL.md) - GoodGo standards
|
||||
|
||||
@@ -519,4 +519,13 @@ pnpm test -- UserService # Run specific test file
|
||||
import { mockDeep } from 'jest-mock-extended';
|
||||
import { prismaMock } from '../__mocks__/prisma';
|
||||
import supertest from 'supertest';
|
||||
```
|
||||
```
|
||||
|
||||
## Resources
|
||||
|
||||
- [Jest Documentation](https://jestjs.io/docs/getting-started) - Testing framework
|
||||
- [Supertest](https://github.com/ladjs/supertest) - HTTP assertions
|
||||
- [jest-mock-extended](https://github.com/marchaos/jest-mock-extended) - TypeScript mocks
|
||||
- [Database Prisma](../database-prisma/SKILL.md) - Database mocking patterns
|
||||
- [Error Handling](../error-handling-patterns/SKILL.md) - Error testing
|
||||
- [Project Rules](../project-rules/SKILL.md) - GoodGo standards
|
||||
Reference in New Issue
Block a user