@QingQ77: A verifiable reference of programming patterns extracted from production code, each with interactive visualization, line-accurate source links, and multi-language implementations. https://github.com/Totoro-jam/battle-tested-patterns… Battle-Teste…
Summary
A reference library of 46 programming patterns extracted from real production code (e.g., React, Linux kernel, Go, Redis, etc.), each with interactive visualization, line-accurate source links, implementations in TypeScript/Python/Go/Rust, and runnable exercises. The site is bilingual (Chinese and English) and supports search and category browsing.
View Cached Full Text
Cached at: 06/15/26, 11:01 AM
A verifiable programming pattern reference extracted from production code. Each pattern includes interactive visualization, precise line-level source code links, and multi-language implementations. https://github.com/Totoro-jam/battle-tested-patterns… Battle-Tested Patterns extracts 46 programming patterns from real projects such as React, Linux kernel, Go, Redis, PostgreSQL, Chromium, etc., categorized into five major types: Data Structures, Concurrency, System Design, Memory Management, and Behavioral. Each pattern comes with interactive visualization, precise line-number source links (not directory, but specific line), code implementations in four languages (TypeScript, Python, Go, Rust), and runnable exercises. The site is bilingual (Chinese and English) with support for search and category browsing.
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 (https://totoro-jam.github.io/battle-tested-patterns/) · 📖 中文文档 (https://totoro-jam.github.io/battle-tested-patterns/zh/)
English | 简体中文
CI (https://github.com/Totoro-jam/battle-tested-patterns/actions/workflows/ci.yml) Deploy (https://github.com/Totoro-jam/battle-tested-patterns/actions/workflows/deploy.yml)
License: MIT PRs Welcome
46 Patterns at a Glance
🧠 Data Structures
- Bitmask (https://totoro-jam.github.io/battle-tested-patterns/patterns/bitmask/) — flags in one int
- Min Heap (https://totoro-jam.github.io/battle-tested-patterns/patterns/min-heap/) — priority queue
- Ring Buffer (https://totoro-jam.github.io/battle-tested-patterns/patterns/ring-buffer/) — fixed-size FIFO
- Trie (https://totoro-jam.github.io/battle-tested-patterns/patterns/trie/) — prefix search
- Skip List (https://totoro-jam.github.io/battle-tested-patterns/patterns/skip-list/) — probabilistic order
- Bloom Filter (https://totoro-jam.github.io/battle-tested-patterns/patterns/bloom-filter/) — set membership
- LRU Cache (https://totoro-jam.github.io/battle-tested-patterns/patterns/lru-cache/) — eviction policy
- B+ Tree (https://totoro-jam.github.io/battle-tested-patterns/patterns/b-plus-tree/) — disk-optimized index
- Tagged Union (https://totoro-jam.github.io/battle-tested-patterns/patterns/tagged-union/) — type-safe dispatch
- Merkle Tree (https://totoro-jam.github.io/battle-tested-patterns/patterns/merkle-tree/) — integrity proof
- Merge Iterator (https://totoro-jam.github.io/battle-tested-patterns/patterns/merge-iterator/) — k-way merge
⚡ Concurrency
- Semaphore (https://totoro-jam.github.io/battle-tested-patterns/patterns/semaphore/) — bounded access
- Actor Model (https://totoro-jam.github.io/battle-tested-patterns/patterns/actor-model/) — message passing
- Work Stealing (https://totoro-jam.github.io/battle-tested-patterns/patterns/work-stealing/) — load balance
- MVCC (https://totoro-jam.github.io/battle-tested-patterns/patterns/mvcc/) — snapshot isolation
- Cooperative Scheduling (https://totoro-jam.github.io/battle-tested-patterns/patterns/cooperative-scheduling/) — yield control
- Double Buffering (https://totoro-jam.github.io/battle-tested-patterns/patterns/double-buffering/) — atomic swap
- Backpressure (https://totoro-jam.github.io/battle-tested-patterns/patterns/backpressure/) — flow control
- Event Loop (https://totoro-jam.github.io/battle-tested-patterns/patterns/event-loop/) — I/O multiplexing
- Logical Clock (https://totoro-jam.github.io/battle-tested-patterns/patterns/logical-clock/) — event ordering
🏗️ Systems
- Circuit Breaker (https://totoro-jam.github.io/battle-tested-patterns/patterns/circuit-breaker/) — fault tolerance
- Rate Limiter (https://totoro-jam.github.io/battle-tested-patterns/patterns/rate-limiter/) — throttle
- Retry Backoff (https://totoro-jam.github.io/battle-tested-patterns/patterns/retry-backoff/) — resilience
- Write-Ahead Log (https://totoro-jam.github.io/battle-tested-patterns/patterns/write-ahead-log/) — durability
- Batch Processing (https://totoro-jam.github.io/battle-tested-patterns/patterns/batch-processing/) — throughput
- Consistent Hashing (https://totoro-jam.github.io/battle-tested-patterns/patterns/consistent-hashing/) — distribution
- Dependency Graph (https://totoro-jam.github.io/battle-tested-patterns/patterns/dependency-graph/) — ordering
- Middleware Chain (https://totoro-jam.github.io/battle-tested-patterns/patterns/middleware-chain/) — pipeline
- Registry (https://totoro-jam.github.io/battle-tested-patterns/patterns/registry/) — self-register
- Dirty Flag (https://totoro-jam.github.io/battle-tested-patterns/patterns/dirty-flag/) — deferred recompute
- LSM Tree (https://totoro-jam.github.io/battle-tested-patterns/patterns/lsm-tree/) — write-optimized store
- Checkpointing (https://totoro-jam.github.io/battle-tested-patterns/patterns/checkpointing/) — snapshot recovery
♻️ Memory
- Object Pool (https://totoro-jam.github.io/battle-tested-patterns/patterns/object-pool/) — reuse instances
- Flyweight (https://totoro-jam.github.io/battle-tested-patterns/patterns/flyweight/) — share immutables
- Arena Allocator (https://totoro-jam.github.io/battle-tested-patterns/patterns/arena-allocator/) — bump alloc
- Free List (https://totoro-jam.github.io/battle-tested-patterns/patterns/free-list/) — O(1) alloc/free
- Copy-on-Write (https://totoro-jam.github.io/battle-tested-patterns/patterns/copy-on-write/) — defer copy
- Reference Counting (https://totoro-jam.github.io/battle-tested-patterns/patterns/reference-counting/) — auto-cleanup
- Tombstone (https://totoro-jam.github.io/battle-tested-patterns/patterns/tombstone/) — deferred deletion
- Interning (https://totoro-jam.github.io/battle-tested-patterns/patterns/interning/) — deduplicate values
🔄 Behavioral
- State Machine (https://totoro-jam.github.io/battle-tested-patterns/patterns/state-machine/) — transitions
- Observer (https://totoro-jam.github.io/battle-tested-patterns/patterns/observer/) — pub/sub
- Iterator (https://totoro-jam.github.io/battle-tested-patterns/patterns/iterator/) — lazy eval
- Diff / Patch (https://totoro-jam.github.io/battle-tested-patterns/patterns/diff-patch/) — minimal edits
- Vtable (https://totoro-jam.github.io/battle-tested-patterns/patterns/vtable/) — manual polymorphism
- Visitor (https://totoro-jam.github.io/battle-tested-patterns/patterns/visitor/) — tree traversal dispatch
📊 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 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 (https://totoro-jam.github.io/battle-tested-patterns/patterns/bitmask/) | Pack N flags into one integer, check any combo in O(1) | React Flags (https://github.com/facebook/react/blob/34b78a2897cc208260a88e6b62ecaf9ca2a9dfe4/packages/react-reconciler/src/ReactFiberFlags.js#L14-L36) · Linux stat.h (https://github.com/torvalds/linux/blob/acb7500801e98639f6d8c2d796ed9f64cba83d3a/include/uapi/linux/stat.h#L25-L33) |
| Double Buffering (https://totoro-jam.github.io/battle-tested-patterns/patterns/double-buffering/) | Swap two copies atomically, zero allocation | React Fiber (https://github.com/facebook/react/blob/34b78a2897cc208260a88e6b62ecaf9ca2a9dfe4/packages/react-reconciler/src/ReactFiber.js#L327-L355) · SDL (https://github.com/libsdl-org/SDL/blob/14b0e9d922da78001223e563efd2f54f473a4115/src/render/SDL_render.c) |
| Cooperative Scheduling (https://totoro-jam.github.io/battle-tested-patterns/patterns/cooperative-scheduling/) | Yield control between work chunks to stay responsive | React Scheduler (https://github.com/facebook/react/blob/34b78a2897cc208260a88e6b62ecaf9ca2a9dfe4/packages/scheduler/src/forks/Scheduler.js#L188-L258) · Go Runtime (https://github.com/golang/go/blob/f5cdf4745455415c7a43cfc7d925214d4511489b/src/runtime/proc.go#L4143-L4200) |
| Min Heap (https://totoro-jam.github.io/battle-tested-patterns/patterns/min-heap/) | O(1) peek at highest priority, O(log n) push/pop | React MinHeap (https://github.com/facebook/react/blob/34b78a2897cc208260a88e6b62ecaf9ca2a9dfe4/packages/scheduler/src/SchedulerMinHeap.js#L17-L90) · Linux CFS (https://github.com/torvalds/linux/blob/acb7500801e98639f6d8c2d796ed9f64cba83d3a/kernel/sched/fair.c#L1407-L1460) |
| Diff / Patch (https://totoro-jam.github.io/battle-tested-patterns/patterns/diff-patch/) | Compute minimal edits between two sequences | React Reconciler (https://github.com/facebook/react/blob/34b78a2897cc208260a88e6b62ecaf9ca2a9dfe4/packages/react-reconciler/src/ReactChildFiber.js#L1169-L1340) · Git (https://github.com/git/git/blob/1ff279f3404a482a83fb04c7457e41ab26884aea/diff.c#L5020-L5060) |
| Object Pool (https://totoro-jam.github.io/battle-tested-patterns/patterns/object-pool/) | Pre-allocate and reuse to avoid GC pressure | Go sync.Pool (https://github.com/golang/go/blob/f5cdf4745455415c7a43cfc7d925214d4511489b/src/sync/pool.go#L52-L97) · Godot (https://github.com/godotengine/godot/blob/ec67cbe92628bdaf979b10594359ba6f02cf8838/core/templates/pooled_list.h#L35-L100) |
| Ring Buffer (https://totoro-jam.github.io/battle-tested-patterns/patterns/ring-buffer/) | Fixed-size circular queue, zero allocation | LMAX Disruptor (https://github.com/LMAX-Exchange/disruptor/blob/c871ca49826a6be7ada6957f6fbafcfecf7b1f87/src/main/java/com/lmax/disruptor/RingBuffer.java#L84-L130) · Linux (https://github.com/torvalds/linux/blob/acb7500801e98639f6d8c2d796ed9f64cba83d3a/include/linux/ring_buffer.h#L12-L70) |
| State Machine (https://totoro-jam.github.io/battle-tested-patterns/patterns/state-machine/) | Explicit states, impossible transitions unrepresentable | XState (https://github.com/statelyai/xstate/blob/9d9b9f1439b773979c5120a793215f5aa4568d8f/packages/core/src/StateMachine.ts#L58-L120) · Linux TCP (https://github.com/torvalds/linux/blob/acb7500801e98639f6d8c2d796ed9f64cba83d3a/net/ipv4/tcp_input.c#L4865-L4920) |
| Copy-on-Write (https://totoro-jam.github.io/battle-tested-patterns/patterns/copy-on-write/) | Share by reference, copy only on mutation | Git objects (https://github.com/git/git/blob/1ff279f3404a482a83fb04c7457e41ab26884aea/object-file.c#L719-L730) · Rust Cow (https://github.com/rust-lang/rust/blob/ab26b175979ee7b2cb3302dce204b99df96f7efb/library/alloc/src/borrow.rs#L169-L220) |
| Observer (https://totoro-jam.github.io/battle-tested-patterns/patterns/observer/) | Subscribe to events, decouple producers from consumers | Node EventEmitter (https://github.com/nodejs/node/blob/19c46abbefdb8711b913d7237b3c1299367f87d7/lib/events.js#L456-L520) · Redux (https://github.com/reduxjs/redux/blob/1d761f471cf58faabe88c50ea16645212d986cd0/src/createStore.ts#L211-L280) |
| Iterator (https://totoro-jam.github.io/battle-tested-patterns/patterns/iterator/) | Lazy sequences, zero intermediate allocations | Rust Iterator (https://github.com/rust-lang/rust/blob/ab26b175979ee7b2cb3302dce204b99df96f7efb/library/core/src/iter/traits/iterator.rs#L68-L112) · Python gen (https://github.com/python/cpython/blob/7a014f44c393fda6d1c4bd135608ebcfc21d626c/Objects/genobject.c) |
| Semaphore (https://totoro-jam.github.io/battle-tested-patterns/patterns/semaphore/) | Bounded concurrency with a counter | Linux (https://github.com/torvalds/linux/blob/acb7500801e98639f6d8c2d796ed9f64cba83d3a/include/linux/semaphore.h#L15-L55) · Go x/sync (https://github.com/golang/sync/blob/5071ed6a9f1617117556b66384f765c934de3698/semaphore/semaphore.go) |
| Batch Processing (https://totoro-jam.github.io/battle-tested-patterns/patterns/batch-processing/) | Accumulate ops, execute as group | Kafka (https://github.com/apache/kafka/blob/ab53829feb7280a1d453ebdaad032c4b64bb0f4d/clients/src/main/java/org/apache/kafka/clients/producer/internals/RecordAccumulator.java#L69-L120) |
| Retry with Backoff (https://totoro-jam.github.io/battle-tested-patterns/patterns/retry-backoff/) | Exponential delay + jitter on failure | Kubernetes (https://github.com/kubernetes/kubernetes/blob/586cc904093af4fe7492e564908a796f0b107f97/staging/src/k8s.io/apimachinery/pkg/util/wait/backoff.go#L30-L50) · gRPC (https://github.com/grpc/grpc/blob/19f781499b13a4890bc39d1a0e6a7909d3294de5/doc/connection-backoff.md) |
| Event Loop (https://totoro-jam.github.io/battle-tested-patterns/patterns/event-loop/) | Single-threaded loop multiplexes I/O via epoll/kqueue | libuv (https://github.com/libuv/libuv/blob/f6b713398e464a9f166328765be1703fd860981f/src/unix/core.c#L427-L492) · Redis ae (https://github.com/redis/redis/blob/df63a65d4d4ee33ae67e9f101885074febe0bccb/src/ae.c#L360-L468) |
| Flyweight (https://totoro-jam.github.io/battle-tested-patterns/patterns/flyweight/) | Share identical objects, avoid duplicates | Python int cache (https://github.com/python/cpython/blob/7a014f44c393fda6d1c4bd135608ebcfc21d626c/Objects/longobject.c#L61-L75) |
| Bloom Filter (https://totoro-jam.github.io/battle-tested-patterns/patterns/bloom-filter/) | Probabilistic set membership, zero false negatives | LevelDB (https://github.com/google/leveldb/blob/7ee830d02b623e8ffe0b95d59a74db1e58da04c5/util/bloom.cc#L17-L80) · Chromium (https://github.com/chromium/chromium/blob/92b3e1f66aa55921a0ab431b7c17b25ae1f3faef/third_party/blink/renderer/core/css/selector_filter.h#L149-L175) |
| Circuit Breaker (https://totoro-jam.github.io/battle-tested-patterns/patterns/circuit-breaker/) | Stop calling failing services, fail fast | Hystrix (https://github.com/Netflix/Hystrix/blob/5ce3bc58c38e7ca60ef2fe0e516e390e294ad941/hystrix-core/src/main/java/com/netflix/hystrix/HystrixCircuitBreaker.java#L138-L289) · gobreaker (https://github.com/sony/gobreaker/blob/fed8e9eb35f9cd3e5c2a67842c924346c3e1fbdd/gobreaker.go#L117-L131) |
| Arena Allocator (https://totoro-jam.github.io/battle-tested-patterns/patterns/arena-allocator/) | Bump-allocate, free all at once | bumpalo (https://github.com/fitzgen/bumpalo/blob/d2cc4dd0b8830d5b05d44e9decc776823e6a70ea/src/lib.rs#L378-L383) · Go arena (https://github.com/golang/go/blob/f5cdf4745455415c7a43cfc7d925214d4511489b/src/arena/arena.go#L44-L67) |
| B+ Tree (https://totoro-jam.github.io/battle-tested-patterns/patterns/b-plus-tree/) | High-fanout balanced tree — internal nodes guide, leaves store and link for range scans | PostgreSQL (https://github.com/postgres/postgres/blob/e18b0cb7344cb4bd28468f6c0aeeb9b9241d30aa/src/backend/access/nbtree/nbtinsert.c#L22-L55) · SQLite (https://github.com/sqlite/sqlite/blob/2cb57d9d4ac7eac3b1d15cfa71511f54817cb3e4/src/btreeInt.h#L190-L198) |
| Backpressure (https://totoro-jam.github.io/battle-tested-patterns/patterns/backpressure/) | Slow producers when consumers can’t keep up | Node.js Streams (https://github.com/nodejs/node/blob/19c46abbefdb8711b913d7237b3c1299367f87d7/lib/internal/streams/writable.js#L312-L370) · Reactive Streams (https://github.com/reactive-streams/reactive-streams-jvm/blob/a625d3aba756e9842ad1291a5b73f5db280b6168/api/src/main/java/org/reactivestreams/Subscription.java#L14-L37) |
| Write-Ahead Log (https://totoro-jam.github.io/battle-tested-patterns/patterns/write-ahead-log/) | Log mutations before applying, crash recovery | etcd (https://github.com/etcd-io/etcd/blob/e9b62f804766edf77cfa918d600cb6fb2c56b401/server/storage/wal/wal.go#L72-L95) · PostgreSQL (https://github.com/postgres/postgres/blob/e18b0cb7344cb4bd28468f6c0aeeb9b9241d30aa/src/backend/access/transam/xlog.c) |
| Logical Clock (https://totoro-jam.github.io/battle-tested-patterns/patterns/logical-clock/) | Monotonic counter orders events without wall-clock time | etcd (https://github.com/etcd-io/etcd/blob/e9b62f804766edf77cfa918d600cb6fb2c56b401/server/storage/mvcc/kvstore.go#L53-L72) · LevelDB (https://github.com/google/leveldb/blob/7ee830d02b623e8ffe0b95d59a74db1e58da04c5/db/dbformat.h#L62-L66) |
| LRU Cache (https://totoro-jam.github.io/battle-tested-patterns/patterns/lru-cache/) | Keep recently accessed items, evict stale ones | Chromium (https://source.chromium.org/chromium/chromium/src/+/main:base/containers/lru_cache.h) · Redis (https://github.com/redis/redis/blob/df63a65d4d4ee33ae67e9f101885074febe0bccb/src/evict.c#L120-L180) |
Similar Articles
@seekjourney: Found a treasure trove! There's also a large collection of Codex practical case studies! Key steps are all with screenshots. https://codexguide.ai/recipes/ https://github.com/freestylefly/CodexGuide…
Shared a case library containing 16 Codex hands-on examples, covering PPT generation, MCP, browser automation, knowledge base, and other functions, with screenshots and step-by-step guides.
@wsl8297: Sharing an easy-to-read open-source book 'Foundations of Large Models'. From an introduction to large language models to architectural evolution, then to key technologies such as Prompt engineering, parameter-efficient fine-tuning, model editing, retrieval-augmented generation (RAG), all in one book. GitHub: https://github.com/ZJU-LLMs/…
The Zhejiang University team open-sourced an easy-to-understand textbook on large models 'Foundations of Large Models', covering from architectural evolution to key technologies like RAG, accompanied by the Agent-Kernel multi-agent framework.
@Ryrenz: Whoa, someone open-sourced their entire Claude Code configuration honed over six months. This reference repo has racked up over 9700 stars on GitHub — it's a production-grade setup the author refined by running a real TypeScript microservices project for 6 months. It specifically tackles a headache many people have...
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: The nightmare era of developers groveling through source code is over! This project turns any codebase into an interactive knowledge graph you can click and query. Understand Anything, 21.8k stars, #1 on GitHub Trending. Click any function and instantly know: what this module does...
Understand Anything is an open-source tool that transforms any codebase into an interactive, queryable knowledge graph, helping developers quickly understand code structure, dependencies, and call relationships. It supports Claude Code, Cursor, and VS Code, and can be installed with a single command.
@AI_jacksaku: https://x.com/AI_jacksaku/status/2068702722807771294
This article compiles 10 high-value Skills essential for Codex, covering planning, code quality, frontend implementation, automated testing, CI/CD, security, and external tool integration, and provides installation methods and recommended combinations to help users improve development efficiency.