diff --git a/.cursor/skills/api-design/SKILL.md b/.cursor/skills/api-design/SKILL.md index e127c6da..22230e1d 100644 --- a/.cursor/skills/api-design/SKILL.md +++ b/.cursor/skills/api-design/SKILL.md @@ -521,4 +521,13 @@ GET /v1/users/:id/orders # Sub-resource - `404` - Not Found - `409` - Conflict (duplicate) - `422` - Unprocessable (business rule) -- `429` - Rate limited \ No newline at end of file +- `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 \ No newline at end of file diff --git a/.cursor/skills/api-gateway-advanced/SKILL.md b/.cursor/skills/api-gateway-advanced/SKILL.md index 155eba98..06f052c7 100644 --- a/.cursor/skills/api-gateway-advanced/SKILL.md +++ b/.cursor/skills/api-gateway-advanced/SKILL.md @@ -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 { + async createOrderWithPayment(orderData: CreateOrderInput): Promise { // 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 { 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 }); }); diff --git a/.cursor/skills/comment-code/SKILL.md b/.cursor/skills/comment-code/SKILL.md index 9b6940d2..7b9c15a2 100644 --- a/.cursor/skills/comment-code/SKILL.md +++ b/.cursor/skills/comment-code/SKILL.md @@ -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 diff --git a/.cursor/skills/database-prisma/SKILL.md b/.cursor/skills/database-prisma/SKILL.md index 89e57033..b4ccf3e4 100644 --- a/.cursor/skills/database-prisma/SKILL.md +++ b/.cursor/skills/database-prisma/SKILL.md @@ -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 | \ No newline at end of file +| `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 \ No newline at end of file diff --git a/.cursor/skills/deployment-kubernetes/SKILL.md b/.cursor/skills/deployment-kubernetes/SKILL.md index 3643aa38..2c22858d 100644 --- a/.cursor/skills/deployment-kubernetes/SKILL.md +++ b/.cursor/skills/deployment-kubernetes/SKILL.md @@ -568,4 +568,13 @@ readinessProbe: initialDelaySeconds: 5 # Start checking early periodSeconds: 5 # Check frequently failureThreshold: 3 # Remove from LB after 3 failures -``` \ No newline at end of file +``` + +## 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 \ No newline at end of file diff --git a/.cursor/skills/documentation/SKILL.md b/.cursor/skills/documentation/SKILL.md index 409f439e..f219c76a 100644 --- a/.cursor/skills/documentation/SKILL.md +++ b/.cursor/skills/documentation/SKILL.md @@ -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 diff --git a/.cursor/skills/middleware-patterns/SKILL.md b/.cursor/skills/middleware-patterns/SKILL.md index 3ff2dd66..1b18a2a7 100644 --- a/.cursor/skills/middleware-patterns/SKILL.md +++ b/.cursor/skills/middleware-patterns/SKILL.md @@ -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 diff --git a/.cursor/skills/observability-monitoring/SKILL.md b/.cursor/skills/observability-monitoring/SKILL.md index 660591d0..8ddca66b 100644 --- a/.cursor/skills/observability-monitoring/SKILL.md +++ b/.cursor/skills/observability-monitoring/SKILL.md @@ -582,4 +582,13 @@ active_connections import { logger } from '@goodgo/logger'; import { Counter, Histogram, Gauge } from 'prom-client'; import { trace, SpanStatusCode } from '@opentelemetry/api'; -``` \ No newline at end of file +``` + +## 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 \ No newline at end of file diff --git a/.cursor/skills/resilience-patterns/SKILL.md b/.cursor/skills/resilience-patterns/SKILL.md index 00c59c2d..df87ccde 100644 --- a/.cursor/skills/resilience-patterns/SKILL.md +++ b/.cursor/skills/resilience-patterns/SKILL.md @@ -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 diff --git a/.cursor/skills/testing-patterns/SKILL.md b/.cursor/skills/testing-patterns/SKILL.md index 94342f17..7316954e 100644 --- a/.cursor/skills/testing-patterns/SKILL.md +++ b/.cursor/skills/testing-patterns/SKILL.md @@ -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'; -``` \ No newline at end of file +``` + +## 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 \ No newline at end of file