建筑.md (2021)
Architecture.md (2021)

原始链接: https://matklad.github.io/2021/02/06/ARCHITECTURE.md.html

在软件开发中,特别是对于开源项目,拥有架构文档可以显着提高不熟悉项目代码库的贡献者的效率。 本文档提供了项目总体设计和布局的高级视图,可帮助新手浏览代码,而无需花费太多时间来确定应在何处实施特定更改。 目的是对系统的主要组件、关系和关键原理进行简洁而全面的描述。 通过避免过多的细节,而只关注最关键的内容,可以减少由于更改代码元素而变得过时或矛盾的可能性。 为了确保有效的沟通,请避免用技术术语或冗长的解释让读者负担过重。 尽可能使用清晰的语言和视觉辅助工具(例如图表或流程图)来增强理解。 此外,明确提供架构不变量,使开发人员能够理解管理其设计选择的固有约束。 总体而言,预先投入精力起草架构文件可以在减少学习曲线、改善协作和增强可扩展性潜力方面产生巨大的好处。 rust-analyzer 存储库中的 architecure.md 等示例可以作为在您自己的开源项目中实现有效架构描述的优秀指南。

本文讨论了有关管理项目架构的各个方面,包括维护文档、设计架构图表、识别主要组件以及描述系统的物理架构。 然而,它强调,主要目标是呈现架构的清晰性和简单性,这包括保持文档简洁、避免不必要的术语以及在可行的情况下降低复杂性。 此外,它还强调了确保每个人都了解如何浏览代码库并知道关键功能所在的重要性。 最终,建议的目标是提供简短、清晰且易于理解的文档。
相关文章

原文

If you maintain an open-source project in the range of 10k-200k lines of code, I strongly encourage you to add an ARCHITECTURE document next to README and CONTRIBUTING. Before going into the details of why and how, I want to emphasize that this is not another docs are good, write more docs advice. I am pretty sloppy about documentation, and, e.g., I often use just simplify as a commit message. Nonetheless, I feel strongly about the issue, even to the point of pestering you :-)

I have experience with both contributing to and maintaining open-source projects. One of the lessons Ive learned is that the biggest difference between an occasional contributor and a core developer lies in the knowledge about the physical architecture of the project. Roughly, it takes 2x more time to write a patch if you are unfamiliar with the project, but it takes 10x more time to figure out where you should change the code. This difference might be hard to perceive if youve been working with the project for a while. If I am new to a code base, I read each file as a sequence of logical chunks specified in some pseudo-random order. If Ive made significant contributions before, the perception is quite different. I have a mental map of the code in my head, so I no longer read sequentially. Instead, I just jump to where the thing should be, and, if it is not there, I move it. Ones mental map is the source of truth.

I find the ARCHITECTURE file to be a low-effort high-leverage way to bridge this gap. As the name suggests, this file should describe the high-level architecture of the project. Keep it short: every recurring contributor will have to read it. Additionally, the shorter it is, the less likely it will be invalidated by some future change. This is the main rule of thumb for ARCHITECTURE only specify things that are unlikely to frequently change. Dont try to keep it synchronized with code. Instead, revisit it a couple of times a year.

Start with a birds eye overview of the problem being solved. Then, specify a more-or-less detailed codemap. Describe coarse-grained modules and how they relate to each other. The codemap should answer wheres the thing that does X?. It should also answer what does the thing that I am looking at do?. Avoid going into details of how each module works, pull this into separate documents or (better) inline documentation. A codemap is a map of a country, not an atlas of maps of its states. Use this as a chance to reflect on the project structure. Are the things you want to put near each other in the codemap adjacent when you run tree .?

Do name important files, modules, and types. Do not directly link them (links go stale). Instead, encourage the reader to use symbol search to find the mentioned entities by name. This doesnt require maintenance and will help to discover related, similarly named things.

Explicitly call-out architectural invariants. Often, important invariants are expressed as an absence of something, and its pretty hard to divine that from reading the code. Think about a common example from web development: nothing in the model layer specifically doesnt depend on the views.

Point out boundaries between layers and systems as well. A boundary implicitly contains information about the implementation of the system behind it. It even constrains all possible implementations. But finding a boundary by just randomly looking at the code is hard good boundaries have measure zero.

After finishing the codemap, add a separate section on cross-cutting concerns.

A good example of ARCHITECTURE document is this one from rust-analyzer: architecture.md.

联系我们 contact @ memedata.com