Skip to content

docs: add Mermaid architecture, flow, and lifecycle diagrams - #9

Merged
christiangda merged 1 commit into
mainfrom
docs/mermaid-diagrams
Jul 11, 2026
Merged

docs: add Mermaid architecture, flow, and lifecycle diagrams#9
christiangda merged 1 commit into
mainfrom
docs/mermaid-diagrams

Conversation

@christiangda

Copy link
Copy Markdown
Contributor

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

  • Component flowchart — how BucketLimiter wires together the newLimiter factory, the pluggable Storage[K, Limiter], the per-key access map, and the background sweepLoop, with each key pointing at its own independent golang.org/x/time/rate bucket.
  • Sequence diagram — a GetOrAdd(key).Allow() call, including the atomic LoadOrStore race path and the allowed/limited (429) branch.

docs/TOKEN_BUCKET.md

  • Token-bucket flow diagram — refill, overflow, and the tokens ≥ 1? decision (complements the existing ASCII art).
  • Lifecycle state diagram — a single key moving Absent → Active → Idle → evicted, plus Remove and timer-refresh transitions.
  • HTTP-middleware sequence diagram — mirrors the real ReserveN(now, 1) / DelayFrom(now) / Cancel() flow in examples/middleware, showing the 200 vs 429 + Retry-After branches.

Notes

  • Docs-only change; no source or public API touched.
  • Diagram labels were checked against the actual code (bucket_limiter.go, examples/middleware/main.go) so they stay accurate.
  • There was no Go Report Card badge in the README to remove — the current badges are Go Reference, go-mod version, license, Release, and CodeQL. Nothing was changed in the badge row.

🤖 Generated with Claude Code

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>
@christiangda christiangda self-assigned this Jul 11, 2026
@christiangda
christiangda merged commit 2543374 into main Jul 11, 2026
4 checks passed
@christiangda
christiangda deleted the docs/mermaid-diagrams branch July 11, 2026 13:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant