软件架构中的生成式AI:不要取代你的架构师! -- 知识铺
[
](https://.com/@ckarthik17?source=post_page—–cde0c5d462c5——————————–)[
](https://.com/inspiredbrilliance?source=post_page—–cde0c5d462c5——————————–)
如何在软件开发中利用生成式 AI
引言本文是探讨如何在软件开发生命周期中应用生成式 AI 的系列文章之一。我们将聚焦于软件架构阶段,特别是如何利用 GPT 等生成式 AI 技术来辅助软件架构师的工作。
软件架构师的角色软件架构师是软件开发中的关键角色,通常由不同职称的工程师担任,如软件架构师、首席工程师、高级工程师等。在本文中,我们将这些角色统一称为“软件架构师”。
主要职责- 技术栈选择:确定适合项目的编程语言、框架、平台和数据库。- 决策制定:为设计模式、编码标准和部署策略做出技术决策。- 系统设计:构建与业务目标一致的软件系统架构。- 跨功能需求集成:将安全性、可扩展性、性能和可靠性等需求整合到设计中。- 风险管理:识别并减轻系统潜在风险。- 团队指导:确保开发团队遵循架构和编码标准。- 利益相关者沟通:作为技术与非技术利益相关者之间的桥梁。- 文档维护:编写和更新技术文档,如设计规范和架构图。
生成式 AI 的辅助作用生成式 AI 如何帮助软件架构师更高效地履行职责?
技术栈选择生成式 AI 可以在选择技术栈时提供帮助,根据项目需求推荐技术和替代方案。
例如,可以利用生成式 AI 来列举一个综合技术栈,包括前端、后端、基础设施、安全工具和 CI/CD 管道。
实践案例虽然没有直接使用 ChatGPT,但通过 Python 调用 OpenAI 的 API,可以更有效地进行提示和交互。想要了解更多关于这种方法的信息,可以参考 ChatGPT Prompt Engineering for Developers 课程。
结语生成式 AI 为软件架构师提供了强大的工具,以支持他们在软件开发过程中做出更加明智的决策。通过利用这些技术,可以提升效率,优化架构设计,并最终推动项目成功。
<span id="e515" data-selectable-paragraph="">import openai
import os
from dotenv import load_dotenv, find_dotenv
_ = load_dotenv(find_dotenv())
openai.api_key = os.getenv('OPENAI_API_KEY')
def get_completion(prompt, model="gpt-3.5-turbo"):
messages = [{"role": "user", "content": prompt}]
response = openai.ChatCompletion.create(
model=model,
messages=messages,
temperature=0
)
return response.choices[0].message["content"]
<span id="879f" data-selectable-paragraph="">tech_stack_prompt = """
Your role is to act as a Software Architect assistant.
Requirements that needs to be met:
- Ecosystem: Node.js
- Cloud Provider: AWS
- Use a typed language
- Backend should be a RESTful API
- Use managed services provided by the cloud provider
- Use managed relational database provided by the cloud provider
- Prefer open source tools
- Do not suggest serverless functions such as AWS Lambda
- Prefer npm over yarn
Please suggest the below:
- Frontend Tech stack
- Programming language
- Framework
- Build tool
- Code coverage tool
- Dependency management
- Dependency vulnerability scanning
- Static code analysis
- Unit testing
- UI testing
- Backend API Tech stack
- Programming language
- Framework
- Build tool
- Code coverage tool
- Static code analysis
- Dependency management
- Dependency vulnerability scanning
- Unit testing
- API testing framework
- API documentation
- Database
- Secret management
- Security
- Container scanning tool
- Static Application Security Testing (SAST) tool
- Dynamic Application Security Testing (DAST) tool
- Penetration testing tool
- Infrastructure
- Infrastructure as code
- Security compliance scanning
- Logging
- Monitoring
- CI/CD tool
For each of the above, please provide in the below format:
<tool name>
Description: <short description>
Reason to choose: <reason> Pls note <reason> must not include generic words like popular or widely used or large community
Alternatives: <alternatives>. <provide the reasons to not choose them. Must not contain the reason that it lack some of the advanced features>.
Output must be in markdown syntax with proper newlines and indentation that can be directly copied to a markdown file.
"""
response = get_completion(tech_stack_prompt)
print(response)
技术堆栈建议概述
本文档提供了一份详细的技术堆栈建议,旨在为架构师在AWS云平台上部署Node.js环境时提供便利。该建议具有高度的可重用性,能够显著提升开发效率。
1. 技术堆栈定制性虽然本建议主要针对AWS和Node.js环境,但可以根据不同的云服务提供商和生态系统需求进行定制。
2. 架构师的便利通过使用这些建议,架构师可以快速地构建和部署应用,而无需从头开始设计技术方案。
3. 建议内容- 云服务提供商:AWS- 应用框架:Node.js- 部署建议:包括但不限于服务选择、安全配置、性能优化等
4. 可重用性这些建议可以在整个组织中共享和重用,有助于统一技术标准和减少重复工作。
5. 定制化示例如需针对其他云服务提供商或不同技术栈进行定制,可以参照以下步骤:- 确定目标云服务提供商- 选择适合的技术栈- 调整安全和性能配置以满足特定需求
结语通过遵循本文档的建议,组织能够构建一个高效、可扩展且安全的Node.js应用环境。
<span id="8264" data-selectable-paragraph="">## Frontend Tech stack
### Programming language
TypeScript
**Description:** TypeScript is a typed superset of JavaScript that compiles to plain JavaScript.
**Reason to choose:** TypeScript provides type checking, which helps catch errors at compile time rather than runtime. This leads to more stable and maintainable code.
**Alternatives:** JavaScript. JavaScript lacks type checking, which can lead to errors at runtime.
### Framework
React
**Description:** React is a popular JavaScript library for building user interfaces.
**Reason to choose:** React has a large and active community, which means there are many resources and plugins available. It also has a virtual DOM, which makes it fast and efficient.
**Alternatives:** Vue.js, Angular. Vue.js is a newer framework with a smaller community. Angular is a more complex framework that can be difficult to learn.
### Build tool
Webpack
**Description:** Webpack is a module bundler for JavaScript applications.
**Reason to choose:** Webpack is highly configurable and can handle a wide range of tasks, such as bundling, minification, and code splitting. It also has a large and active community.
**Alternatives:** Parcel, Rollup. Parcel is a simpler build tool that is easier to set up, but it lacks some of the advanced features of Webpack. Rollup is a more specialized build tool that is designed for libraries rather than applications.
### Code coverage tool
Istanbul
**Description:** Istanbul is a code coverage tool for JavaScript applications.
**Reason to choose:** Istanbul is widely used and has good integration with other tools, such as Jest. It also has a large and active community.
**Alternatives:** nyc. nyc is a similar tool to Istanbul, but it is less widely used.
...
...
技术决策:
生成式 AI 可以通过提供一系列选项来支持建筑师。例如,在我们的实验中,我们使用此提示来确定 AWS 上React.js前端的各种部署策略。
<span id="1948" data-selectable-paragraph="">deployment_options_prompt = """
What are the different ways to deploy the frontend react js application to AWS
- Suggest at least 3 ways
- For each way, provide the pros and cons
Suggest the best way among the 3 for the below requirements
- For a small team of 3 developers
- For faster deployment using AWS CloudFormation
- Lower cost
- Used by up to 1000 users
- Around 100 concurrent users
Output should be in markdown syntax with proper newlines and indentation that can be directly copied to a markdown file.
"""
response = get_completion(deployment_options_prompt)
print(response)
GPT 为这些选项提供了相应的优缺点和推荐的方法。
<span id="f9c0" data-selectable-paragraph="">## Deploying React JS Application to AWS
There are several ways to deploy a React JS application to AWS. Here are three ways with their pros and cons:
### 1. Deploying to Amazon S3
#### Pros:
- Easy to set up and deploy
- Low cost
- Good for static websites
#### Cons:
- Limited functionality
- Not suitable for dynamic websites
### 2. Deploying to AWS Elastic Beanstalk
#### Pros:
- Easy to deploy and manage
- Supports multiple languages and frameworks
- Auto-scaling and load balancing
#### Cons:
- Higher cost than S3
- Limited control over infrastructure
### 3. Deploying to AWS EC2
#### Pros:
- Full control over infrastructure
- Can handle complex applications
- Can be cost-effective for larger applications
#### Cons:
- More complex to set up and manage
- Requires more technical expertise
- Higher cost than S3 and Elastic Beanstalk
### Best Way for the Given Requirements
Based on the requirements, the best way to deploy the React JS application to AWS would be to use AWS Elastic Beanstalk. It is easy to deploy and manage, supports auto-scaling and load balancing, and is cost-effective for a small team of 3 developers. It can handle up to 1000 users and around 100 concurrent users. Additionally, it can be accessed from anywhere in the world, making it suitable for a team working from different locations. Finally, AWS CloudFormation can be used to automate the deployment process, making it faster and more efficient.
系统设计概述
大型语言模型,如GPT,是在众多架构实践的基础上训练而成的。它们能够根据特定项目的需求,提供合适的系统设计建议。这不仅显著减少了在技术解决方案设计上的投入时间,还为设计者提供了一个基础的启动蓝图。
系统设计的优势
- 时间效率:通过自动化设计建议,大幅减少设计时间。2. 基础蓝图:为设计者提供快速启动的设计基础。
应用实例:使用DiagramGPT生成部署图
生成式人工智能可以通过精准的提示,加速创建部署图的流程。以下是我们在实验中使用的提示示例,以利用DiagramGPT生成部署图。
- 提示示例:输入具体的项目需求,以生成初步的系统架构图。- 生成过程:尽管初步设计可能不是最优或最精确的,但它为进一步的细化提供了一个快速的起点。
注意事项
- DiagramGPT 提供了四种类型的图表生成:流程图、实体关系图、云架构图和序列图。- 编辑功能:生成的图表可以在 Eraser 中使用其图表即代码的语法进行编辑。- 数据隐私:Eraser 不会使用用户数据来训练 AI 模型,但可能会分析使用情况以改进 AI 功能。
未来展望
Eraser 团队正在不断改进 DiagramGPT 的准确性和布局定制化。如果有任何特定的改进建议或需求,欢迎通过 hello@tryeraser.com 与我们联系。
图标和徽标
.svg)
<span id="9ece" data-selectable-paragraph="">Please provide deployment diagram with all the below items
- React application deployed to s3 and exposed via cloudfront
- Backend nodejs service deployed using Elastic Beanstalk and communicate with AWS relation database
- Backend REST API exposed via API Gateway
- Cloudfront routing to s3 or api gateway based on path
- Route 53 in front of cloudfront
- Show the users accessing the route 53 from internet
- All Components should be inside the AWS Cloud
- Arrows to represent the network flow between the components
自动部署图生成指南
1. 跨职能需求的重要性生成式AI在架构设计中扮演着重要角色,它通过提供洞察力和建议来辅助架构师,尤其是对于经验较少或新接触系统设计的初级架构师。跨职能需求常常被忽略,但它们对于确保架构设计的全面性和有效性至关重要。
2. 架构设计中的跨职能需求- 识别关键需求:在设计初期,识别并理解所有相关的需求,包括技术、业务和用户需求。- 设计思维:采用设计思维方法,确保解决方案能够满足不同利益相关者的需求。- 沟通与协作:架构师需要与团队成员进行有效沟通,并与跨职能团队协作,以确保需求得到满足。
3. 使用生成式AI的提示为了帮助架构师更好地导航跨职能需求,以下是一些有用的提示:
- 定义问题:明确定义问题的范围和目标,以便AI可以提供更精确的建议。- 利用AI的见解:利用AI提供的见解来识别潜在的设计缺陷或改进机会。- 迭代改进:根据AI的建议进行迭代设计,以逐步完善架构解决方案。
4. 结构化内容的创建在创建内容时,保持条理性与结构性至关重要。以下是一些基本的步骤:
- 确定主题:明确内容的主题和目标受众。- 组织结构:使用标题和子标题来组织内容,使其易于阅读和理解。- 逻辑顺序:确保内容按照逻辑顺序排列,以便读者能够顺畅地跟随思路。- 使用列表和项目符号:使用列表和项目符号来突出关键点和步骤。
5. 持续改进架构设计是一个持续的过程,需要不断地回顾和改进。生成式AI可以在这个过程中提供持续的支持和建议。
6. 结论通过结合生成式AI的能力和架构师的专业知识,可以创建出既满足跨职能需求又具有创新性的架构设计。
<span id="c88b" data-selectable-paragraph="">cross_functional_prompt = """
List all the cross-functional requirements (At least 15) that need to be followed in the overall system architecture
Information about the System architecture:
- Nodejs backend deployed in AWS Elastic Beanstalk
- React frontend deployed in AWS S3
- AWS RDS MySQL database
Each cross-functional requirement should be in the below format:
<requirement name>:
Description: <Description of the requirement in detail>
Best Practices: List of practices to follow to meet the requirement
Example: List multiple examples of how the requirement is met
Tools: List the tools that can be used to meet the requirement
The output must be in markdown syntax with proper new lines and indentation that can be directly copied to a markdown file
"""
response = get_completion(cross_functional_prompt)
print(response)
GPT 能够通过工具和示例就各种跨职能需求提出详细的建议。部分输出如下:
<span id="b590" data-selectable-paragraph="">## Cross-Functional Requirements
-----------------
### Scalability:
Description: The system should be able to handle an increase in load without affecting performance.
Best Practices:
- Use horizontal scaling by adding more instances of the application.
- Use load balancers to distribute traffic evenly.
- Use caching to reduce the load on the database.
Example:
- Use AWS Elastic Beanstalk to automatically scale the application based on traffic.
- Use AWS Auto Scaling to add or remove instances based on CPU utilization.
Tools:
- AWS Elastic Beanstalk
- AWS Auto Scaling
-----------------
### Security:
Description: The system should be secure and protect against unauthorized access.
Best Practices:
- Use HTTPS for all communication.
- Use encryption for sensitive data.
- Use strong passwords and two-factor authentication.
Example:
- Use AWS Certificate Manager to obtain SSL/TLS certificates for HTTPS.
- Use AWS Key Management Service to encrypt and decrypt sensitive data.
Tools:
- AWS Certificate Manager
- AWS Key Management Service
-----------------
### Performance:
Description: The system should be performant and respond quickly to user requests.
Best Practices:
- Use caching to reduce the load on the database.
- Use CDNs to serve static assets.
- Use compression to reduce the size of responses.
Example:
- Use AWS ElastiCache to cache frequently accessed data.
- Use AWS CloudFront to serve static assets.
Tools:
- AWS ElastiCache
- AWS CloudFront
-----------------
### Monitoring:
...
### Availability:
...
### Reliability:
...
### Maintainability:
...
### Cost:
...
### Compliance:
...
### Disaster Recovery:
...
### Collaboration:
...
### Documentation:
...
### Performance Optimization:
...
### Accessibility:
...
生成式人工智能(AI)在扮演软件架构师的角色时,需要考虑以下几个关键因素:
1. 设计细节的局限性当前技术阶段的生成式AI能够提供高层次的设计蓝图,但缺乏深入细节的处理能力。这限制了AI在进行精细架构决策时的应用。
2. 实验项目案例在我们的实验项目中,AI在面对设计系统的业务需求时,生成了以下基本大纲:- 系统目标和业务需求- 初步架构设计- 技术选型和框架
3. 技术设计元素的提示为了实现一个全面且定制化的建筑解决方案,需要对每个技术设计元素进行详细的提示和指导。
4. 架构决策的深度AI生成的大纲需要进一步细化,包括但不限于:- 数据流和处理逻辑- 安全性和合规性考量- 性能优化策略- 可扩展性和可维护性设计
5. 结论尽管生成式AI在提供初步设计方面具有潜力,但要成为成熟的软件架构师,仍需人类专家的深入参与和细致打磨。
人工智能在软件架构中的局限性
1. 复杂性重载随着对问题细节的深入了解,人工智能可能会过度增加解决方案的复杂性。例如,它可能推荐一个包含无服务器功能的复杂分布式架构,而实际上,一个简单的单体设计可能更为高效。
2. 潜在的安全风险使用生成式人工智能在软件架构中可能带来安全挑战。人工智能可能无法充分考虑到保护API端点、执行数据加密或部署网络安全措施等关键方面,从而暴露潜在的安全盲点。
3. 受限制的创造力人工智能的创新能力受限于其训练数据的范围和多样性。面对需要前沿技术解决方案的任务时,它可能难以提供创新的方案,因为它可能没有接受过足够广泛的领域数据训练。
4. 忽视团队和文化因素生成式人工智能在提出架构建议时可能会忽略团队的动态和组织文化。它可能提出一个技术上可行但与团队能力或组织目标不一致的复杂解决方案。
5. 建筑师的工具,而不是替代品尽管生成式人工智能是一个宝贵的工具,但它尚未准备好取代人类建筑师。机器的决策能力依赖于其训练数据,无法完全理解复杂的商业环境或预见挑战,也无法提供人类架构师所能提供的创造力和创新。
6. 决策能力的限制软件架构中的决策往往需要主观判断、商业直觉和个人责任感,这些是人工智能目前所不具备的。因此,人工智能应被视为建筑师的工具,而非替代品。
7. 人工智能与建筑师的合作在可预见的未来,人工智能将成为建筑师工具箱中的重要组成部分,但必须与建筑师紧密合作。通过建筑师的引导,人工智能可以更好地满足软件架构的需求,实现有效和创新的解决方案。
- 原文作者:知识铺
- 原文链接:https://index.zshipu.com/geek001/post/20240730/%E8%BD%AF%E4%BB%B6%E6%9E%B6%E6%9E%84%E4%B8%AD%E7%9A%84%E7%94%9F%E6%88%90%E5%BC%8FAI%E4%B8%8D%E8%A6%81%E5%8F%96%E4%BB%A3%E4%BD%A0%E7%9A%84%E6%9E%B6%E6%9E%84%E5%B8%88--%E7%9F%A5%E8%AF%86%E9%93%BA/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。
- 免责声明:本页面内容均来源于站内编辑发布,部分信息来源互联网,并不意味着本站赞同其观点或者证实其内容的真实性,如涉及版权等问题,请立即联系客服进行更改或删除,保证您的合法权益。转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。也可以邮件至 sblig@126.com