Files
pos-system/services/_template/ARCHITECTURE.md
Ho Ngoc Hai 7d68f61b82 Update dependencies and enhance service template with bilingual support
- 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.
2025-12-27 11:01:17 +07:00

73 lines
2.3 KiB
Markdown

# 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
```mermaid
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
1. **Request Entry**: Use hits ingress/load balancer.
* *Đầu vào*: Người dùng gửi request đến ingress/load balancer.
2. **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*)
3. **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*)
4. **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*)
5. **Data Access**:
* Prisma ORM communicates with PostgreSQL. (*Prisma giao tiếp với PostgreSQL*)
6. **Response**:
* Formatted JSON response sent back. (*Trả về JSON đã định dạng*)
* Metrics/Logs finalized. (*Hoàn tất ghi metrics/log*)