docs: add Mermaid architecture, flow, and lifecycle diagrams - #9
Merged
Conversation
Add rendered-on-GitHub Mermaid diagrams to the README and token-bucket guide to make the library's design easier to grasp at a glance: - README: a component flowchart of BucketLimiter / Storage / factory / sweeper and a GetOrAdd().Allow() sequence diagram showing per-key isolation. - docs/TOKEN_BUCKET.md: a token-bucket flow diagram, a per-key lifecycle state diagram (Absent → Active → Idle → evicted), and an HTTP-middleware sequence diagram matching the ReserveN/DelayFrom/Cancel flow in examples/middleware. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds Mermaid diagrams (which GitHub renders natively) to the README and the token-bucket guide so the design of the library reads at a glance.
README — new Architecture section
BucketLimiterwires together thenewLimiterfactory, the pluggableStorage[K, Limiter], the per-keyaccessmap, and the backgroundsweepLoop, with each key pointing at its own independentgolang.org/x/time/ratebucket.GetOrAdd(key).Allow()call, including the atomicLoadOrStorerace path and the allowed/limited (429) branch.docs/TOKEN_BUCKET.md
tokens ≥ 1?decision (complements the existing ASCII art).Absent → Active → Idle → evicted, plusRemoveand timer-refresh transitions.ReserveN(now, 1)/DelayFrom(now)/Cancel()flow inexamples/middleware, showing the 200 vs 429 +Retry-Afterbranches.Notes
bucket_limiter.go,examples/middleware/main.go) so they stay accurate.🤖 Generated with Claude Code