- Added `dotenv` and `prom-client` dependencies for environment variable management and metrics collection. - Updated `package.json` to include new dependencies and types for `dotenv`. - Enhanced `README.md` with bilingual features, usage instructions, and project structure. - Improved `app.config.ts` to validate environment variables using Zod. - Implemented graceful shutdown in `main.ts` for better service reliability. - Added metrics middleware and updated routes to include metrics endpoint. - Enhanced error handling middleware with detailed logging and responses. - Updated feature and health controllers with bilingual comments and improved structure.
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 / Giới hạn tốc độ request.
- Health checks (liveness/readiness) / Kiểm tra sức khỏe hệ thống.
- 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 (optional for local DB)
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" 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.