logiSA 2.0 / DOCS

Design baseline · 28 SEP 2026 · 02 / 23

High-level architecture

Process Definition → Workflow → Task · mô hình quy trình nghiệp vụ end-to-end.

HIGH-LEVEL ARCHITECTURE · TARGET MODEL

01 · Process Definition → Workflow → Task

Process Definition mô tả nghiệp vụ end-to-end. Mỗi Workflow con có một Role owner và nhiều Task có thể rẽ nhánh, chạy song song, hội tụ hoặc chờ. Process Instance gắn quy trình với booking/lô hàng cụ thể.

Channel event qua Gateway và Core Intake đến Process Orchestrator. Orchestrator tìm Process Definition và Business Case/Process Instance; instance gồm nhiều Workflow Instance. Mỗi Workflow thuộc một Role, gồm task graph; task chạy bằng human, deterministic code hoặc AI skill.

02 · Runtime hiện tại (để đối chiếu)

Đây là luồng code đang chạy: intake cố định theo media; Cont/Seal match workflow config theo session/group. Master Orchestrator và Workflow Canvas chưa nằm trong execution path.

Zalo đến Gateway đến Core. Ảnh đi qua group config đến OPS image worker rồi CUSTOMER_SERVICE report dispatch. Text đi qua text worker. Master Orchestrator API là đường riêng; Canvas là config, validation và dry-run.

03 · Deployment và ownership

Gateway sở hữu transport; Core sở hữu Process/Workflow/Task state và business decisions; PostgreSQL lưu state và audit; adapters gọi model và dịch vụ ngoài.

Gateway sở hữu transport, Core sở hữu nghiệp vụ và orchestration, PostgreSQL lưu state, các adapter kết nối dịch vụ ngoài.
Phân biệt target với hiện trạng. Process Definition → nhiều Workflow → nhiều Task là mô hình kiến trúc đề xuất. Runtime hiện tại chưa có Process Orchestrator chung và chưa thực thi Workflow DAG production.
01Inbound eventGateway nhận notify từ channel, gom album, lưu inbox rồi chuyển canonical event vào Core.
02Context + correlationCore xác thực tenant/session/thread, lấy sender/group/config, business references và công việc đang mở.
03Process OrchestratorPhân loại intent, tìm hoặc tạo Business Case/Process Instance, chọn Workflow con cần bắt đầu/tiếp tục.
04Role-owned WorkflowMỗi Workflow có một Role owner; Workflow quyết định Task graph, nhánh, wait, review và handoff.
05Task executionTask chạy bằng code thường, AI skill hoặc human; quyền và schema được kiểm tra phía Core.
06Commit + integrationValidator cập nhật facts/state/audit atomically; outbox gọi channel, Sheet, ERP hoặc payment adapter.

Ranh giới module trong kiến trúc đích

Thành phầnSở hữuKhông tự quyết
TS channel gatewayPhiên kênh, gom media, inbox giao nhận, gửi outbound và receiptNghiệp vụ, role, quyền sửa shipment
Dashboard / BFFLogin, tenant scope, UI và proxy có xác thựcTenant lấy từ payload client; credentials public
Quarkus coreDispatcher, role runtime, orchestrator, validators, DB transactionsĐể output model tự commit business state
Model adapterText/vision completion và structured parsing; capability-based model profileSở hữu task/flow state hoặc tạo đích gửi tùy ý
Integration adapters / MCPSheet read/write, provider API, schema validation và auditTự quyết scope hoặc role permission
PostgreSQL + evidence storageNguồn sự thật; durable jobs/outbox, object metadata, auditDùng chat history hoặc model memory thay cho facts

Domain model và naming

Khái niệmVai trò trong kiến trúc
Process DefinitionĐịnh nghĩa quy trình end-to-end, ví dụ xử lý lô hàng từ lập kế hoạch đến thu tiền. Nó chứa nhiều Workflow Definition.
Workflow DefinitionMột quy trình con có ranh giới nghiệp vụ và đúng một Role owner. Nó chứa nhiều Task Definition với điều kiện, nhánh và điểm chờ.
Task Definition / Task InstanceĐịnh nghĩa việc và một lần thực hiện cụ thể. Task có input/output schema, executor kind, retry/timeout và kết quả kiểm định.
RoleTrách nhiệm logistics thực tế như Field Operations, Documentation, Fleet Dispatch, Customer Service, Finance, Supervisor. Role sở hữu Workflow; không phải model/provider.
Business CaseDanh tính nghiệp vụ ổn định như booking/lô hàng, dùng để tương quan message và nhiều quy trình.
Process InstanceMột lần chạy Process Definition cho Business Case cụ thể; chứa các Workflow Instance và state tổng.
Workflow InstanceMột lần chạy Workflow con trong Process Instance; chứa Task Instances, task graph state và Role/version snapshot.
Message EventĐầu vào hoặc bằng chứng cập nhật case; không mặc định tương đương một Task hay một Process Instance mới.

Luồng xử lý mục tiêu

  1. Channel gửi notification/event tới Gateway. Gateway chuẩn hóa envelope, gom album, lưu inbox bền vững và chuyển event sang Core.
  2. Core xác thực scope, dedupe và persist event. Context Resolver lấy channel/session, tên nhóm, sender, config, media/text, case references và active work.
  3. Process Orchestrator xác định loại nghiệp vụ. Rule đã cấu hình được ưu tiên; AI hỗ trợ semantic routing khi cần. Nó tìm Business Case và Process Instance hiện hữu trước khi tạo mới.
  4. Orchestrator chọn Process Definition phù hợp, rồi bắt đầu/tiếp tục một hay nhiều Workflow con theo intent và trạng thái. Message có thể cập nhật nhiều workflow nếu chứa nhiều ý độc lập; không tạo workflow chỉ vì có message mới.
  5. Workflow có một Role owner và điều phối nhiều Task theo graph: tuần tự, song song, condition, join, wait hoặc human review. Handoff giữa Role diễn ra qua Workflow boundary.
  6. Task executor có thể là deterministic code, AI skill/model, human action hoặc connector. Role/workflow policy giới hạn quyền; AI đề xuất kết quả nhưng Core validate và commit.
  7. Kết quả được ghi cùng state, evidence, audit và outbox. Message/receipt sau đó có thể resume đúng Process/Workflow Instance theo correlation.

AI architecture: dùng AI ở đâu?

Ranh giới module

ModuleSở hữu
Channel GatewayChannel sessions, album/message normalization, durable inbox, outbound command và receipt.
Core IntakeCanonical event, tenant scope, dedupe, event persistence và inbox ACK.
Process OrchestratorIntent routing, case correlation, Process Definition/Instance lifecycle, chọn workflow start/resume.
Workflow RuntimeWorkflow graph state, Role owner, task scheduling, branch/join, wait/retry/review, version pinning.
Role & Task CatalogRole responsibility/policy, Task schema/executor contract, workflow ownership và capability binding.
Task ExecutorsVision/OCR, code rules, Sheet lookup, human approval, send result; không tự thay state machine.
State + evidence storeBusiness Case, process/workflow/task instances, facts có provenance, idempotency, audit và outbox.
AI Connector & StatsModel providers, model routing theo policy, usage/quota/cost logs và thống kê. Không sở hữu Workflow/Task state hoặc business routing.
Business ConnectorsSheet/MCP/ERP/channel/payment adapters; quyền gọi do Task capability + Tool Broker kiểm tra, không nằm trong AI Connector.

Hiện trạng runtime so với target

Nguyên tắc triển khai

  1. Định danh Business Case/correlation trước khi tạo Process Instance; tránh mỗi message tạo một case mới.
  2. Process Definition và Workflow Definition version hóa độc lập; running instances pin snapshot.
  3. Mỗi Workflow có một Role owner. Cross-role handoff được mô hình thành workflow khác trong cùng Process Definition, không giao Role gọi chéo.
  4. Task graph hỗ trợ fan-out/fan-in; khai báo join policy, timeout và failure path rõ ràng.
  5. Outbox/integration side effect chạy idempotent/reconcilable; unknown receipt không tự gửi lại.
  6. Triển khai modular monolith trước; chỉ tách worker/service khi tải hoặc ownership yêu cầu.

Liên quan: Intake & Process Routing · Role & Task · Process / Workflow Runtime · Vertical slice Cont/Seal.

logiSA 2.0 · Public development cookbook · Design target; implementation status in Delivery.