欢迎使用 FlowZap,快速、清晰、掌控的绘图应用。

CQRS 基于任务的 UI 架构

Architecture

CQRS 基于任务的 UI 架构图,前端将用户意图捕获为显式命令,异步提交并进行乐观更新,当读模型同步时通过 WebSocket 接收实时确认。该模板模拟用意图驱动命令替代 CRUD 表单的现代 UI 模式,实现具有最终一致性的响应式用户体验。推荐给在 CQRS 后端上构建响应式前端的团队。

完整 FlowZap 代码

UI { # Task-Based UI
n1: circle label:"User Intent"
n2: rectangle label:"Render Task Form"
n3: rectangle label:"Capture User Intent as Command"
n4: rectangle label:"Submit Command"
n5: rectangle label:"Show Optimistic Update"
n6: circle label:"UI Updated"
n1.handle(right) -> n2.handle(left)
n2.handle(right) -> n3.handle(left) [label="PlaceOrder"]
n3.handle(right) -> n4.handle(left) [label="Command DTO"]
n4.handle(bottom) -> CommandAPI.n7.handle(top) [label="POST /commands"]
n4.handle(right) -> n5.handle(left) [label="Optimistic"]
n5.handle(right) -> n6.handle(left)
}
CommandAPI { # Command API
n7: rectangle label:"Deserialize Command"
n8: rectangle label:"Authorize User"
n9: diamond label:"Idempotency Check"
n10: rectangle label:"Dispatch to Handler"
n11: rectangle label:"Return 202 Accepted"
n12: rectangle label:"Return 409 Duplicate"
n7.handle(right) -> n8.handle(left)
n8.handle(right) -> n9.handle(left)
n9.handle(right) -> n10.handle(left) [label="New"]
n9.handle(bottom) -> n12.handle(top) [label="Duplicate"]
n10.handle(right) -> n11.handle(left) [label="Queued"]
n11.handle(top) -> UI.n5.handle(bottom) [label="202"]
n10.handle(bottom) -> Domain.n13.handle(top) [label="Process"]
}
Domain { # Domain Model
n13: rectangle label:"Load Aggregate"
n14: rectangle label:"Execute Business Logic"
n15: rectangle label:"Persist State Change"
n16: rectangle label:"Emit Events"
n13.handle(right) -> n14.handle(left) [label="Current State"]
n14.handle(right) -> n15.handle(left) [label="New State"]
n15.handle(right) -> n16.handle(left) [label="Committed"]
n16.handle(bottom) -> QuerySync.n17.handle(top) [label="Async"]
}
QuerySync { # Query Synchronization
n17: rectangle label:"Update Read Model"
n18: rectangle label:"Push via WebSocket"
n19: rectangle label:"Invalidate Cache"
n17.handle(right) -> n18.handle(left) [label="Real-Time"]
n18.handle(top) -> UI.n6.handle(bottom) [label="Confirmed Update"]
n17.handle(right) -> n19.handle(left)
}

为什么需要这个工作流?

Traditional CRUD forms map poorly to complex business operations—a "Place Order" action involves validation, payment, inventory, and shipping, not a simple database row update. Task-based UIs capture user intent as explicit commands, enabling optimistic updates, async processing, and real-time confirmation via WebSocket.

工作原理

  1. Step 1: The UI renders a task form that captures user intent (e.g., "Place Order" not "Update Row").
  2. Step 2: User intent is serialized as a command DTO and submitted to the Command API.
  3. Step 3: The UI immediately shows an optimistic update while the command processes asynchronously.
  4. Step 4: The Command API checks idempotency, authorizes the user, and dispatches to the domain.
  5. Step 5: After processing, the read model is updated and a WebSocket push confirms the real state.
  6. Step 6: Cache invalidation ensures subsequent reads reflect the latest state.

替代方案

Traditional CRUD forms are simpler but cannot express complex business intent. Polling for updates adds latency. Server-Sent Events are simpler than WebSockets for one-way updates. This template shows the full task-based UI with optimistic updates.

Key Facts

Template NameCQRS 基于任务的 UI 架构
CategoryArchitecture
Steps6 workflow steps
FormatFlowZap Code (.fz file)

相关模板

事件驱动 CQRS 与事件存储架构

Architecture

CQRS 架构图,结合独立的命令和查询 API 与事件总线进行异步读模型同步,包括从领域事件构建反规范化视图的投影器。该模板演示了完整的 CQRS+ES 技术栈,写入通过领域验证,读取从优化的物化视图提供服务。适合读写工作负载具有根本不同扩展需求的高吞吐量系统。

CQRS 读写分离架构

Architecture

CQRS 读写分离架构图,展示专用的命令和查询路径,PostgreSQL 用于写入,Redis 或 Elasticsearch 用于优化读取,以及带有延迟监控的事件驱动同步层。该模板演示了 CQRS 的核心原则——分离读写模型以独立扩展和优化每条路径。适合读写比例不对称且查询性能至关重要的应用。

CQRS 物化视图架构

Architecture

CQRS 物化视图架构图,多个投影器构建特定用途的读模型:订单摘要、客户仪表板、分析立方体和搜索索引,全部由单一事件流提供。该模板展示如何从相同的写入事件创建多个优化的查询视图,每个视图针对特定用例定制,读取延迟低于毫秒级。适合需要从单一数据源进行多样化查询模式的系统。

微服务 API 网关架构

Architecture

微服务 API 网关架构图,展示请求路由、JWT 身份验证、速率限制、服务发现以及跨分布式后端服务的响应聚合。该模板模拟微服务生态系统中所有客户端流量的入口点,在请求到达内部服务之前执行安全策略。适合设计具有集中式横切关注点的可扩展 API 基础设施的平台工程师。

微服务服务网格架构

Architecture

服务网格架构图,展示 Istio 或 Linkerd 边车代理处理 mTLS 加密、流量策略、熔断器和跨微服务的分布式追踪。该模板可视化服务网格如何将网络关注点从应用代码中抽象出来,实现服务间的零信任通信。对于采用服务网格基础设施以提升可观测性和安全性的团队至关重要。

微服务每服务独立数据库架构

Architecture

每服务独立数据库架构图,每个微服务拥有其专用数据存储,通过 Kafka 进行事件驱动同步以实现跨服务数据一致性。该模板展示了微服务数据隔离的核心原则,展示 PostgreSQL 和 MongoDB 如何在多语言持久化策略中共存。对于在保持最终一致性的同时强制服务自治的架构师至关重要。

返回所有模板