Files
pos-system/docs/vi/architecture/system-design.md
Ho Ngoc Hai 4da46b5b8e Sure! Pl
2025-12-27 01:31:10 +07:00

3.4 KiB

Thiết Kế Hệ Thống

Tổng Quan

GoodGo Microservices Platform được xây dựng sử dụng kiến trúc microservices với các nguyên tắc sau:

  • Độc Lập Service: Mỗi service có database riêng và có thể deploy độc lập
  • API Gateway: Traefik xử lý routing, load balancing, và các concerns xuyên suốt
  • Shared Libraries: Chức năng chung được trích xuất vào shared packages
  • Infrastructure as Code: Tất cả cấu hình infrastructure đều được version
  • Observability: Đầy đủ khả năng monitoring, logging, và tracing

Sơ Đồ Kiến Trúc

┌─────────────┐     ┌─────────────┐
│   Web App   │     │ Mobile App  │
│  (Next.js)  │     │ (React Native)
└──────┬──────┘     └──────┬──────┘
       │                   │
       └──────────┬────────┘
                  │
         ┌────────▼────────┐
         │   Traefik       │
         │  (API Gateway)   │
         └────────┬─────────┘
                  │
    ┌─────────────┼─────────────┐
    │             │             │
┌───▼────┐   ┌───▼────┐   ┌───▼────┐
│ Auth  │   │ Future │   │ Future │
│Service │   │Service │   │Service │
└───┬────┘   └───┬────┘   └───┬────┘
    │            │            │
    └────────────┼────────────┘
                 │
    ┌────────────┼────────────┐
    │            │            │
┌───▼────┐  ┌───▼────┐  ┌───▼────┐
│Postgres│  │ Redis  │  │Prometheus│
└────────┘  └────────┘  └─────────┘

Các Thành Phần

Frontend Layer

  • Web App: Ứng dụng Next.js với App Router
  • Mobile App: Ứng dụng React Native

API Gateway

  • Traefik: Reverse proxy, load balancer, SSL termination

Services Layer

  • Auth Service: Xác thực và phân quyền
  • Future Services: Payment, Order, Notification, v.v.

Infrastructure Layer

  • PostgreSQL: Database chính
  • Redis: Caching và session storage
  • Prometheus: Thu thập metrics
  • Grafana: Hiển thị metrics
  • Loki: Tập hợp logs

Các Mẫu Giao Tiếp

  • Đồng Bộ: HTTP/REST cho các mẫu request-response
  • Bất Đồng Bộ: Message queues (triển khai trong tương lai)
  • Service Discovery: Docker networking và Kubernetes DNS

Quản Lý Dữ Liệu

  • Database per Service: Mỗi service sở hữu dữ liệu của mình
  • API Composition: Services expose APIs để truy cập dữ liệu
  • Event Sourcing: Xem xét trong tương lai cho audit trails

Bảo Mật

  • Authentication: JWT tokens với refresh token rotation
  • Authorization: Role-based access control (RBAC)
  • Network Security: TLS/SSL, rate limiting, CORS
  • Secrets Management: Environment variables, Kubernetes secrets