# hcksyg-27/myleetcode architecture

> Architecture diagram of the GitHub repository hcksyg-27/myleetcode, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hcksyg-27/myleetcode
- Repository: https://github.com/hcksyg-27/myleetcode

## Overview

This is a small in-memory rate-limiting library for an LLM API gateway. A caller submits a client and resource to `allow`; the limiter retrieves isolated state, dispatches to the configured sliding-window or token-bucket algorithm, and returns an allow decision with remaining capacity and, on rejection, a retry estimate. The source confirms these calls and the use of the system clock. Both algorithms share one implementation file; no separate gateway or persistent storage is present.

Main entry points: [`rate_limiter.py`](https://github.com/hcksyg-27/myleetcode/blob/main/rate_limiter.py) (Request Decision)

## Diagram (Mermaid)

```mermaid
flowchart TD

node_caller(("API Caller"))
node_allow["Request Decision<br/>[rate_limiter.py]"]
node_state_lookup["State Lookup<br/>[rate_limiter.py]"]
node_state_store["Per-Client State<br/>[rate_limiter.py]"]
node_sliding["Sliding Window<br/>[rate_limiter.py]"]
node_bucket["Token Bucket<br/>[rate_limiter.py]"]
node_clock["System Clock"]

node_caller -->|"submits request"| node_allow
node_allow -->|"gets state"| node_state_lookup
node_state_lookup -->|"reads or creates"| node_state_store
node_allow -->|"dispatches to"| node_sliding
node_allow -->|"dispatches to"| node_bucket
node_sliding -->|"reads time"| node_clock
node_bucket -->|"reads time"| node_clock

click node_allow "https://github.com/hcksyg-27/myleetcode/blob/main/rate_limiter.py"
click node_state_lookup "https://github.com/hcksyg-27/myleetcode/blob/main/rate_limiter.py"
click node_state_store "https://github.com/hcksyg-27/myleetcode/blob/main/rate_limiter.py"
click node_sliding "https://github.com/hcksyg-27/myleetcode/blob/main/rate_limiter.py"
click node_bucket "https://github.com/hcksyg-27/myleetcode/blob/main/rate_limiter.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_caller,node_allow toneMint
class node_state_lookup,node_sliding,node_bucket toneTeal
class node_state_store toneBlue
class node_clock toneIndigo
```

## Components

### Other components

- **API Caller**
- [Request Decision](https://github.com/hcksyg-27/myleetcode/blob/main/rate_limiter.py): `rate_limiter.py`
- [State Lookup](https://github.com/hcksyg-27/myleetcode/blob/main/rate_limiter.py): `rate_limiter.py`
- [Per-Client State](https://github.com/hcksyg-27/myleetcode/blob/main/rate_limiter.py): `rate_limiter.py`
- [Sliding Window](https://github.com/hcksyg-27/myleetcode/blob/main/rate_limiter.py): `rate_limiter.py`
- [Token Bucket](https://github.com/hcksyg-27/myleetcode/blob/main/rate_limiter.py): `rate_limiter.py`
- **System Clock**

## Connections

- API Caller → Request Decision: submits request (evidence: `README.md`)
- Request Decision → State Lookup: gets state (evidence: `rate_limiter.py`)
- State Lookup → Per-Client State: reads or creates (evidence: `rate_limiter.py`)
- Request Decision → Sliding Window: dispatches to (evidence: `rate_limiter.py`)
- Request Decision → Token Bucket: dispatches to (evidence: `rate_limiter.py`)
- Sliding Window → System Clock: reads time (evidence: `rate_limiter.py`)
- Token Bucket → System Clock: reads time (evidence: `rate_limiter.py`)
