Chuyển tới nội dung chính

Container — Host Application

Port8080
Package@vppos/container
MFE RoleHost (consumer)

Mục đích

Container là host application — điểm vào duy nhất của hệ thống. Chịu trách nhiệm:

  • Load và render tất cả Remote MFEs
  • Quản lý layout (Sidebar, Header)
  • Authentication & Authorization
  • Routing chính

Chức năng chính

1. MFE Loading

  • MfeLoader — Suspense + ErrorBoundary wrapper cho mỗi MFE
  • MfeErrorBoundary — Bắt lỗi MFE crash, hiển thị fallback
  • MfeSkeleton — Loading skeleton khi MFE đang load

2. Authentication

  • AuthInitializer — Restore token từ localStorage khi app load
  • AuthGuard — Redirect về /auth/login nếu chưa đăng nhập

3. Store Selection

  • StoreInitializer — Auto-select store nếu chỉ có 1

4. Layout

  • MainLayout — Sidebar + Header + Content area
  • Sidebar auto-generated từ routes.config.ts

Cấu trúc

container/src/
├── components/
│ ├── layout/ # MainLayout, Sidebar, Header
│ ├── mfe/ # MfeLoader, MfeErrorBoundary, MfeSkeleton
│ ├── guards/ # AuthGuard, RouteGuard
│ ├── AuthInitializer.tsx
│ └── StoreInitializer.tsx
├── config/
│ ├── routes.config.ts # Source of truth cho routing
│ └── mfeRegistry.ts # MFE registry
├── routes/
│ └── index.tsx # AppRoutes component
├── services/ # API cho auth, store, etc.
├── store/ # Redux store (auth, storeSelection slices)
└── App.tsx

Luồng khởi tạo