hi,我是熵减,见字如面。

昨天我们用ChatGPT来设计一个账号系统,并尝试输出:模型表,类关系图,序列图,状态图等常用的架构设计中常用的元素。

今天,我们继续向更高层级延伸一下,看ChatGPT能不能更进一步释放工程师的生产力,创造更多的可能性。

所以,这次我们就来尝试用ChatGPT,来构建账号系统的C4模型的架构图啦。

由于ChatGPT不能直接输出图像,所以我们转化为用Mermaid的脚本,通过markdown的方式输出,再用支持Mermaid渲染的工具,将图片显示出来。

生成数据库初始化SQL

我们首先来试试,生成数据库初始化SQL吧。

提示:将以上账号系统的数据模型,生成MySQL数据库的SQL

ChatGPT:

-- 创建表:Account
CREATE TABLE Account (
id INT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
password VARCHAR(50) NOT NULL,
email VARCHAR(50),
phone_number VARCHAR(20),
state VARCHAR(20),
email_ver BOOLEAN DEFAULT false,
phone_ver BOOLEAN DEFAULT false,
created_at DATETIME,
updated_at DATETIME
); -- 创建表:EmailVerification
CREATE TABLE EmailVerification (
id INT PRIMARY KEY,
token VARCHAR(50) NOT NULL,
expired_at DATETIME,
account_id INT,
FOREIGN KEY (account_id) REFERENCES Account(id)
); -- 创建表:PhoneVerification
CREATE TABLE PhoneVerification (
id INT PRIMARY KEY,
token VARCHAR(50) NOT NULL,
expired_at DATETIME,
phone_number VARCHAR(20),
account_id INT,
FOREIGN KEY (account_id) REFERENCES Account(id)
); -- 创建表:ThirdPartySocialAccount
CREATE TABLE ThirdPartySocialAccount (
id INT PRIMARY KEY,
provider VARCHAR(20) NOT NULL,
provider_id VARCHAR(50) NOT NULL,
account_id INT,
FOREIGN KEY (account_id) REFERENCES Account(id)
); -- 创建表:LoginRecord
CREATE TABLE LoginRecord (
id INT PRIMARY KEY,
account_id INT,
login_at DATETIME,
FOREIGN KEY (account_id) REFERENCES Account(id)
);

以上SQL语句可以在MySQL数据库中创建相应的表,包括Account、EmailVerification、PhoneVerification、ThirdPartySocialAccount和LoginRecord五个表,并设置它们之间的关联关系。

直接输出C4 Diagram

接下来我们直接尝试其是否可以输出系统的C4模型的代码吧。

提示:对于系统架构图,用Mermaid's c4 diagram是非常有效的,接下来,我们需要开始构建c4 模型的Mermaid脚本,并用markdown

ChatGPT:

好的,以下是用Mermaid's C4 Diagram构建系统架构图的Mermaid脚本,并用markdown格式输出:

## C4 Model for Account System

### Level 1: System Context Diagram

title Account System - System Context Diagram

actor User

User -> AccountSystem: Use

### Level 2: Container Diagram

title Account System - Container Diagram

AccountSystem -> AccountService: Uses
AccountSystem -> EmailService: Uses
AccountSystem -> PhoneService: Uses
AccountSystem -> ThirdPartyService: Uses
AccountSystem -> Database: Uses AccountService -> Database: Reads/Writes
EmailService -> Database: Reads/Writes
PhoneService -> Database: Reads/Writes
ThirdPartyService -> Database: Reads/Writes ### Level 3: Component Diagram title Account System - Component Diagram AccountSystem --> AccountService: Manages Accounts
AccountSystem --> EmailService: Sends Email
AccountSystem --> PhoneService: Sends SMS
AccountSystem --> ThirdPartyService: Interacts with Social Platforms AccountService --> Account: Accesses Account Data
EmailService --> EmailVerification: Validates Email
PhoneService --> PhoneVerification: Validates Phone Number Account --> PasswordSecurity: Manages Passwords
Account --> LoginRecord: Records Login Information

虽然给出了完整的代码,但在我的vscode的插件中,无法渲染出正确的结果图。

我推测由于ChatGPT训练的时间是21年的,所以其给出的代码版较低,而Mermaid近期升级了对C4模型的脚本规范,所以,我试图提升ChatGPT升级一下:

提示:这不是最新版的,请用Mermaid的最新版的C4 Diagrams脚本,再次输出

ChatGPT:

输出的结果,依然在我的渲染插件中无法展示。

所以,我尝试换了一种方法,来让其帮我继续做C4模型图,这也是我发现的一个大惊喜:

你给ChatGPT一个内容模版,它立马就会学会应用,而且效果惊人。

下面我们继续来看新方法的过程。

C4模型实验

C4Context视图

我输入的提示:下面,我要给你一个最新版本的Mermaid C4 Diagrams脚本案例,你要记住哦

ChatGPT:好的,尽管跟我分享吧。

我将从Mermaid官网上复制的C4Context代码输入给了ChatGPT:

    C4Context
title System Context diagram for Internet Banking System
Enterprise_Boundary(b0, "BankBoundary0") {
Person(customerA, "Banking Customer A", "A customer of the bank, with personal bank accounts.")
Person(customerB, "Banking Customer B")
Person_Ext(customerC, "Banking Customer C", "desc") Person(customerD, "Banking Customer D", "A customer of the bank, <br/> with personal bank accounts.") System(SystemAA, "Internet Banking System", "Allows customers to view information about their bank accounts, and make payments.") Enterprise_Boundary(b1, "BankBoundary") { SystemDb_Ext(SystemE, "Mainframe Banking System", "Stores all of the core banking information about customers, accounts, transactions, etc.") System_Boundary(b2, "BankBoundary2") {
System(SystemA, "Banking System A")
System(SystemB, "Banking System B", "A system of the bank, with personal bank accounts. next line.")
} System_Ext(SystemC, "E-mail system", "The internal Microsoft Exchange e-mail system.")
SystemDb(SystemD, "Banking System D Database", "A system of the bank, with personal bank accounts.") Boundary(b3, "BankBoundary3", "boundary") {
SystemQueue(SystemF, "Banking System F Queue", "A system of the bank.")
SystemQueue_Ext(SystemG, "Banking System G Queue", "A system of the bank, with personal bank accounts.")
}
}
} BiRel(customerA, SystemAA, "Uses")
BiRel(SystemAA, SystemE, "Uses")
Rel(SystemAA, SystemC, "Sends e-mails", "SMTP")
Rel(SystemC, customerA, "Sends e-mails to") UpdateElementStyle(customerA, $fontColor="red", $bgColor="grey", $borderColor="red")
UpdateRelStyle(customerA, SystemAA, $textColor="blue", $lineColor="blue", $offsetX="5")
UpdateRelStyle(SystemAA, SystemE, $textColor="blue", $lineColor="blue", $offsetY="-10")
UpdateRelStyle(SystemAA, SystemC, $textColor="blue", $lineColor="blue", $offsetY="-40", $offsetX="-50")
UpdateRelStyle(SystemC, customerA, $textColor="red", $lineColor="red", $offsetX="-50", $offsetY="20") UpdateLayoutConfig($c4ShapeInRow="3", $c4BoundaryInRow="1")

ChatGPT:

提示:请按照上面给的案例,输出我们修改后的账号系统的C4Context的Mermaid脚本,用markdown输出

ChatGPT输出:

C4Context
title Account System Context Diagram Enterprise_Boundary(EB, "Account System Boundary") {
System(AccountSystem, "Account System", "Allows users to manage their accounts, passwords, and login sessions.")
User(User, "User", "A user of the account system.") System_Ext(MailSystem, "Email System", "The internal email system.")
System_Ext(SMS, "SMS System", "The system that sends SMS messages for 2FA.") AccountSystem --> User
AccountSystem --> MailSystem
AccountSystem --> SMS
} BiRel(User, AccountSystem, "Uses")
Rel(AccountSystem, MailSystem, "Sends emails")
Rel(AccountSystem, SMS, "Sends SMS messages for 2FA") UpdateElementStyle(User, $fontColor="red", $bgColor="grey", $borderColor="red")
UpdateRelStyle(User, AccountSystem, $textColor="blue", $lineColor="blue", $offsetX="5")
UpdateRelStyle(AccountSystem, MailSystem, $textColor="blue", $lineColor="blue", $offsetY="-10", $offsetX="-50")
UpdateRelStyle(AccountSystem, SMS, $textColor="blue", $lineColor="blue", $offsetY="10", $offsetX="-50")

代码渲染后为:

实验成功,那接下来的其他的C4模型,就可以如法炮制啦。

C4Container视图

提供Mermaid官网的demo后,就可以提示:

请按照上面给的案例,输出我们我们要处理账号系统C4Container的Mermaid脚本,用markdown输出

ChatGPT输出代码为:

C4Container
title Container diagram for Account System System_Ext(identity_provider, "Identity Provider", "An external identity provider, such as Auth0 or Okta", $tags="v1.0")
Person(user, User, "A user of the system, with a registered account", $tags="v1.0") Container_Boundary(c1, "Account System") {
Container_Ext(web_app, "Web Application", "Java, Spring MVC", "Delivers the static content and the account system SPA")
Container(spa, "Single-Page App", "JavaScript, Angular", "Provides all the account system functionality to users via their web browser")
ContainerDb(database, "Database", "SQL Database", "Stores user registration information, hashed auth credentials, access logs, etc.")
ContainerDb_Ext(api, "API Application", "Java, Docker Container", "Provides account system functionality via API") } Rel(user, web_app, "Uses", "HTTPS")
UpdateRelStyle(user, web_app, $offsetY="60", $offsetX="90")
Rel(user, spa, "Uses", "HTTPS")
UpdateRelStyle(user, spa, $offsetY="-40")
Rel(web_app, spa, "Delivers")
UpdateRelStyle(web_app, spa, $offsetX="130")
Rel(spa, api, "Uses", "async, JSON/HTTPS")
Rel_Back(database, api, "Reads from and writes to", "sync, JDBC") Rel(identity_provider, user, "Provides authentication for")
UpdateRelStyle(identity_provider, user, $offsetX="-45")
Rel(api, identity_provider, "Uses", "async, OAuth2/OpenID Connect")
UpdateRelStyle(api, identity_provider, $offsetY="-60")

脚本渲染后图片为:

C4Component视图

提供Mermaid官网的demo后,就可以提示:

请按照上面给的案例,输出我们我们要处理账号系统C4Component的Mermaid脚本,用markdown输出

ChatGPT输出代码渲染后图片为:

C4Dynamic 视图

提供Mermaid官网的demo后,就可以提示:

请按照上面给的案例,输出我们我们要处理账号系统C4Component的Mermaid脚本,用markdown输出

ChatGPT输出代码渲染后图片为:

C4Deployment视图

提供Mermaid官网的demo后,就可以提示:

请按照上面给的案例,输出我们我们要处理账号系统C4Deployment的Mermaid脚本,用markdown输出

ChatGPT输出代码渲染后图片为:

备注:在ChatGPT熟悉了2-3次过程后,只要输入模版,其就会自动给出结果啦,连提示都可以省略了,重复工作完全自动化啦。

复杂状态试图

在今天的实验中,最后尝试做了一个负责的系统状态转化图,具体如下:

提示:在账号系统中的EmailVerification,PhoneVerification,ThirdPartyBinding的状态发生变化时,Account中对应信息变化的 Mermaid 脚本

ChatGPT:

以下是在账号系统中的EmailVerification,PhoneVerification,ThirdPartyBinding的状态发生变化时,Account中对应信息变化的Mermaid脚本:

给出的代码如下:

stateDiagram-v2
state "Account" as account {
state "EmailVerified" as emailVerified
state "PhoneVerified" as phoneVerified
state "ThirdPartyBound" as thirdPartyBound [*] --> emailVerified : initialize
[*] --> phoneVerified : initialize
[*] --> thirdPartyBound : initialize emailVerified --> phoneVerified : Email verified
emailVerified --> thirdPartyBound : Third-party bound
phoneVerified --> thirdPartyBound : Third-party bound emailVerified --> emailVerified : Re-verify email
phoneVerified --> phoneVerified : Re-verify phone
thirdPartyBound --> thirdPartyBound : Unbind third-party emailVerified --> * : Email unverified
phoneVerified --> * : Phone unverified
thirdPartyBound --> * : No third-party
}

这个脚本包含了四个节点,分别表示账户,电子邮件验证,电话验证和第三方绑定。每个节点有对应的状态,包括已验证,无效,已绑定和未绑定。节点之间的关系用箭头表示,例如账户有电子邮件验证,电话验证和第三方绑定。在状态发生变化时,节点的颜色也会相应地改变。

代码渲染图片:

继续尝试,输出以上变化的序列图,提示:

ChatGPT:

以下是在账号系统中的EmailVerification,PhoneVerification,ThirdPartyBinding的状态发生变化时,Account中对应信息变化的序列图的Mermaid脚本:

sequenceDiagram
participant Account
participant EmailVerification
participant PhoneVerification
participant ThirdPartyBinding Account ->> EmailVerification: VerifyEmail(email, code)
activate EmailVerification
EmailVerification -->> Account: EmailVerified(email)
deactivate EmailVerification Account ->> PhoneVerification: VerifyPhone(phone, code)
activate PhoneVerification
PhoneVerification -->> Account: PhoneVerified(phone)
deactivate PhoneVerification Account ->> ThirdPartyBinding: BindThirdParty(thirdPartyAccount)
activate ThirdPartyBinding
ThirdPartyBinding -->> Account: ThirdPartyBound(thirdPartyAccount)
deactivate ThirdPartyBinding Account ->> ThirdPartyBinding: UnbindThirdParty(thirdPartyAccount)
activate ThirdPartyBinding
ThirdPartyBinding -->> Account: ThirdPartyUnbound(thirdPartyAccount)
deactivate ThirdPartyBinding

上面的序列图描述了Account对象和三个相关对象(EmailVerification,PhoneVerification和ThirdPartyBinding)之间的交互,以处理EmailVerification,PhoneVerification和ThirdPartyBinding状态变化的情况。

在这个序列图中,Account对象向EmailVerification,PhoneVerification和ThirdPartyBinding发送请求,以更新与它们关联的信息。每个参与者在收到请求后执行其操作,并通过消息传递结果将结果返回给Account对象,以通知其信息已被更新。

渲染后的图片为:

写在最后

今天的实验,就这么多啦,希望对你有启发哦。

在日常的系统设计中,创造系统图表是一件不太容易,也非常繁琐的事情,而ChatGPT则可以很好的帮我们处理这些问题,让我们可以节省不少的时间和精力哦。

在实验的过程中,也可以发现ChatGPT存在这个各种可能性,只要我们能给出不错的提示,提供有效的上下文,他就可以快速的学习,并将此结果有效的利用在接下来的任务之中。

ChatGPT还有很多未知的能力,值得每一个人去探索,保持好奇心吧。

用ChatGPT,绘制一个账号系统的C4架构图的更多相关文章

  1. 一步一步教你在 Android 里创建自己的账号系统(一)

    大家假设喜欢我的博客,请关注一下我的微博,请点击这里(http://weibo.com/kifile),谢谢 转载请标明出处(http://blog.csdn.net/kifile),再次感谢 大家在 ...

  2. 如何构建一个PKM系统

    原文链接 这篇文章是个人知识总结相关的第一篇文章,主要目的是为了阐述我们为什么需要一个 PKM 系统,并且简单对自己这几年亲身形成的PKM 系统进行总结. PKM 是什么? PKM 是 Persona ...

  3. 【大前端之打通账号系统】passport应该如何落地?

    前言 之前接入百度账号系统的时候写了一篇博客做研究:[大前端]认识单点登录,出来后才发现,很多小公司其实并没有将账号系统打通,总结一下账号系统没通的原因是: ① 最初设计就没想过身份认证应该做整合 ② ...

  4. iOS----自定义UIView,绘制一个UIView

    绘制一个UIVIew最灵活的方式就是由它自己完成绘制.实际上你不是绘制一个UIView,你只是子类化了UIView并赋予子类绘制自己的能力.当一个UIVIew需要执行绘图操作的时,drawRect:方 ...

  5. OpenGl 绘制一个立方体

    OpenGl 绘制一个立方体 为了绘制六个正方形,我们为每个正方形指定四个顶点,最终我们需要指定6*4=24个顶点.但是我们知道,一个立方体其实总共只有八个顶点,要指定24次,就意味着每个顶点其实重复 ...

  6. 转:iOS绘制一个UIView

    绘制一个UIView 绘制一个UIVIew最灵活的方式就是由它自己完成绘制.实际上你不是绘制一个UIView,你只是子类化了UIView并赋予子类绘制自己的能力.当一个UIVIew需要执行绘图操作的时 ...

  7. 用canvas绘制一个简易时钟

    在见识了html5中canvas的强大,笔者准备制作一个简易时钟. 下面就是成果啦,制作之前我们先分析一下,绘制一个时钟需要做哪些准备. 一 . 1.首先这个时钟分为表盘,指针(时针,分针,秒针)和数 ...

  8. 【Mac系统 + Python + Django】之开发一个发布会系统【Django视图(二)】

    此学习资料是通过虫师的python接口自动化出的书学习而来的,在此说明一下,想学习更多的自动化的同学可以找虫师的博客园,非广告,因为我python+selenium自动化也是跟虫师学的,学习效果很好的 ...

  9. CAD指定区域绘制一个jpg文件

    主要用到函数说明: _DMxDrawX::DrawToJpg 把指定区域的内容绘制一个jpg文件中.详细说明如下: 参数 说明 BSTR sJpgFilePath Jpg文件名 DOUBLE dLbx ...

  10. WebGL简易教程(三):绘制一个三角形(缓冲区对象)

    目录 1. 概述 2. 示例:绘制三角形 1) HelloTriangle.html 2) HelloTriangle.js 3) 缓冲区对象 (1) 创建缓冲区对象(gl.createBuffer( ...

随机推荐

  1. 【每日一题】【DFS+存已加的值】2022年2月27日-二叉树根节点到叶子节点的所有路径和

    描述给定一个二叉树的根节点root,该树的节点值都在数字0−9 之间,每一条从根节点到叶子节点的路径都可以用一个数字表示.1.该题路径定义为从树的根结点开始往下一直到叶子结点所经过的结点2.叶子节点是 ...

  2. 【每日一题】【第n个 n-->0】19./NC53 【删除】链表的倒数第 N 个结点-211123/220127

    给你一个链表,删除链表的倒数第 n 个结点,并且返回链表的头结点. 答案: import java.util.*; /* * public class ListNode { * int val; * ...

  3. 单节锂电池充电管理芯片,IC电路图

    PW4054 是一款性能优异的单节锂离子电池恒流/恒压线性充电器.PW4054 适合给 USB 电源以及适配器电源供电.基于特殊的内部 MOSFET 架构以及防倒充电路, PW4054 不需要外接检测 ...

  4. Python Excel 处理模块 : OpenPyXL

    OpenPyXL模块使用方法 以下是介绍OpenPyXL的基本使用,不涉及样式和合并单元格的跨行操作 一般来说,对于大名鼎鼎的xlrd,xlwt和xlutils三个模块,Excel操作有3个基本状态 ...

  5. 《HTTP权威指南》– 16.重定向与负载均衡

    重定向 重定向 的目标是尽快地将HTTP报文发送到可用的Web服务器上去.在穿过因特网的路径上,HTTP报文传输的方向会受到HTTP应用程序和报文经由的路由设备的影响: 配置创建客户端报文的浏览器应用 ...

  6. SQLMap入门——获取数据库用户的密码

    列出数据库用户的密码 如果当前用户有读取包含用户密码的权限,SQLMap会先列举出用户,然后列出Hash,并尝试破解 python sqlmap.py -u http://localhost/sqli ...

  7. js将数组内属性值相同的项合并成二维数组

    var ary=[ {"RaDate":'2021-09-08',"Type":'Morning1','title':'测试1'}, {"RaDate ...

  8. Sql Server中order by对varchar类型排序结果不对

    1.问题描述 我写一个sql想要把查询结果根据LineNumber升序进行排序,即1.0,1.1,1.2,...1.3.2....2.0,......10.0,......15.2,......这样子 ...

  9. 关于Git在Visual studio及Git Bush中的日常操作教程,有图有说明,会一直更新本页内容... (Git相对SVN具有更加安全的分布式存储, 分支版本之间切换秒级速度, 分支版本强大灵活等特点)

    >安装命令行和TortoiseGit UI程序. <git bash的安装> https://git-scm.com/downloads <windows可视化工具 Torto ...

  10. [机器学习] PCA (主成分分析)详解

    转载于https://my.oschina.net/gujianhan/blog/225241 一.简介 PCA(Principal Components Analysis)即主成分分析,是图像处理中 ...