Search CTRL + K

C4 Model

The C4 model was created as a way to help software development teams describe and communicate software architecture, both during up-front design sessions and when retrospectively documenting an existing codebase. It's a way to create maps of your code, at various levels of detail, in the same way you would use something like Google Maps to zoom in and out of an area you are interested in. [1]

C4 模型是一种分层表述软件架构和设计的建模工具。C4 模型将软件系统架构拆分为 4 个层级,以不同维度去看软件系统,包含不同粒度的信息。类似于地图放大(Zoon in)、缩小(Zoon out)。

C4 模型需要一种通用的抽象语言来描述不同层级的内容,为了便于描述,将软件系统抽象为 系统上下文容器组件代码 四个层级。[2]

系统上下文(Context)

uml diagram

上下文层级展示正在构建的软件系统和其他系统、用户之间的关系。

容器(Container)

uml diagram

容器层展示组成该软件系统的容器(指能独立部署的单元,比如应用程序、数据存储、微服务等)。该层可以表达软件系统的技术决策。

组件(Component)

将单个容器放大,组件层反映到代码逻辑的真实抽象。组件在 C4 模型的定义中是指封装在良定义接口后的不同实现,也就是说组建层描述一堆实现类之间的关系。

代码(Code)

当确实有必要时,可以放大某几个关键组件到代码层,展示某个组件的接口和类。代码层直接反映代码逻辑,一般使用 UML 图、流程图描述。


  1. https://c4model.com/ ↩︎

  2. https://www.infoq.cn/article/C4-architecture-model/ ↩︎