让AI快速理解你的项目架构:介绍一下在X上非常流行的ARCHITECTURE.md

为什么需要这份AI”宪法”?

在我使用AI协助开发的过程中,我发现它总是在”重新理解”我的项目。每次对话都像从零开始,导致代码风格不一致,架构理解偏差,甚至出现”vibe coding”——AI凭感觉写代码,完全无视我的项目规范。

直到我发现了这个在X上非常流行的ARCHITECTURE.md模板,它完美解决了我的问题。我把它理解为给AI的一份 「项目”宪法”和”守则”」,确保每次编码都有统一的架构理解基础,让我彻底告别重复解释和”无法无天”的随意编码。

模板结构

我发现这个模板通过11个关键章节构建了完整的架构认知框架:从项目结构规划到系统组件设计,从数据存储策略到部署安全考虑,再到开发环境配置和未来规划方向,每一部分都帮助AI准确理解我的项目的技术边界和设计原则。

实践经验

我总结出使用这个模板的关键在于每次编码前都喂给AI完整的架构文档。这样AI就能基于对我项目的全面理解来进行功能设计和代码实现,而不是在每次对话中重新摸索项目结构。最重要的是,我认识到这个模板需要持续维护。随着我的项目架构演进,我必须同步更新文档,确保AI始终基于最新的项目信息来工作。通过这种方式,我的AI助手真正从”临时工”变成了了解我项目架构、遵循规章制度的”正式员工”,为我产出高质量的代码。


原文链接https://architecture.md/ - 这是该架构文档模板的官方来源。

英文原版

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
# Architecture Overview
This document serves as a critical, living template designed to equip agents with a rapid and comprehensive understanding of the codebase's architecture, enabling efficient navigation and effective contribution from day one. Update this document as the codebase evolves.

## 1. Project Structure
This section provides a high-level overview of the project's directory and file structure, categorised by architectural layer or major functional area. It is essential for quickly navigating the codebase, locating relevant files, and understanding the overall organization and separation of concerns.


[Project Root]/
├── backend/ # Contains all server-side code and APIs
│ ├── src/ # Main source code for backend services
│ │ ├── api/ # API endpoints and controllers
│ │ ├── client/ # Business logic and service implementations
│ │ ├── models/ # Database models/schemas
│ │ └── utils/ # Backend utility functions
│ ├── config/ # Backend configuration files
│ ├── tests/ # Backend unit and integration tests
│ └── Dockerfile # Dockerfile for backend deployment
├── frontend/ # Contains all client-side code for user interfaces
│ ├── src/ # Main source code for frontend applications
│ │ ├── components/ # Reusable UI components
│ │ ├── pages/ # Application pages/views
│ │ ├── assets/ # Images, fonts, and other static assets
│ │ ├── services/ # Frontend services for API interaction
│ │ └── store/ # State management (e.g., Redux, Vuex, Context API)
│ ├── public/ # Publicly accessible assets (e.g., index.html)
│ ├── tests/ # Frontend unit and E2E tests
│ └── package.json # Frontend dependencies and scripts
├── common/ # Shared code, types, and utilities used by both frontend and backend
│ ├── types/ # Shared TypeScript/interface definitions
│ └── utils/ # General utility functions
├── docs/ # Project documentation (e.g., API docs, setup guides)
├── scripts/ # Automation scripts (e.g., deployment, data seeding)
├── .github/ # GitHub Actions or other CI/CD configurations
├── .gitignore # Specifies intentionally untracked files to ignore
├── README.md # Project overview and quick start guide
└── ARCHITECTURE.md # This document



## 2. High-Level System Diagram
Provide a simple block diagram (e.g., a C4 Model Level 1: System Context diagram, or a basic component diagram) or a clear text-based description of the major components and their interactions. Focus on how data flows, services communicate, and key architectural boundaries.

[User] <--> [Frontend Application] <--> [Backend Service 1] <--> [Database 1]
|
+--> [Backend Service 2] <--> [External API]

## 3. Core Components
(List and briefly describe the main components of the system. For each, include its primary responsibility and key technologies used.)

### 3.1. Frontend

Name: [e.g., Web App, Mobile App]

Description: Briefly describe its primary purpose, key functionalities, and how users or other systems interact with it. E.g., 'The main user interface for interacting with the system, allowing users to manage their profiles, view data dashboards, and initiate workflows.'

Technologies: [e.g., React, Next.js, Vue.js, Swift/Kotlin, HTML/CSS/JS]

Deployment: [e.g., Vercel, Netlify, S3/CloudFront]

### 3.2. Backend Services

(Repeat for each significant backend service. Add more as needed.)

#### 3.2.1. [Service Name 1]

Name: [e.g., User Management Service, Data Processing API]

Description: [Briefly describe its purpose, e.g., "Handles user authentication and profile management."]

Technologies: [e.g., Node.js (Express), Python (Django/Flask), Java (Spring Boot), Go]

Deployment: [e.g., AWS EC2, Kubernetes, Serverless (Lambda/Cloud Functions)]

#### 3.2.2. [Service Name 2]

Name: [e.g., Analytics Service, Notification Service]

Description: [Briefly describe its purpose.]

Technologies: [e.g., Python, Kafka, Redis]

Deployment: [e.g., AWS ECS, Google Cloud Run]

## 4. Data Stores

(List and describe the databases and other persistent storage solutions used.)

### 4.1. [Data Store Type 1]

Name: [e.g., Primary User Database, Analytics Data Warehouse]

Type: [e.g., PostgreSQL, MongoDB, Redis, S3, Firestore]

Purpose: [Briefly describe what data it stores and why.]

Key Schemas/Collections: [List important tables/collections, e.g., users, products, orders (no need for full schema, just names)]

### 4.2. [Data Store Type 2]

Name: [e.g., Cache, Message Queue]

Type: [e.g., Redis, Kafka, RabbitMQ]

Purpose: [Briefly describe its purpose, e.g., "Used for caching frequently accessed data" or "Inter-service communication."]

## 5. External Integrations / APIs

(List any third-party services or external APIs the system interacts with.)

Service Name 1: [e.g., Stripe, SendGrid, Google Maps API]

Purpose: [Briefly describe its function, e.g., "Payment processing."]

Integration Method: [e.g., REST API, SDK]

## 6. Deployment & Infrastructure

Cloud Provider: [e.g., AWS, GCP, Azure, On-premise]

Key Services Used: [e.g., EC2, Lambda, S3, RDS, Kubernetes, Cloud Functions, App Engine]

CI/CD Pipeline: [e.g., GitHub Actions, GitLab CI, Jenkins, CircleCI]

Monitoring & Logging: [e.g., Prometheus, Grafana, CloudWatch, Stackdriver, ELK Stack]

## 7. Security Considerations

(Highlight any critical security aspects, authentication mechanisms, or data encryption practices.)

Authentication: [e.g., OAuth2, JWT, API Keys]

Authorization: [e.g., RBAC, ACLs]

Data Encryption: [e.g., TLS in transit, AES-256 at rest]

Key Security Tools/Practices: [e.g., WAF, regular security audits]

## 8. Development & Testing Environment

Local Setup Instructions: [Link to CONTRIBUTING.md or brief steps]

Testing Frameworks: [e.g., Jest, Pytest, JUnit]

Code Quality Tools: [e.g., ESLint, Black, SonarQube]

## 9. Future Considerations / Roadmap

(Briefly note any known architectural debts, planned major changes, or significant future features that might impact the architecture.)

[e.g., "Migrate from monolith to microservices."]

[e.g., "Implement event-driven architecture for real-time updates."]

## 10. Project Identification

Project Name: [Insert Project Name]

Repository URL: [Insert Repository URL]

Primary Contact/Team: [Insert Lead Developer/Team Name]

Date of Last Update: [YYYY-MM-DD]

## 11. Glossary / Acronyms

Define any project-specific terms or acronyms.)

[Acronym]: [Full Definition]

[Term]: [Explanation]

中文版本(推荐使用)

为了方便中文团队使用,我特别准备了完整的中文翻译版本:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# 架构总览

本文档是一个关键的、活跃的模板,旨在帮助AI代理快速全面地了解代码库架构,使其从第一天开始就能高效导航并有效贡献。随着代码库的演进,请及时更新本文档。

## 1. 项目结构

本节提供项目目录和文件结构的高层概览,按架构层或主要功能区域分类。对于快速导航代码库、定位相关文件以及理解整体组织结构和关注点分离至关重要。

[项目根目录]/
├── backend/ # 包含所有服务端代码和API
│ ├── src/ # 后端服务的主要源代码
│ │ ├── api/ # API端点和控制器
│ │ ├── client/ # 业务逻辑和服务实现
│ │ ├── models/ # 数据库模型/模式
│ │ └── utils/ # 后端工具函数
│ ├── config/ # 后端配置文件
│ ├── tests/ # 后端单元和集成测试
│ └── Dockerfile # 后端部署的Dockerfile
├── frontend/ # 包含用户界面的所有客户端代码
│ ├── src/ # 前端应用的主要源代码
│ │ ├── components/ # 可重用的UI组件
│ │ ├── pages/ # 应用页面/视图
│ │ ├── assets/ # 图片、字体和其他静态资源
│ │ ├── services/ # 用于API交互的前端服务
│ │ └── store/ # 状态管理(例如:Redux、Vuex、Context API)
│ ├── public/ # 公开访问的资源(例如:index.html)
│ ├── tests/ # 前端单元和端到端测试
│ └── package.json # 前端依赖和脚本
├── common/ # 前端和后端都使用的共享代码、类型和工具
│ ├── types/ # 共享的TypeScript/接口定义
│ └── utils/ # 通用工具函数
├── docs/ # 项目文档(例如:API文档、设置指南)
├── scripts/ # 自动化脚本(例如:部署、数据填充)
├── .github/ # GitHub Actions或其他CI/CD配置
├── .gitignore # 指定要忽略的故意不跟踪的文件
├── README.md # 项目概览和快速入门指南
└── ARCHITECTURE.md # 本文档

## 2. 高层系统图

提供简单的块状图(例如:C4模型1级:系统上下文图,或基本组件图)或主要组件及其交互的清晰基于文本的描述。重点关注数据流、服务通信和关键架构边界。

[用户] <--> [前端应用] <--> [后端服务1] <--> [数据库1]
|
+--> [后端服务2] <--> [外部API]

## 3. 核心组件

(列出并简要描述系统的主要组件。对于每个组件,包括其主要职责和使用的关键技术。)

### 3.1. 前端

名称:[例如:Web应用、移动应用]

描述:简要描述其主要目的、关键功能,以及用户或其他系统如何与之交互。例如:"与系统交互的主要用户界面,允许用户管理个人资料、查看数据仪表板并启动工作流。"

技术:[例如:React、Next.js、Vue.js、Swift/Kotlin、HTML/CSS/JS]

部署:[例如:Vercel、Netlify、S3/CloudFront]

### 3.2. 后端服务

(对每个重要的后端服务重复。根据需要添加更多。)

#### 3.2.1. [服务名称1]

名称:[例如:用户管理服务、数据处理API]

描述:[简要描述其目的,例如:"处理用户身份验证和个人资料管理。"]

技术:[例如:Node.js (Express)、Python (Django/Flask)、Java (Spring Boot)、Go]

部署:[例如:AWS EC2、Kubernetes、无服务器(Lambda/Cloud Functions)]

#### 3.2.2. [服务名称2]

名称:[例如:分析服务、通知服务]

描述:[简要描述其目的。]

技术:[例如:Python、Kafka、Redis]

部署:[例如:AWS ECS、Google Cloud Run]

## 4. 数据存储

(列出并描述使用的数据库和其他持久化存储解决方案。)

### 4.1. [数据存储类型1]

名称:[例如:主用户数据库、分析数据仓库]

类型:[例如:PostgreSQL、MongoDB、Redis、S3、Firestore]

目的:[简要描述它存储什么数据以及为什么。]

关键模式/集合:[列出重要的表/集合,例如:users、products、orders(无需完整模式,只需名称)]

### 4.2. [数据存储类型2]

名称:[例如:缓存、消息队列]

类型:[例如:Redis、Kafka、RabbitMQ]

目的:[简要描述其目的,例如:"用于缓存频繁访问的数据"或"服务间通信。"]

## 5. 外部集成/API

(列出系统与之交互的任何第三方服务或外部API。)

服务名称1:[例如:Stripe、SendGrid、Google Maps API]

目的:[简要描述其功能,例如:"支付处理。"]

集成方法:[例如:REST API、SDK]

## 6. 部署和基础设施

云提供商:[例如:AWS、GCP、Azure、本地]

使用的关键服务:[例如:EC2、Lambda、S3、RDS、Kubernetes、Cloud Functions、App Engine]

CI/CD流水线:[例如:GitHub Actions、GitLab CI、Jenkins、CircleCI]

监控和日志:[例如:Prometheus、Grafana、CloudWatch、Stackdriver、ELK Stack]

## 7. 安全考虑

(突出任何关键安全方面、身份验证机制或数据加密实践。)

身份验证:[例如:OAuth2、JWT、API密钥]

授权:[例如:RBAC、ACL]

数据加密:[例如:传输中的TLS、静态AES-256]

关键安全工具/实践:[例如:WAF、定期安全审计]

## 8. 开发和测试环境

本地设置说明:[链接到CONTRIBUTING.md或简要步骤]

测试框架:[例如:Jest、Pytest、JUnit]

代码质量工具:[例如:ESLint、Black、SonarQube]

## 9. 未来考虑/路线图

(简要说明任何已知的架构债务、计划的重大变更或可能影响架构的重要未来功能。)

[例如:"从单体迁移到微服务。"]

[例如:"为实时更新实现事件驱动架构。"]

## 10. 项目标识

项目名称:[插入项目名称]

仓库URL:[插入仓库URL]

主要联系人/团队:[插入首席开发人员/团队名称]

最后更新日期:[YYYY-MM-DD]

## 11. 术语表/缩写

定义任何项目特定的术语或缩写。

[缩写]:[完整定义]

[术语]:[解释]

让AI快速理解你的项目架构:介绍一下在X上非常流行的ARCHITECTURE.md

https://yelihu.github.io/2025/10/08/让AI快速理解你的项目架构:介绍一下在X上非常流行的ARCHITECTURE.md/

作者

Ye Lihu

发布于

2025-10-08

更新于

2025-10-11

许可协议