- 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.
2.3 KiB
2.3 KiB
Service Template Architecture / Kiến Trúc Template Dịch Vụ
This document describes the high-level architecture of the microservice template. Tài liệu này mô tả kiến trúc cấp cao của template microservice.
Component Diagram / Sơ đồ Thành phần
graph TD
Client[Client / External Service]
subgraph "Service Boundary / Phạm vi Dịch vụ"
LB[Load Balancer / Ingress]
subgraph "Application / Ứng dụng"
Middleware[Middleware Layer]
Router[Router Layer]
Controller[Controller Layer]
Service[Service Layer]
Repo[Repository / Data Access]
end
Config[Configuration Manager]
Logger[Logger]
Metrics[Prometheus Metrics]
end
DB[(PostgreSQL Database)]
Jaeger[Jaeger Tracing]
Client -->|HTTP Request| LB
LB -->|Traffic| Middleware
Middleware -->|Auth & Validation| Router
Middleware -.->|Track| Metrics
Middleware -.->|Log| Logger
Router -->|Dispatch| Controller
Controller -->|Business Logic| Service
Service -->|Data Query| Repo
Repo -->|SQL| DB
Config -->|Settings| Application
Application -.->|Traces| Jaeger
Request Flow / Luồng Xử Lý Request
-
Request Entry: Use hits ingress/load balancer.
- Đầu vào: Người dùng gửi request đến ingress/load balancer.
-
Middleware:
- Helmet: Secures HTTP headers. (Bảo mật header HTTP)
- Rate Limiter: Prevents abuse. (Ngăn chặn spam/abuses)
- Logger/Metrics: records start time. (Ghi nhận thời gian bắt đầu)
-
Router & Controller:
- Routes request to specific handler. (Định tuyến đến handler cụ thể)
- Controller orchestrates response. (Controller điều phối phản hồi)
-
Service Layer:
- Contains core business logic. (Chứa logic nghiệp vụ cốt lõi)
- Independent of transport layer (HTTP). (Độc lập với lớp giao thức)
-
Data Access:
- Prisma ORM communicates with PostgreSQL. (Prisma giao tiếp với PostgreSQL)
-
Response:
- Formatted JSON response sent back. (Trả về JSON đã định dạng)
- Metrics/Logs finalized. (Hoàn tất ghi metrics/log)