垂直代码库

Apr 13, 2026 — , ,

Apr 13, 2026 — , ,

The Vertical Codebase

Photo by Darryl Low

照片由 Darryl Low 提供

I’ve always had opinions about how to “properly” structure a codebase. I think most engineers do. My stance has obviously evolved over time as things changed, but I found a tweet of myself from two years ago that I still 100% agree with:

我一直对如何“正确”结构化一个 codebase 有自己的看法。我认为大多数工程师都是如此。我的立场显然随着时间的推移和事物的变化而演变,但我发现两年前我自己的一条 tweet,我仍然 100% 同意:

[

[

Avatar for TkDodo

Dominik 🔮

Dominik 🛮

@tkdodo

@tkdodo

components / hooks / types / utils (and constants) is the split I’m seeing in many codebases, yet it’s the one I dislike the most. It groups by type, not by domain. “useTheme” will live next to “useTodo”, but not next to ThemeProvider … why?

components / hooks / types / utils (and constants) 是我在许多 codebases 中看到的拆分,但这是我最不喜欢的一种。它按类型分组,而不是按 domain。“useTheme” 会与 “useTodo” 相邻,但不会与 ThemeProvider 相邻……为什么?

Code colocation

- Jan 23, 2024

- Jan 23, 2024

](https://x.com/tkdodo/status/1835035534072447245)

](https://x.com/tkdodo/status/1835035534072447245)

Why indeed? 🤔 The horizontal split has never made sense to me. I guess it’s convenient when you’re starting out, but that’s about it. Most of the things you write will be components anyway, and the other folders might just have a couple of files.

为什么会这样呢? \ud83e\udd14 横向分割对我来说从来就没有意义。我猜它在起步阶段很方便,但仅此而已。你写的大多数东西反正都是 components,其他文件夹可能只有几个文件。

Of course, over time, this becomes a nightmare, and once you have it in place, it’s very hard to get rid of. Once again, the Sentry codebase is a good example. 10+ years of product development with this structure has lead to over 200 files in the top level components directory. What they have in common? That they are components. Nothing else.

当然,随着时间推移,这会变成噩梦,一旦建立起来,就很难摆脱。Sentry代码库再次是一个好例子。用这种结构进行了10+年的产品开发,导致顶级组件目录中有超过200个文件。他们有什么共同点?它们都是components。仅此而已。

From analyticsArea to workflowEngine, you’ll find everything in there. Well actually, you’ll likely find nothing, because you don’t know where to start looking.

analyticsAreaworkflowEngine,你能在那里找到一切。嗯,实际上,你很可能什么都找不到,因为你不知道从哪里开始查找。

If your startup is NGMI No...

开通本站会员,查看完整译文。

首页 - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.1. UTC+08:00, 2026-04-18 18:45
浙ICP备14020137号-1 $访客地图$