目录

用C4-PlantUML画软件架构图

目录

C4 Model是一种简洁有序的架构模型,四个“C”分别表示“Context”、“Container”、“Component”和“Code”,是由上而下逐步细化的四个层级。

Contex即上下文,它表示我们正在构架的软件系统和用户、其它系统之间的关系。例如:

https://www.plantuml.com/plantuml/svg/0/TLHBRzim3BxxLt2vD0NIP8UTTceUnbeiZo8F53qPYaB7GcJ9a-IcmR3_FigE4xjrSeh8Z-H7ygCVhMF6vQaClWd5PRx3t4X8dClipy70i6D_BroIRtEBXclbKBa-r-bWAJWpEpqNcA4SZ7yyl4Yct6Os7QJCEZHaYiOU_-7wcKz_1xcYm9GIW4iGOYsbFWgr1oaK0bCxQBY5iVHF0nK6gJcJyaGvAfBmENrmDns-BJRhQBruYIQBr_d5C5n5gz_XUln4uMVJw_FwAPg6lyBv90YSS19XTIBMAKo9X-KiGzW9jZSi9Pu6Hc8F8wOEa4aU12zeh5PTdbkdKpGzw9GM9WkGRsbyzdN8EOGA2JekUjiIgWT7cYjaLQIt0UDSvyhPVkS-24BgpcH6M8n6PDqnS-hoxvImpgPp3ty3e5_9lxij2KIsU1BusMTHw2xKIc11p2_0NjXPF-rtWKSGYffEcHDQ0TlglDY8C4sElM9bAJiWPEpazrRIlfA9mW_NPSwp6AvdjohwCUn8Py2PJNo6JmbI9kIrdV31ly5UcbZJF4NH8mrn9hZHLiSEmW-UCBL7m7f06q5ogvWMZPHiLlrlcTRAQOCMI8VL6ZaPu3pmbfbTkkpLPkOCKvPn3wCNEdwXL6gee5H5HdHpxu9xPfMWO5MQOELO77VgdZCOhFSKOnNg8hTgiBKgMyOFaOxZii28Nh0eNjVSmrqgbB14kkoB5cxpBDF6tQxoBmYMAACvYdsorQPs9b-qkR5eASB3bpLSAPdNiovi8Gpw353e6Uovrl1DXQoGBlYyTYymFz_F5Le6FBG72tzojCLgV9mN5qhC4gsmIZBvSc2tYpSeByj3g8kjqNrBsZRWf4KRDw2Rve9RKC6KdIXZGQnPl-chIjuNnatp8g_EH-gTliJ_0G00
System Landscape diagram for Big Bank plc

容器(Container)把关注点放在被架构的系统本身,显示组成系统的容器(例如:APP、Web端、API、微服务、数据库等)及彼此之间的关系。例如:

https://www.plantuml.com/plantuml/svg/0/bLN1Zjf84BtxAsh98KJo35ffJtiA0sXdae7nZfcTv6ILsmMqqkwskjiG5Es_RxMn0KEKP3dPHTMhrwzUjTyxZzRNfOf-argekg3QAjXuNxa_HoEBkzkrz9iwhnrPORGdxM-5AKVFKg0jp49IHMeq-UCcKQZzo_nnLABpP3cKJJWVfIPxMuK6Rw7MN5eo1FWDmSeePNPIhq5n4g0keFUtj8wV371hK4QWKdl6w6Z2TOFeSVpvwMMPBP-IRFhqkeZUje5ncgKVPyl9FTUteTU7vNtsEFjhjfX6aPTUCM271eN4jSMI6Lfuu3DRJHxkK7y9PDCzdw-CeeIiCteeQkTDIJQ6oV5fC8Ok36RLd2RdwXXsh2LKJI6g9WOeXAcrTuDtKNI0pkuuKA3T3yNlZ7L9OF0ElaN0loFVuOxo3AkAaryfXt5LAPwEbqOFEFG1jnX3Mjb0VlxF9CIcfEIMQJJKs05U2cYdsymXX8zzy-xWoPX9zZkxYh47AV-jw2R1DONkNTTKM5dv6CPwNIkq8PnOivK5EU1fVh_BYaqIgAEIVX_6B-f6I0TRYQ54Mk3pGcxDZZrvnQWqkLJKoZ5lNZfEapSnVC8IMOa-5pPWAJqLuEhSCPTsPh_2pLsHEn20WhPIq2MzQJuiq6EEZi8OsiV09ltx4NhltbZc5lOEBAsbynQvDKZDhYoRwSQmuUG2i6PN2Ki5Zq-YSd4m5Jd7MxFc5_BYzagc7CKNqWNh98DVauVlssPgECsUwdgw_KIV80a3S-j_ZzQUVVL3Ab6gp3K1XflTpFczNQk0lsJfPGFDEpANmXfdLXvcNyK6DJliKCcmPvWjWnCgO-eLxp1TxEsPjC62xQG51uwdE5COC3UrFuqvFgvh33mFxR0vxqdaw9dKsPLmMimNHoxqlbykavGJ-tc7DVfnJi_OJUgXNROWkTxavkmQEC1rIzuYDS7-sBk6wFPQnF0XVLgCpfkVj_nVbTaTPv-8dIpVHtacB1oih2cRMsTdUGdvJZ81kGMUtaswSmRCCpqkR9Goh0Ew2T46uqJamd5z3lswseKRzjW-dI-J5kXuc5xvbUywOKBzg5Nd4tyLEt7USob_g_u3
Container diagram for Internet Banking System

组件(Component)把一个容器放大,拆分成不同的抽象逻辑,这一层级已经涉及代码层面的内容。例如:

https://www.plantuml.com/plantuml/svg/0/fLLDRnen4BtlhvXoQ45AmgMddaf8sYJA1mBIZnEQzGwBMt-iR2yKLVtl7Nk1NPAeYjHSuXsFPzwyzsm--e0kr5fbRwGHgYweTWfM8LJ-mt3eS7DMoh2gyzgJ4zO4Ck5CM3sSIe6kiFUIAbB3yVlJYK8J7kzkXnfz8CUXnTZgoffueeeDta5j-AZc08GLmT8gPJVIbA2a8K1JmD6sT9vN5hWrA2jGgItNsCE4vmsosz7tXyVvuklr_6fnU_dvylwYFyYo88FYz7qk519BXvhxExZcYPoX0ETeVaOeiosZrt0AeyarZAfAyPn1MfDbOvuU6QZh-mfFe3VZTAuxmPAwYJtU-e5hzCB9AgIfq9IrGXTt9iwkPK4UU9eqfTm3o7S0banIh8DAXcqSNzG-M4tEmrfYF2CTR2Y7tDaDYtBM6tIWwOZipkPI9L2nvJVKwAGvxiwKQnce05_ddhlRy1zeTDDlzw-WjHHq1EiYxnSvzx_0W3bwYbYcfB2f3FimpCIADCRTMR2ESKRNWQDI-k1IDYDasNHQdy0A_Ofdm9fncB0J08IZ8dwYyYU0Gf3tx9-IFoY8YAlHU77vA_HrxYDXZ7B9bg0dDkWWYNhPPI99SE10K0SFO6xhq3AKcjlQ15unVECnKTdYQ0bQd7DUWMxRnqfoqoVcwmtWTmRyTp1ntylI91EMXaqCiPBZ-qJ9PNTVnZ0blZs7S8oEudLhEFLHobY2ySVbYzhxXeF1ayxjKBtHRWcpMhF9jg-2SJ1XQwKDFp7iISzLB5TfU6PZHIG74fy1yIHgnxQCDEoMxMwIhd9nZdF2O_SVczf58xAB4YEcR4Gz0R72vgD2xpVM5Qrknp3OGaiKMD0_Z0IVKiOBe4RG70QcgD517seS2v4S4rlppTd9ts7WqTEUeRZVYjI5zoIfFPvkvvImWBUmuH0n6n7TpSNvk7EWKwkvEAbWV6FutR-QpoSpJlwJPQbuV2HtBjsdtSmUxWzvXwIEeLvCJ9dw5TNqAufz95FmRyLV
Component diagram for Internet Banking System - API Application

而抽象逻辑内部代码之间的关系由Code这一层展示。

C4-PlantUML是为PlantUML封装的一套模板,用来画C4架构图既美观又方便。下面是我画的样子:

https://www.plantuml.com/plantuml/svg/0/jLXVJzjM57_Ff_3oKYAnvcLFUse7Q7Ib445GDMcIPHmRh3fsP3ljq5I9m4ef8v0MwDgDjGqjRRKL1rG68H7amyptElaMkzVNyP_43cPXUOXkxZs_txddt7FEFJStL8rHj7nMZCM-42HMp6SuQaxJSkhNoQJ2FBW-AsXp-PcyoYciB6cSf5rdvMnoKc0P9IEF2roE4vD3NtsP4Xb9cxupbimogiOfQ8eUGlAC877AzHoclqRb9GJD8WfAc-CeNXP5-O4WpL8Y4g8OAKFvbWL5HIEPGgefKMOPKPn77CuUknN4ncv-Fp6TfjCJANfuukuuahPdRaxHKxT7qaEZ0mbtykwjz2WzDlBjoFWmcevfWYPob57x03OBIQFs3hxOJ3QFTi5g6VvTCAg_uS6hO_ZgvrWinIcgB0ta53cJPpKwoqZCBASCsc2plc6MbXDjAJQlQdAMKsX6LGNaQqaRf82-2tUAtI8E4nPOEUbWObXMpak4WUoilKIF_AWvB6sqRp73gSAiX1UR-dbJBuFg2h9v11seabC4bQE_GTGPHfaVU20hzsOuYPqRfEBWPCyusm4R1_44zLECGf-fUNIwMLUwxGEMmrG8GdnWLFT1Oyb1uOzpM0CvbkOLAvOoMCUJelbN9Ov6tp7t6PLLX1ooxwQa3LjRZZiYhVAf-RiUJmGppZ3iFPkmj6uJfaPJWzHO7eLKt9c7wtjWusqGo_0Cviam6ZF3g5o7AN3x01PrKDl4JAqNZTRZDQFsr9q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5wwo4_zfavkdXNlSy_lyJhgvwdpFeOU9zkS6jSx1oW5-MjJNqDeiHogvIvtaU9IwI8OTmeLWxK2uKj8F1jWMyUzvQ-cY_NwpDmvq5e_eBUXPt45bFkNR7cGXQTBVWEDEV1xxGI3X2dHK6uM-WSJuh_Wi0
产品 交易 财务流业务架构

和上面的例子相比,好像不太适合画较复杂的架构,布局不太好处理,另外连线太多容易重叠在一块傻傻分不清楚。