@QingQ77: 一套从生产代码中提取的、可验证的编程模式参考,每个模式附带交互式可视化、精确到行的源码链接和多语言实现。 https://github.com/Totoro-jam/battle-tested-patterns… Battle-Teste…

X AI KOLs Timeline 工具

摘要

一个从真实生产代码(如React、Linux内核、Go、Redis等)中提取的46个编程模式参考库,每个模式配有交互式可视化、精确到行的源码链接以及TypeScript/Python/Go/Rust四种语言的实现和可运行练习。站点中英文双语,支持搜索和分类浏览。

一套从生产代码中提取的、可验证的编程模式参考,每个模式附带交互式可视化、精确到行的源码链接和多语言实现。 https://github.com/Totoro-jam/battle-tested-patterns… Battle-Tested Patterns 从 React、Linux 内核、Go、Redis、PostgreSQL、Chromium 等真实项目中提取了 46 个编程模式,分数据结构、并发、系统设计、内存管理和行为五大类。每个模式都配了交互可视化、精确到行号的源码链接(不是目录,是具体某一行)、四种语言(TypeScript、Python、Go、Rust)的代码实现和可运行的练习。站点中英文双语,支持搜索和分类浏览。
查看原文
查看缓存全文

缓存时间: 2026/06/15 11:01

一套从生产代码中提取的、可验证的编程模式参考,每个模式附带交互式可视化、精确到行的源码链接和多语言实现。

https://github.com/Totoro-jam/battle-tested-patterns…

Battle-Tested Patterns 从 React、Linux 内核、Go、Redis、PostgreSQL、Chromium 等真实项目中提取了 46 个编程模式,分数据结构、并发、系统设计、内存管理和行为五大类。每个模式都配了交互可视化、精确到行号的源码链接(不是目录,是具体某一行)、四种语言(TypeScript、Python、Go、Rust)的代码实现和可运行的练习。站点中英文双语,支持搜索和分类浏览。


Totoro-jam/battle-tested-patterns

Source: https://github.com/Totoro-jam/battle-tested-patterns

Battle-Tested Patterns

Code-level programming patterns extracted from production codebases.

Interactive visualizations with time-travel playback · Precise source links · Multi-language · Runnable exercises

📖 Documentation · 📖 中文文档

English | 简体中文

CI Deploy License: MIT PRs Welcome

LRU Cache pattern — interactive visualization, property table, and sidebar navigation

46 Patterns at a Glance

🧠 Data Structures

⚡ Concurrency

🏗️ Systems

♻️ Memory

🔄 Behavioral

📊 Proven In

  • React · Linux · Go
  • Redis · PostgreSQL
  • Kafka · Chromium
  • Tokio · Erlang/OTP
  • LevelDB · RocksDB · etcd
  • Nginx · Akka
  • LLVM · Vue · Godot
  • PyTorch · CPython · ZFS

The Gap This Fills

What existsWhat’s missing
Design patterns booksToo abstract, too OOP-centric
Algorithm reposDisconnected from real engineering
System design guidesArchitecture-level, not code-level

This project: code-level techniques from React, Linux, Go, Chromium — each with verifiable source links.

Patterns

PatternWhat It DoesProven In
BitmaskPack N flags into one integer, check any combo in O(1)React Flags · Linux stat.h
Double BufferingSwap two copies atomically, zero allocationReact Fiber · SDL
Cooperative SchedulingYield control between work chunks to stay responsiveReact Scheduler · Go Runtime
Min HeapO(1) peek at highest priority, O(log n) push/popReact MinHeap · Linux CFS
Diff / PatchCompute minimal edits between two sequencesReact Reconciler · Git
Object PoolPre-allocate and reuse to avoid GC pressureGo sync.Pool · Godot
Ring BufferFixed-size circular queue, zero allocationLMAX Disruptor · Linux
State MachineExplicit states, impossible transitions unrepresentableXState · Linux TCP
Copy-on-WriteShare by reference, copy only on mutationGit objects · Rust Cow
ObserverSubscribe to events, decouple producers from consumersNode EventEmitter · Redux
IteratorLazy sequences, zero intermediate allocationsRust Iterator · Python gen
SemaphoreBounded concurrency with a counterLinux · Go x/sync
Batch ProcessingAccumulate ops, execute as groupKafka
Retry with BackoffExponential delay + jitter on failureKubernetes · gRPC
Event LoopSingle-threaded loop multiplexes I/O via epoll/kqueuelibuv · Redis ae
FlyweightShare identical objects, avoid duplicatesPython int cache
Bloom FilterProbabilistic set membership, zero false negativesLevelDB · Chromium
Circuit BreakerStop calling failing services, fail fastHystrix · gobreaker
Arena AllocatorBump-allocate, free all at oncebumpalo · Go arena
B+ TreeHigh-fanout balanced tree — internal nodes guide, leaves store and link for range scansPostgreSQL · SQLite
BackpressureSlow producers when consumers can’t keep upNode.js Streams · Reactive Streams
Write-Ahead LogLog mutations before applying, crash recoveryetcd · PostgreSQL
Logical ClockMonotonic counter orders events without wall-clock timeetcd · LevelDB
LRU CacheEvict least recently used, O(1) get/putgroupcache · Linux
Consistent HashingAdd/remove nodes remaps ~1/n keysgroupcache · HAProxy
TrieO(k) lookup, shared prefixes share nodesLinux FIB · Redis rax
Skip ListProbabilistic O(log n) sorted structureRedis · LevelDB
Rate LimiterToken bucket controls throughputGo rate · Nginx
Reference CountingAtomic counter tracks owners, auto-cleanup at zeroCPython · Rust Arc
RegistryComponents self-register into a global lookup table by nameTensorFlow · gRPC-Go
Work StealingIdle threads steal from busy queuesGo proc.go · Tokio
MVCCTimestamped versions, readers never blockPostgreSQL · etcd
Free ListO(1) alloc/free via linked freed slotsGo mfixalloc · Linux SLUB
Dependency GraphDAG + toposort for execution orderCargo · pnpm
Dirty FlagMark “dirty” on mutation, defer recomputation until neededChromium/Blink · React
Actor ModelPrivate state + mailbox, no locksAkka · Erlang/OTP
Tagged UnionType tag + union for safe dispatchGodot Variant · PyTorch IValue
InterningDeduplicate values, O(1) equalityRust Symbol · CPython
VtableFunction pointer struct for polymorphismLinux file_operations · CPython PyTypeObject
VisitorDispatch callbacks on tree nodesLLVM InstVisitor · Vue transforms
Merkle TreeHash upward to root for integrityGit tree.c · ZFS blkptr
Merge IteratorK-way merge of sorted streamsLevelDB merger · RocksDB merge
Middleware ChainCompose handlers where each wraps the next — bidirectional pipelinegRPC-Go · Koa.js
LSM TreeBuffer writes, flush to sorted filesLevelDB DBImpl · RocksDB MemTable
CheckpointingSnapshot state, recover from checkpointPostgreSQL · Redis RDB
TombstoneMark deleted with a tombstone, background reclaims laterLevelDB · Cassandra

Every “Proven In” link goes to the exact lines in the source code. Not a directory. Not a file. The lines.

What a Pattern Looks Like

Each pattern follows a consistent structure — here’s a taste from Bitmask:

  Bit position:   7    6    5    4    3    2    1    0
                ┌────┬────┬────┬────┬────┬────┬────┬────┐
  Flags:        │    │    │    │ SN │ CB │ RF │ UP │ PL │
                └────┴────┴────┴──┬─┴──┬─┴──┬─┴──┬─┴──┬─┘
                                  │    │    │    │    └── Placement  (1 << 0)
                                  │    │    │    └─────── Update     (1 << 1)
                                  │    │    └──────────── Ref        (1 << 2)
                                  │    └───────────────── Callback   (1 << 3)
                                  └────────────────────── Snapshot   (1 << 4)

Implementations in 4 languages, each idiomatic:

// TypeScript                          // Python
const READ  = 1 << 0;                  READ  = 1 << 0
const WRITE = 1 << 1;                  WRITE = 1 << 1
const perms = READ | WRITE;            perms = READ | WRITE
(perms & READ) !== 0;  // true         bool(perms & READ)  # True

Then exercises at 2 difficulty levels — all with tests you can run.

What’s Inside

FeatureDetails
46 patternsBitmask, LRU Cache, MVCC, Work Stealing, Actor Model, and 41 more
46 interactive visualizationsHands-on SVG visualizations — click, drag, experiment, then undo or replay any step with the time-travel playback bar
93 TS exercises + 46 per lang4 languages (TS/Rust/Go/Python), 1,073+ tests across real-world scenarios
184 challenge questions“Guess what happens” scenario Q&A to test understanding
9 system case studiesHow React, Linux, Go, Git, Node.js, Rust, game engines, and distributed systems compose patterns
4 languagesTypeScript, Go, Python, Rust — idiomatic implementations
BilingualFull English + Chinese documentation
Learning guidesLearning Paths · Complexity Cheat Sheet · Pattern Comparison · Study Plan

Quick Start

Prerequisites

ToolVersionRequired for
Node.js≥ 22Docs site, TypeScript exercises
pnpm≥ 9Package manager
RuststableRust exercises (optional)
Go≥ 1.23Go exercises (optional)
Python≥ 3.10Python exercises (optional)
git clone https://github.com/Totoro-jam/battle-tested-patterns.git
cd battle-tested-patterns && pnpm install

# Run exercises in any language
pnpm test:exercises               # TypeScript (491 tests, Vitest)
cd exercises/rust && cargo test   # Rust (173 tests)
cd exercises/go && go test ./...  # Go (176 tests)
cd exercises/python && pytest     # Python (233 tests)

pnpm test                         # Run ALL tests (exercises + docs components)

pnpm dev                          # Local docs site

See the Exercise Guide for detailed setup instructions per language.

Contributing

See CONTRIBUTING.md. The bar is intentionally high:

  1. ≥ 2 production proofs with verified, line-number-precise source links
  2. TypeScript + ≥ 1 other language — idiomatic, not translated
  3. Exercise files in all 4 languages (TS/Rust/Go/Python) + answer files
  4. Chinese translation with identical code blocks
  5. All tests pass (pnpm test · cargo test · go test ./... · pytest), no lint errors
  6. Source links checked weekly by CI — broken links auto-open an Issue

Contributors

Totoro-jam
Totoro-jam

💻 📖 🎨 🚧 🤔

This project follows the all-contributors specification. Contributions of any kind welcome!

Star History

Star History Chart

License

MIT © Totoro-jam

相似文章

@Ryrenz: 卧槽,有人把自己半年调教 Claude Code 的全套配置开源了。 这个参考库在 GitHub 攒了 9700 多 star,是作者拿一个真实的 TypeScript 微服务项目跑了 6 个月磨出来的生产级配置。 它专治一个让很多人头疼…

X AI KOLs Timeline

An open-source reference library containing production-tested Claude Code infrastructure from 6 months of real-world use, including auto-activating skills, hooks, and modular patterns for TypeScript microservices projects.

@IndieDevHailey: 程序员跪着啃源码的噩梦时代,终结了! 这个项目让任何代码库直接变成可以点击、可以问答的交互式知识图谱! Understand Anything,21.8k stars,GitHub Trending 第一 点击任意函数,秒告诉你:这模块干…

X AI KOLs Timeline

Understand Anything 是一个开源工具,能将任何代码库转化为可点击、可问答的交互式知识图谱,帮助开发者快速理解代码结构、依赖关系和调用关系,支持 Claude Code、Cursor 和 VS Code,仅需一行命令即可安装。