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

整洁架构层次

Architecture

整洁架构层次图,展示四个同心层:实体(领域)、用例(应用)、接口适配器(控制器、展示器、仓储)和框架与驱动(Web 服务器、数据库、云 SDK)。该模板模拟 Uncle Bob 的整洁架构及其依赖规则——内层永远不依赖外层,确保领域模型保持纯净且框架无关。对于强制架构边界的软件架构师来说是必备参考。

完整 FlowZap 代码

External { # External Layer (Frameworks & Drivers)
n1: rectangle label:"Express/Fastify Web Server"
n2: rectangle label:"PostgreSQL Driver"
n3: rectangle label:"Redis Client"
n4: rectangle label:"AWS SDK"
n1.handle(bottom) -> Interface.n5.handle(top) [label="HTTP Request"]
n2.handle(bottom) -> Interface.n8.handle(top) [label="DB Connection"]
n3.handle(bottom) -> Interface.n8.handle(top) [label="Cache"]
}
Interface { # Interface Adapters Layer
n5: rectangle label:"Controller"
n6: rectangle label:"Presenter"
n7: rectangle label:"DTO Mapper"
n8: rectangle label:"Repository Implementation"
n5.handle(right) -> n7.handle(left) [label="Map Input"]
n7.handle(bottom) -> UseCase.n9.handle(top) [label="Request Model"]
n6.handle(top) -> External.n1.handle(bottom) [label="View Model"]
n8.handle(bottom) -> UseCase.n12.handle(top) [label="Implements"]
}
UseCase { # Use Cases Layer (Application)
n9: rectangle label:"Create Order Use Case"
n10: rectangle label:"Get Order Use Case"
n11: rectangle label:"Cancel Order Use Case"
n12: rectangle label:"Order Repository Interface"
n9.handle(bottom) -> Entity.n13.handle(top) [label="Call Domain"]
n10.handle(bottom) -> Entity.n13.handle(top) [label="Query"]
n11.handle(bottom) -> Entity.n14.handle(top) [label="Cancel"]
n9.handle(right) -> n12.handle(left) [label="Persist"]
n10.handle(top) -> Interface.n6.handle(bottom) [label="Output"]
}
Entity { # Entities Layer (Domain)
n13: rectangle label:"Order Aggregate Root"
n14: rectangle label:"Order Item Entity"
n15: rectangle label:"Money Value Object"
n16: rectangle label:"Order Status Enum"
n13.handle(right) -> n14.handle(left) [label="Contains"]
n14.handle(right) -> n15.handle(left) [label="Uses"]
n13.handle(bottom) -> n16.handle(top) [label="State"]
}

为什么需要这个工作流?

Frameworks and databases change frequently, but business rules should remain stable. Clean Architecture enforces the dependency rule—inner layers never depend on outer layers—ensuring that the most important code (domain logic) is the most stable and testable, while infrastructure details are easily replaceable.

工作原理

  1. Step 1: The Entities layer defines domain models, value objects, and business rules.
  2. Step 2: The Use Cases layer implements application-specific business logic.
  3. Step 3: The Interface Adapters layer converts data between use case format and external format.
  4. Step 4: The Frameworks & Drivers layer contains web servers, database drivers, and cloud SDKs.
  5. Step 5: Dependencies point inward: controllers depend on use cases, use cases depend on entities.
  6. Step 6: The repository interface is defined in the use case layer but implemented in the adapter layer.

替代方案

Traditional MVC mixes concerns across layers. Hexagonal architecture is similar but uses different terminology. Vertical slice architecture organizes by feature instead of layer. This template provides the canonical Clean Architecture reference.

Key Facts

Template Name整洁架构层次
CategoryArchitecture
Steps6 workflow steps
FormatFlowZap Code (.fz file)

相关模板

六边形(端口与适配器)架构

Architecture

六边形架构图,展示领域核心、入站适配器(REST、GraphQL、CLI、消息消费者)、出站适配器(PostgreSQL、Stripe、邮件、Redis)以及连接它们的端口接口之间的清晰分离。该模板可视化端口与适配器模式,领域核心对基础设施零依赖,使其完全可测试且技术无关。对于在代码库中采用整洁架构原则的团队至关重要。

微服务 API 网关架构

Architecture

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

微服务服务网格架构

Architecture

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

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

Architecture

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

按业务能力分解微服务架构

Architecture

按业务能力组织的微服务分解架构图:身份认证、产品目录、定价和订单履行,每个都有独立的数据存储和 API。该模板展示如何将单体应用拆分为与业务领域对齐的服务,使用 Backend-for-Frontend (BFF) 模式进行客户端特定的聚合。适合规划领域驱动微服务边界的架构师。

微服务绞杀者模式迁移架构

Architecture

绞杀者模式迁移架构图,展示使用路由层在新旧系统之间分流流量,逐步用新微服务替换遗留单体应用。该模板模拟经过验证的迁移策略,新功能作为微服务构建,遗留端点逐步退役。对于在不进行高风险大爆炸重写的情况下现代化遗留系统的团队至关重要。

返回所有模板