2

用ChatGPT,快速设计一个真实的账号系统

 1 year ago
source link: https://www.cnblogs.com/peida/p/17147347.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

用ChatGPT,快速设计一个真实的账号系统

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

用ChatGPT,可以尝试做很多的事情。

今天我们就来让ChatGPT做为架构师,来帮我们设计一个账号系统吧。

我的实验过程记录如下,与你分享。

首先,我们从用户故事开始吧。

提示:我们从用户故事开始,需要设计一个网站的账号系统模型,其中包括账号基础信息实体,邮箱验证实体,手机号验证实体,三方社交绑定实体,密码安全实体,登录记录实体。

ChatGPT反馈为:

image

确认没有问题,就可以将次转化为一个数据模型啦。

提示:OK,将以上设计转化为一个数据模型,并使用markdown表格的形式来描述输出

ChatGPT输出为:

image
image

模型确认后,就可以输出类关系图啦。

我输入的提示为:帮我输出类之间的关系图,用markdown的格式,输出符合Mermaid的脚本代码

ChatGPT反馈为:

classDiagram
    class Account {
        +username: string
        +password: string
        +create_time: datetime
        +update_time: datetime
    }
    class EmailVerification {
        +email: string
        +verification_code: string
        +is_success: boolean
        +create_time: datetime
        +update_time: datetime
    }
    class PhoneVerification {
        +phone_number: string
        +verification_code: string
        +is_success: boolean
        +create_time: datetime
        +update_time: datetime
    }
    class ThirdPartyBinding {
        +third_party_id: string
        +third_party_username: string
        +create_time: datetime
        +update_time: datetime
    }
    class PasswordSecurity {
        +password_security_id: string
        +password_strength: string
        +password_salt: string
        +create_time: datetime
        +update_time: datetime
    }
    class LoginRecord {
        +login_time: datetime
        +login_ip: string
        +create_time: datetime
        +update_time: datetime
    }
    Account "1" --> "0..1" EmailVerification
    Account "1" --> "0..1" PhoneVerification
    Account "1" --> "0..*" ThirdPartyBinding
    Account "1" --> "1" PasswordSecurity
    Account "1" --> "0..*" LoginRecord

以上代码经过markdown渲染后的图片为:

image

增加类属性

此时,发现Account类中缺失了部分需要的属性,那就可以让ChatGPT类增加吧。

提示:Account实体类中,需要增加一个state状态属性,一个email_ver状态属性,一个phone_ver的状态属性,请将变更后的类关系图,用markdown再次输出

新返回的markdown代码经过渲染后的图片为:

image

接下来,我们试一下事务变更的序列图吧。

我输入的提示为:

ChatGPT返回的代码:

sequenceDiagram
    participant PhoneVerification
    participant Account
    participant PhoneVerificationService
    participant SMS
    PhoneVerification ->> PhoneVerificationService: 验证通过,发送信号
    PhoneVerificationService ->> Account: 更新phone_ver属性
    PhoneVerificationService ->> SMS: 发送验证码

经过渲染后的图片为:

image

接下来,我们生产一个状态图看一下吧。

我输入的提示为:Account的state状态有:新注册,已激活,已注销,被锁定等状态,将这些状态在Mermaid脚本中描述出来,用markdown输出状态转换的代码

ChatGPT返回的代码为:

stateDiagram
    [*] --> New: 注册
    New --> Active: 邮箱/手机号验证通过
    Active --> Locked: 多次输入错误密码
    Locked --> Active: 解除锁定
    Active --> Deactivated: 注销
    Deactivated --> Active: 恢复
    Deactivated --> Archived: 数据保留
    Locked --> Archived: 数据保留
    Archived --> [*]: 数据清理

经过渲染后的图片为:

image

今天的实验就到这儿啦。

可见,ChatGPT在软件开发中是一个不错的助手,它一家具有了不错的生产能力,帮我们做很多事情。

只要我们在每一个问答的回合中,能给ChatGPT正确的提示,它就可以很好的配合我们来完成任务,我就可以持续的发起并推动接下来的步骤。

接下来可以继续尝试啦。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK