@QingQ77: 一套从生产代码中提取的、可验证的编程模式参考,每个模式附带交互式可视化、精确到行的源码链接和多语言实现。 https://github.com/Totoro-jam/battle-tested-patterns… Battle-Teste…
摘要
一个从真实生产代码(如React、Linux内核、Go、Redis等)中提取的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
English | 简体中文
46 Patterns at a Glance
|
🧠 Data Structures
|
⚡ Concurrency
|
🏗️ Systems
|
|
♻️ Memory
|
🔄 Behavioral
|
📊 Proven In
|
The Gap This Fills
| What exists | What’s missing |
|---|---|
| Design patterns books | Too abstract, too OOP-centric |
| Algorithm repos | Disconnected from real engineering |
| System design guides | Architecture-level, not code-level |
This project: code-level techniques from React, Linux, Go, Chromium — each with verifiable source links.
Patterns
| Pattern | What It Does | Proven In |
|---|---|---|
| Bitmask | Pack N flags into one integer, check any combo in O(1) | React Flags · Linux stat.h |
| Double Buffering | Swap two copies atomically, zero allocation | React Fiber · SDL |
| Cooperative Scheduling | Yield control between work chunks to stay responsive | React Scheduler · Go Runtime |
| Min Heap | O(1) peek at highest priority, O(log n) push/pop | React MinHeap · Linux CFS |
| Diff / Patch | Compute minimal edits between two sequences | React Reconciler · Git |
| Object Pool | Pre-allocate and reuse to avoid GC pressure | Go sync.Pool · Godot |
| Ring Buffer | Fixed-size circular queue, zero allocation | LMAX Disruptor · Linux |
| State Machine | Explicit states, impossible transitions unrepresentable | XState · Linux TCP |
| Copy-on-Write | Share by reference, copy only on mutation | Git objects · Rust Cow |
| Observer | Subscribe to events, decouple producers from consumers | Node EventEmitter · Redux |
| Iterator | Lazy sequences, zero intermediate allocations | Rust Iterator · Python gen |
| Semaphore | Bounded concurrency with a counter | Linux · Go x/sync |
| Batch Processing | Accumulate ops, execute as group | Kafka |
| Retry with Backoff | Exponential delay + jitter on failure | Kubernetes · gRPC |
| Event Loop | Single-threaded loop multiplexes I/O via epoll/kqueue | libuv · Redis ae |
| Flyweight | Share identical objects, avoid duplicates | Python int cache |
| Bloom Filter | Probabilistic set membership, zero false negatives | LevelDB · Chromium |
| Circuit Breaker | Stop calling failing services, fail fast | Hystrix · gobreaker |
| Arena Allocator | Bump-allocate, free all at once | bumpalo · Go arena |
| B+ Tree | High-fanout balanced tree — internal nodes guide, leaves store and link for range scans | PostgreSQL · SQLite |
| Backpressure | Slow producers when consumers can’t keep up | Node.js Streams · Reactive Streams |
| Write-Ahead Log | Log mutations before applying, crash recovery | etcd · PostgreSQL |
| Logical Clock | Monotonic counter orders events without wall-clock time | etcd · LevelDB |
| LRU Cache | Evict least recently used, O(1) get/put | groupcache · Linux |
| Consistent Hashing | Add/remove nodes remaps ~1/n keys | groupcache · HAProxy |
| Trie | O(k) lookup, shared prefixes share nodes | Linux FIB · Redis rax |
| Skip List | Probabilistic O(log n) sorted structure | Redis · LevelDB |
| Rate Limiter | Token bucket controls throughput | Go rate · Nginx |
| Reference Counting | Atomic counter tracks owners, auto-cleanup at zero | CPython · Rust Arc |
| Registry | Components self-register into a global lookup table by name | TensorFlow · gRPC-Go |
| Work Stealing | Idle threads steal from busy queues | Go proc.go · Tokio |
| MVCC | Timestamped versions, readers never block | PostgreSQL · etcd |
| Free List | O(1) alloc/free via linked freed slots | Go mfixalloc · Linux SLUB |
| Dependency Graph | DAG + toposort for execution order | Cargo · pnpm |
| Dirty Flag | Mark “dirty” on mutation, defer recomputation until needed | Chromium/Blink · React |
| Actor Model | Private state + mailbox, no locks | Akka · Erlang/OTP |
| Tagged Union | Type tag + union for safe dispatch | Godot Variant · PyTorch IValue |
| Interning | Deduplicate values, O(1) equality | Rust Symbol · CPython |
| Vtable | Function pointer struct for polymorphism | Linux file_operations · CPython PyTypeObject |
| Visitor | Dispatch callbacks on tree nodes | LLVM InstVisitor · Vue transforms |
| Merkle Tree | Hash upward to root for integrity | Git tree.c · ZFS blkptr |
| Merge Iterator | K-way merge of sorted streams | LevelDB merger · RocksDB merge |
| Middleware Chain | Compose handlers where each wraps the next — bidirectional pipeline | gRPC-Go · Koa.js |
| LSM Tree | Buffer writes, flush to sorted files | LevelDB DBImpl · RocksDB MemTable |
| Checkpointing | Snapshot state, recover from checkpoint | PostgreSQL · Redis RDB |
| Tombstone | Mark deleted with a tombstone, background reclaims later | LevelDB · 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
| Feature | Details |
|---|---|
| 46 patterns | Bitmask, LRU Cache, MVCC, Work Stealing, Actor Model, and 41 more |
| 46 interactive visualizations | Hands-on SVG visualizations — click, drag, experiment, then undo or replay any step with the time-travel playback bar |
| 93 TS exercises + 46 per lang | 4 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 studies | How React, Linux, Go, Git, Node.js, Rust, game engines, and distributed systems compose patterns |
| 4 languages | TypeScript, Go, Python, Rust — idiomatic implementations |
| Bilingual | Full English + Chinese documentation |
| Learning guides | Learning Paths · Complexity Cheat Sheet · Pattern Comparison · Study Plan |
Quick Start
Prerequisites
| Tool | Version | Required for |
|---|---|---|
| Node.js | ≥ 22 | Docs site, TypeScript exercises |
| pnpm | ≥ 9 | Package manager |
| Rust | stable | Rust exercises (optional) |
| Go | ≥ 1.23 | Go exercises (optional) |
| Python | ≥ 3.10 | Python 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:
- ≥ 2 production proofs with verified, line-number-precise source links
- TypeScript + ≥ 1 other language — idiomatic, not translated
- Exercise files in all 4 languages (TS/Rust/Go/Python) + answer files
- Chinese translation with identical code blocks
- All tests pass (
pnpm test·cargo test·go test ./...·pytest), no lint errors - Source links checked weekly by CI — broken links auto-open an Issue
Contributors
Totoro-jam 💻 📖 🎨 🚧 🤔 |
This project follows the all-contributors specification. Contributions of any kind welcome!
Star History
License
MIT © Totoro-jam
相似文章
@seekjourney: 挖到宝了,还有大量 codex 实战案例库!关键步骤都有截图。 https://codexguide.ai/recipes/ https://github.com/freestylefly/CodexGuide…
分享了一个包含16个Codex实战案例的案例库,覆盖PPT生成、MCP、浏览器自动化、知识库等功能,并提供截图和步骤指南。
@wsl8297: 分享一本通俗好读的开源书《大模型基础》。 从大语言模型入门到架构演化,再到 Prompt 工程、参数高效微调、模型编辑、检索增强生成(RAG)等关键技术,一本串起来。 GitHub:https://github.com/ZJU-LLMs/…
浙江大学团队开源了一本通俗易懂的大模型教材《大模型基础》,涵盖从架构演化到RAG等关键技术,并附带Agent-Kernel多智能体框架。
@Ryrenz: 卧槽,有人把自己半年调教 Claude Code 的全套配置开源了。 这个参考库在 GitHub 攒了 9700 多 star,是作者拿一个真实的 TypeScript 微服务项目跑了 6 个月磨出来的生产级配置。 它专治一个让很多人头疼…
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 第一 点击任意函数,秒告诉你:这模块干…
Understand Anything 是一个开源工具,能将任何代码库转化为可点击、可问答的交互式知识图谱,帮助开发者快速理解代码结构、依赖关系和调用关系,支持 Claude Code、Cursor 和 VS Code,仅需一行命令即可安装。
@AI_jacksaku: https://x.com/AI_jacksaku/status/2068702722807771294
本文整理了Codex必装的10个高价值Skills,涵盖规划、代码质量、前端实现、自动化测试、CI/CD、安全及外部工具接入,并提供了安装方法和推荐组合,帮助用户提升开发效率。