Skip to content

Kiến trúc Hệ thống 7 Plugin & Hợp đồng Host ​

Toàn bộ phần mở rộng nghiệp vụ và kỹ thuật của LatticeDX v0.4.2 được đóng gói thành 7 plugin NocoBase độc lập dưới thư mục plugins/nocobase/*. Thiết kế này giữ kho mã nguồn Apache-2.0 tách rời hoàn toàn khỏi mã nguồn host NocoBase: runtime nocobase/nocobase:2.2.50 chạy dưới dạng container OCI ngoài và nạp cả 7 gói qua cơ chế sdkProvidedByHost: true.

Kiến trúc 7 Plugin Apache-2.0 & Host NocoBase 2.2.50
GIAI ĐOẠN BIÊN DỊCH · ESBUILD 0.28.2 & NOCOBASE-EXTERNALS.MJSGIAI ĐOẠN RUNTIME · CONTAINER OCI NGOÀI (:RO MOUNT)StripBundleMount :roMã nguồn 7@latticedx/*Apache-2.0 · v0.4.2sdkProvidedByHost: trueHost Externals (Loạitrừ)7 @nocobase/* packagesReact 18.2 · AntD 5.24Thư viện Pure-OSIopenid-client@6.8.9maplibre · @xyflow/reactĐầu ra dist/*server · client ·client-v2externalVersion.jsNocoBase 2.2.50 Hostnode_modules/@latticedx/*Resolves Host SDKPG16 & Valkey 8.1nocobase_app · 56+ RLSValkey DB 0 / 1 / 2
Chi tiết khốiHost Externals (Loại trừ)Nhấn vào từng khối để xem giao diện & trách nhiệm
Vai trò
Loại trừ SDK NocoBase và Vendor UI Khỏi Bundle
Gói / Cổng
scripts/lib/nocobase-externals.mjs
Giao thức
react@18.2.0 · antd@5.24.2 · 7 @nocobase/*
Payload / Schema
Stripped at build time (externalized)
Trách nhiệm
Loại trừ 7 gói @nocobase/* và React/AntD khỏi bản build để runtime container host cung cấp trực tiếp, không sao chép vào dist/*.
Toàn bộ 7 plugin @latticedx/* biên dịch với sdkProvidedByHost: true (loại trừ @nocobase/*, React 18.2, AntD 5.24 và đóng gói thư viện Pure-OSI), gắn chỉ đọc (:ro) vào container ngoài nocobase/nocobase:2.2.50 và giữ nguyên ghi công Powered by NocoBase theo Điều 5.2.

Danh mục 7 Plugin @latticedx/* (0.4.2) ​

Tất cả 7 package đều khai báo "version": "0.4.2", "private": true, "license": "Apache-2.0", "supportedVersions": ["2.2.x"], "testedRuntime": "2.2.50" và "sdkProvidedByHost": true, kèm tệp LICENSE và README.md riêng.

#Thư mục nguồn (plugins/nocobase/)Package (package.json)Entrypoint Server & ClientCơ chế Build & Phụ thuộc ngoài
1action-bridge/@latticedx/plugin-action-bridgeserver.cjs, client.js, client-v2.jsbuild.mjs sao chép src/ sang dist/ và sinh dist/externalVersion.js cho @nocobase/server, @nocobase/client, @nocobase/client-v2
2plugin-lattice-foundation/@latticedx/plugin-lattice-foundationdist/server/index.js (LatticeFoundationPlugin), client.js, client-v2.jsscripts/build.mjs kiểm tra cú pháp bằng node --check, đóng gói module nội bộ cho client/client-v2, khai báo external cho SDK NocoBase, react, antd
3plugin-enterprise-auth/@latticedx/plugin-enterprise-authdist/server/index.js (EnterpriseLoginPlugin), client.js, client-v2.jsĐóng gói sẵn openid-client@6.8.9 (bundleDependencies); đặt external @nocobase/server, @nocobase/auth, @nocobase/plugin-auth, @nocobase/client, @nocobase/client-v2, react, antd
4plugin-dxos-para/@latticedx/plugin-dxos-paradist/server/index.js (DxosParaPlugin), client.js, client-v2.jsbuild.mjs sao chép src/ sang dist/; trích xuất PDF/Office và tìm kiếm kết hợp pgvector HNSW + tsvector RRF trực tiếp qua @nocobase/database
5plugin-dxos-blocks/@latticedx/plugin-dxos-blocksdist/server/index.js (DxosBlocksServerPlugin), client.js, client-v2.jsDùng esbuild@0.28.2 đóng gói maplibre-gl@6.19.0 (kèm CSS và Web Worker) thành bundle UMD; đăng ký 12 BlockModels và tài nguyên dxosBlocks, dxosBroker
6plugin-dxos-studio/@latticedx/plugin-dxos-studiodist/server/index.js (DxosStudioPlugin), client.js, client-v2.jsDùng esbuild@0.28.2 đóng gói @xyflow/react@12.12.1 và @dagrejs/dagre@3.1.3 thành bundle UMD cho LatticeFlow v2, Visual DMN, WMS, Rich Schema và cầu nối n8n
7plugin-dxos-ai/@latticedx/plugin-dxos-aidist/server/index.js (DxosAiPlugin), client.js, client-v2.jsbuild.mjs đóng gói module client nội bộ; đăng ký 7 AI Profiles, 20 Unified Tools, cổng Streamable HTTP MCP, A2A Gateway và bộ lập lịch proactive triage

Phân bổ 31 Tài nguyên resourceManager & Gateway Routes ​

Toàn bộ API nội bộ của nền tảng được đăng ký qua this.app.resourceManager.define(...) hoặc Gateway.registerRequestHandler(...) theo đúng ranh giới từng plugin:

Plugin sở hữuTài nguyên resourceManager.defineTuyến Gateway / Middleware đặc biệt
plugin-action-bridgedxActions (13 actions)Proxy PKCE phía máy chủ cho /lattice/* (trả 503 an toàn nếu thiếu DX_BRIDGE_*)
plugin-lattice-foundationdxos, dxosApiKeys, dxosLedger, dxosDataGov, dxosVault, dxosEvents, dxosApprovals, dxosNotify, dxosForms, latticeNative, latticeApps, latticePortals, latticeChatter, latticeVoucher, latticeNotifications, latticeSla, latticeContextSync, latticeIntegrationsGateway.registerRequestHandler: /v/form/*, /v/track/*, /v/lattice-brand.svg, /v/mobile
plugin-enterprise-authenterpriseAuth (9 actions)Authenticator lattice-keycloak + middleware enterpriseAuthRevocationGuard
plugin-dxos-paralatticePara (6 actions)Middleware phạm vi P.A.R.A. + tác vụ runAfterCommit đồng bộ vector chunk
plugin-dxos-blocksdxosBlocks (17 actions), dxosBroker (10 actions)dxosTelemetryDirectGuard chặn CRUD trực tiếp vào latticeTelemetryPoints, latticeTwinShadows, latticeIotDevices
plugin-dxos-studiodxosStudio, dxosWms, dxosDmn, dxosDelegations, dxosAutomations, dxosBuilder, dxosN8n4 guard middleware (dxosServiceScope, dxosWmsDmnScope, dxosAutomationScope, dxosOrganizationScope)
plugin-dxos-aidxosAi (Trợ lý AI, App Builder 2.0, Eval Lab, surfaceEvents)POST /api/dxos-mcp, POST /api/dxos-mcp/it-ot, GET /.well-known/agent-card.json, POST /api/dxos-a2a

Hợp đồng sdkProvidedByHost: true & nocobase-externals.mjs ​

Thay vì cài đặt @nocobase/* vào node_modules trong kho mã nguồn, mỗi plugin khai báo các gói lõi của NocoBase và thư viện UI dùng chung là external. Khi container nocobase/nocobase:2.2.50 khởi động, host tự cung cấp các gói này từ runtime của chính nó theo đúng phiên bản đang chạy.

Cấu hình External & Phiên bản Host (scripts/lib/nocobase-externals.mjs)
Tham sốKiểuMặc địnhMô tả
DEFAULT_NOCOBASE_VERSIONbắt buộc
string2.2.50Phiên bản host mặc định dùng khi sinh dist/externalVersion.js nếu không đặt biến NOCOBASE_VERSION.
NOCOBASE_VERSION
env (SemVer)2.2.50Biến môi trường ghi đè phiên bản đích, được kiểm tra nghiêm ngặt bằng biểu thức SEMVER_RE trước khi phát sinh mã.
NOCOBASE_EXTERNAL_NAMESbắt buộc
string[7]2.2.50@nocobase/server, @nocobase/auth, @nocobase/plugin-auth, @nocobase/database, @nocobase/client, @nocobase/client-v2, @nocobase/plugin-workflow.
SHARED_VENDOR_VERSIONSbắt buộc
object18.2.0 / 5.24.2Các thư viện frontend chia sẻ từ host: react (18.2.0), react-dom (18.2.0) và antd (5.24.2).

Hàm externalVersionSource(names, options) trong scripts/lib/nocobase-externals.mjs kiểm tra từng tên gói nằm trong danh sách cho phép (Object.hasOwn(versions, name)), từ chối bất kỳ phụ thuộc chưa xác minh nào, rồi ghi tệp dist/externalVersion.js mang header SPDX-License-Identifier: Apache-2.0.

json
{
  "name": "@latticedx/plugin-lattice-foundation",
  "version": "0.4.2",
  "private": true,
  "license": "Apache-2.0",
  "main": "dist/server/index.js",
  "nocobase": {
    "supportedVersions": ["2.2.x"],
    "testedRuntime": "2.2.50",
    "sdkProvidedByHost": true
  }
}

Vòng đời Plugin (Plugin Lifecycle Hooks) & Thứ tự Middleware ​

Mỗi plugin kế thừa lớp Plugin từ @nocobase/server và triển khai các hook vòng đời theo từng giai đoạn khởi chạy, kích hoạt và thu dọn tài nguyên của ứng dụng.

Hook vòng đờiThời điểm kích hoạtHành vi chuẩn hóa trong các plugin @latticedx/*
load()Khi NocoBase nạp plugin vào Koa/ResourceManagerĐăng ký collection mở rộng, gắn this.db.attachLatticeRlsPolicy, định nghĩa resourceManager.define, khai báo acl.allow / acl.registerSnippet, gắn middleware theo thứ tự ưu tiên, đăng ký Gateway.registerRequestHandler, lắng nghe sự kiện DB (db.on) và đặt lịch nền (_delayTicker, _triageScheduler).
install()Lần đầu cài đặt plugin vào DBKhởi tạo dữ liệu nền idempotent dưới withSystemRlsBypass (ví dụ seedFoundation, ensureDefaultAiWorkforce, runStartupRepairs).
afterEnable()Sau khi quản trị viên bật lại pluginĐồng bộ lại quyền vai trò (ensureIncidentManagerGrants), hồ sơ AI mặc định (forceUpdate: false) và căn chỉnh route/SLA mà không ghi đè cấu hình người dùng.
start()Khi tiến trình ứng dụng khởi động hoàn tấtChạy lại các tác vụ idempotent như ensureIncidentManagerGrants và runStartupRepairs (kết hợp thêm hook this.app.once('afterStart', ...)).
unload() / remove() / destroy()Khi reload, tắt hoặc gỡ bỏ pluginDừng eventBusDrainer, stopAutomationListener() (clearInterval), đóng _otelExporter.shutdown(), dừng _triageScheduler và hủy đăng ký toàn bộ handler qua Gateway.unregisterRequestHandler.

Thứ tự Gắn Middleware & DB Event Hooks ​

Thứ tự middleware được neo tường minh bằng thuộc tính before và after để lớp xác thực, guard chống CRUD trực tiếp và lớp cô lập RLS không bao giờ chạy sai trình tự:

Thứ tự / Mốc gắnThành phần đăng ký và hành vi thực thi
Trước auth (before: 'auth')latticePaasApiKeyAuth giải mã khóa ldx_pat_* từ X-Lattice-API-Key hoặc Authorization: Bearer và ánh xạ vào ctx.state.currentUser trước khi middleware phiên chuẩn kiểm tra.
Sau auth (after: 'auth')enterpriseAuthRevocationGuard đối chiếu danh sách thu hồi phiên revoked: / revoked_sid: trên Valkey DB 2.
Sau acl, trước latticeNativeScope (after: 'acl', before: 'latticeNativeScope')Các middleware bảo vệ miền chuyên biệt (dxosTelemetryDirectGuard, dxosServiceScope, dxosWmsDmnScope, dxosAutomationScope, dxosOrganizationScope, dxosAiProfileScope, dxosAiHitlScope, dxosAiMemoryAndA2aScope) chặn mọi yêu cầu CRUD trực tiếp vào các bảng nhạy cảm trước khi latticeNativeScope mở transaction RLS.
Sau dataWrapping, trước dataSource (before: 'dataSource', after: 'dataWrapping')dxosMcpGateway, dxosA2aAgentCard và dxosA2aGateway xử lý trực tiếp JSON-RPC Streamable HTTP MCP và Agent Card của giao thức A2A.
Sự kiện DB (this.db.on)latticeServiceTickets.beforeValidate, WMS_DMN_COLLECTIONS .beforeValidate, latticeAiProfiles.beforeValidate (chống leo thang quyền builder AI và chặn SSRF mcpServers), roles.afterCreate (thu hồi tự động gán vai trò mới cho Builder AI) và llmServices.afterSave (cập nhật dịch vụ LLM mặc định).

Bảng Guard Middleware & DB Event Hooks ​

Thành phần / HookPlugin đăng kýVị trí & Hành vi bảo vệ
latticePaasApiKeyAuthplugin-lattice-foundationbefore: 'auth' — xác thực ldx_pat_* bằng SHA-256 và giới hạn role không vượt quá khóa
enterpriseAuthRevocationGuardplugin-enterprise-authafter: 'auth' — chặn token/session có trong danh sách thu hồi trên Valkey DB 2
dxosTelemetryDirectGuardplugin-dxos-blocksafter: 'acl', before: 'latticeNativeScope' — chặn CRUD trực tiếp vào telemetry, twin shadow và thiết bị IoT
dxosServiceScope / dxosWmsDmnScopeplugin-dxos-studioafter: 'acl', before: 'latticeNativeScope' — buộc truy cập qua dxosWms, dxosDmn và kiểm tra phạm vi ticket
dxosAutomationScope / dxosOrganizationScopeplugin-dxos-studioafter: 'acl', before: 'latticeNativeScope' — khóa ghi trực tiếp rule tự động hóa và giới hạn latticeOrganizations cho root
dxosAiProfileScope / dxosAiHitlScopeplugin-dxos-aiafter: 'acl', before: 'latticeNativeScope' — khóa hồ sơ AI cho admin và chặn sửa trực tiếp hàng đợi HITL
dxosAiMemoryAndA2aScopeplugin-dxos-aiafter: 'acl', before: 'latticeNativeScope' — buộc thao tác bộ nhớ AI, tác vụ A2A và trace qua endpoint chuyên biệt
latticeAiProfiles.beforeValidate & roles.afterCreateplugin-dxos-aiChặn leo thang quyền isAdminBuilder, kiểm tra URL mcpServers chống SSRF và gỡ quyền builder khỏi role mới
Gateway.registerRequestHandler (5 handler)foundation & dxos-aiPhục vụ /v/form/*, /v/track/*, /v/lattice-brand.svg, /v/mobile và /.well-known/agent-card.json và tự hủy đăng ký trong unload()/destroy()
javascript
const { Plugin, Gateway } = require("@nocobase/server");

class CustomLatticePlugin extends Plugin {
  async load() {
    this.app.resourceManager.use(this.guardMiddleware(), {
      tag: "customDomainGuard",
      after: "acl",
      before: "latticeNativeScope",
    });
    this.app.resourceManager.define({ name: "customDomain", actions: this.buildActions() });
    this.app.once("afterStart", () => this.ensureSeeded().catch(() => {}));
  }

  async install() { await this.ensureSeeded(); }
  async afterEnable() { await this.ensureSeeded(); }

  async unload() {
    this.stopTimers();
    if (this._gatewayHandler) {
      Gateway?.unregisterRequestHandler?.(this._gatewayHandler);
      this._gatewayHandler = null;
    }
    if (typeof super.unload === "function") await super.unload();
  }
}

Ghi chú Vận hành & Chiến lược Đóng gói Client ​

Quy tắc vận hànhChi tiết triển khai
Gắn kết chỉ đọc (:ro)Tất cả 7 thư mục plugin đều gắn vào /app/nocobase/node_modules/@latticedx/* dưới chế độ :ro. Mọi bước biên dịch dist/ (externalVersion.js, UMD client bundle) được thực hiện trong quá trình build trước khi khởi chạy container.
Loại bỏ tệp cũ khi buildplugin-lattice-foundation/scripts/build.mjs chủ động xóa các module hoặc migration đã ngừng sử dụng khỏi dist/ sau bước cp nhằm ngăn NocoBase auto-discovery nạp nhầm tệp cũ từ các bản build cục bộ trước đó.
Phân tách bundler cho clientCác plugin chỉ dùng module tương đối nội bộ (plugin-lattice-foundation, plugin-dxos-ai) sử dụng trình đóng gói JS zero-dependency kèm node --check, trong khi plugin-dxos-blocks và plugin-dxos-studio dùng esbuild@0.28.2 (MIT) để đóng gói maplibre-gl, @xyflow/react và @dagrejs/dagre thành UMD chạy trực tiếp trên trình duyệt mà vẫn giữ react, react-dom, antd và @nocobase/client* ở dạng external.
Bảo toàn Điều 5.2 NocoBaseGiao diện client và client-v2 giữ nguyên chân trang Powered by NocoBase, phiên bản v2.2.50, liên kết https://www.nocobase.com và mục License settings theo đúng điều khoản sử dụng runtime host.

Hàm Xuất Khẩu Tĩnh Giữa các Plugin (Plugin Static Exports) ​

Để các plugin nghiệp vụ (plugin-dxos-studio, plugin-dxos-ai) tái sử dụng các hàm dùng chung đã gắn với host mà không nhân bản mã nguồn, hai plugin lõi gắn trực tiếp các hàm tiện ích lên lớp Plugin trước khi export:

  • LatticeFoundationPlugin: xuất khẩu appendLedgerEntrySafely, computeMeanKineticTemperature, recordLineageEdge, captureQuarantineRecord, publishDomainEvent, verifyStandardWebhookSignature, resolveConnectorSecrets, recordGenAiSpan, startGenAiSpan, persistGenAiTrace, dispatchOmnichannel và các hàm requestApproval / decideUnifiedInboxItem.
  • DxosStudioPlugin: xuất khẩu parseFormulaAst, evaluateFormulaExpression, validateFormulaExpression, validateSafeRegexPattern, registerRichSchemaHooks, alignPortalOverviewRoutesSort, normalizeLegacySlaEscalateRoles và createOrganizationDirectGuardMiddleware.

Tài liệu liên quan ​

Apache-2.0 · LatticeDX v0.4.2 · Powered by NocoBase · v2.2.50 · Apache-2.0 (Clause 5.2)