用ChatGPT,绘制一个账号系统的C4架构图

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 --> ThirdPartyS
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值