- Integrated Redis for distributed rate limiting using `rate-limit-redis`. - Updated `README.md` to include Redis caching strategy and configuration details. - Enhanced architecture diagram to reflect Redis usage. - Added new dependencies for `ioredis`, `opossum`, and their respective type definitions. - Updated application configuration to include Redis URL. - Improved bilingual documentation throughout the service template.
Service Template / Template Dịch Vụ
EN: Standard template for creating new microservices in the @goodgo ecosystem. VI: Template chuẩn để tạo các microservice mới trong hệ sinh thái @goodgo.
Features / Tính Năng
- Framework: Express.js with TypeScript / Express.js với TypeScript.
- Database: Prisma ORM with PostgreSQL / Prisma ORM với PostgreSQL.
- Validation: Zod for environment & input validation / Zod cho validation biến môi trường và đầu vào.
- Observability / Khả năng quan sát:
- Metrics: Prometheus metrics at
/metrics/ Metrics Prometheus tại/metrics. - Logging: Common logger with request tracking / Logger chung với theo dõi request.
- Tracing: OpenTelemetry/Jaeger integration / Tích hợp OpenTelemetry/Jaeger.
- Metrics: Prometheus metrics at
- Resilience / Khả năng phục hồi:
- Graceful shutdown / Đóng ứng dụng an toàn.
- Rate limiting (Distributed via Redis) / Giới hạn tốc độ request (Phân tán qua Redis).
- Circuit Breaker / Ngắt mạch.
- Health checks (liveness/readiness) / Kiểm tra sức khỏe hệ thống.
- Caching: Redis caching strategy / Chiến lược caching với Redis.
- Security / Bảo mật: Helmet & CORS configured / Đã cấu hình Helmet & CORS.
Project Structure / Cấu trúc Dự án
src/
├── config/ # Configuration & Env validation / Cấu hình & Validate biến môi trường
├── middlewares/ # Express middlewares (error, logger, metrics)
├── modules/ # Feature modules (controller, service, repository)
├── routes/ # API route definitions
└── main.ts # Entry point & App bootstrapping
Getting Started / Bắt đầu
Prerequisites / Yêu cầu tiên quyết
- Node.js >= 20
- pnpm
- Docker (Redis required)
Installation / Cài đặt
-
Clone & Install dependencies:
pnpm install -
Environment Setup / Thiết lập môi trường: Copy
.env.exampleto.env(create if missing):PORT=5000 NODE_ENV=development DATABASE_URL="postgresql://user:password@localhost:5432/dbname" REDIS_URL="redis://localhost:6379" TRACING_ENABLED=false -
Run Development / Chạy môi trường phát triển:
pnpm dev -
Build & Start Production:
pnpm build pnpm start
Observability / Khả năng quan sát
- Metrics: Visit
http://localhost:5000/metrics. - Health:
- Liveness:
http://localhost:5000/health/live - Readiness:
http://localhost:5000/health/ready
- Liveness:
Development Guidelines / Hướng dẫn Phát triển
Comments / Comment Code
- Use bilingual comments for all public APIs and complex logic.
- Format:
ENfirst, thenVI. - See
.cursor/skills/comment-code/SKILL.mdfor details.
Adding a Module / Thêm Module
- Create
src/modules/<name>/. - Implement
Controller,Service. - Register routes in
src/routes/index.ts.