# anant-agarwal12/redirecthub architecture

> Architecture diagram of the GitHub repository anant-agarwal12/redirecthub, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/anant-agarwal12/redirecthub
- Repository: https://github.com/anant-agarwal12/redirecthub

## Overview

RedirectHub is a payment-link shortening and redirect service. Clients create links through `/shorten`, where the server stores a link, encodes its generated ID as a Base62 code, and returns the short link. On redirects, the server rate-limits requests, checks Redis before PostgreSQL, validates expiry, and responds with a redirect or error; click logging runs asynchronously. The README also documents cache metrics and expiry behavior. Source excerpts show the runtime entry point and storage modules; deployment topology and other unsampled implementation details are not mapped.

Main entry points: [`src/index.js`](https://github.com/anant-agarwal12/redirecthub/blob/main/src/index.js) (Express Server), [`src/db.js`](https://github.com/anant-agarwal12/redirecthub/blob/main/src/db.js) (Database Access), [`src/redis.js`](https://github.com/anant-agarwal12/redirecthub/blob/main/src/redis.js) (Read-Through Cache), [`src/middleware/rateLimit.js`](https://github.com/anant-agarwal12/redirecthub/blob/main/src/middleware/rateLimit.js) (Rate Limiter)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_server["Express Server<br/>[index.js]"]
end

subgraph group_links["Link Workflow"]
  node_shorten["Create Link<br/>[index.js]"]
  node_base62["Base62 Encoder<br/>[base62.js]"]
  node_redirect["Resolve And Redirect<br/>[index.js]"]
  node_expiry["Expiry Checks<br/>[index.js]"]
end

subgraph group_platform["Cache And Limits"]
  node_rate["Rate Limiter<br/>[rateLimit.js]"]
  node_cache["Read-Through Cache<br/>[redis.js]"]
  node_metrics["Cache Metrics<br/>[redis.js]"]
  node_redis[("Redis")]
end

subgraph group_analytics["Click Analytics"]
  node_db["Database Access<br/>[db.js]"]
  node_postgres[("PostgreSQL")]
  node_clicks["Async Click Logging<br/>[db.js]"]
end

node_client(("Client"))

node_client -->|"HTTP requests"| node_server
node_server -->|"dispatches"| node_shorten
node_server -->|"dispatches"| node_redirect
node_server -->|"runs middleware"| node_rate
node_rate -->|"updates window"| node_redis
node_shorten -->|"creates link"| node_db
node_db -->|"queries"| node_postgres
node_db -->|"returns ID"| node_shorten
node_shorten -->|"encodes ID"| node_base62
node_shorten -->|"updates code"| node_db
node_redirect -->|"gets code"| node_cache
node_cache -->|"reads and writes"| node_redis
node_redirect -->|"looks up on miss"| node_db
node_redirect -->|"checks validity"| node_expiry
node_expiry -->|"deletes expired entry"| node_cache
node_redirect -->|"caches database result"| node_cache
node_redirect -->|"logs asynchronously"| node_clicks
node_clicks -->|"inserts click"| node_db
node_server -->|"reads metrics"| node_metrics
node_metrics -->|"returns metrics"| node_client
node_server -->|"redirects or responds"| node_client

click node_server "https://github.com/anant-agarwal12/redirecthub/blob/main/src/index.js"
click node_shorten "https://github.com/anant-agarwal12/redirecthub/blob/main/src/index.js"
click node_base62 "https://github.com/anant-agarwal12/redirecthub/blob/main/src/utils/base62.js"
click node_redirect "https://github.com/anant-agarwal12/redirecthub/blob/main/src/index.js"
click node_expiry "https://github.com/anant-agarwal12/redirecthub/blob/main/src/index.js"
click node_rate "https://github.com/anant-agarwal12/redirecthub/blob/main/src/middleware/rateLimit.js"
click node_cache "https://github.com/anant-agarwal12/redirecthub/blob/main/src/redis.js"
click node_metrics "https://github.com/anant-agarwal12/redirecthub/blob/main/src/redis.js"
click node_db "https://github.com/anant-agarwal12/redirecthub/blob/main/src/db.js"
click node_clicks "https://github.com/anant-agarwal12/redirecthub/blob/main/src/db.js"

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_server,node_client toneBlue
class node_shorten,node_base62,node_redirect,node_expiry toneAmber
class node_rate,node_cache,node_metrics,node_redis toneMint
class node_db,node_postgres,node_clicks toneRose
```

## Components

### HTTP API

- [Express Server](https://github.com/anant-agarwal12/redirecthub/blob/main/src/index.js): `src/index.js`

### Link Workflow

- [Create Link](https://github.com/anant-agarwal12/redirecthub/blob/main/src/index.js): `src/index.js`
- [Base62 Encoder](https://github.com/anant-agarwal12/redirecthub/blob/main/src/utils/base62.js): `src/utils/base62.js`
- [Resolve And Redirect](https://github.com/anant-agarwal12/redirecthub/blob/main/src/index.js): `src/index.js`
- [Expiry Checks](https://github.com/anant-agarwal12/redirecthub/blob/main/src/index.js): `src/index.js`

### Cache And Limits

- [Rate Limiter](https://github.com/anant-agarwal12/redirecthub/blob/main/src/middleware/rateLimit.js): `src/middleware/rateLimit.js`
- [Read-Through Cache](https://github.com/anant-agarwal12/redirecthub/blob/main/src/redis.js): `src/redis.js`
- [Cache Metrics](https://github.com/anant-agarwal12/redirecthub/blob/main/src/redis.js): `src/redis.js`
- **Redis**

### Click Analytics

- [Database Access](https://github.com/anant-agarwal12/redirecthub/blob/main/src/db.js): `src/db.js`
- **PostgreSQL**
- [Async Click Logging](https://github.com/anant-agarwal12/redirecthub/blob/main/src/db.js): `src/db.js`

### Other components

- **Client**

## Connections

- Client → Express Server: HTTP requests
- Express Server → Create Link: dispatches
- Express Server → Resolve And Redirect: dispatches
- Express Server → Rate Limiter: runs middleware
- Rate Limiter → Redis: updates window
- Create Link → Database Access: creates link
- Database Access → PostgreSQL: queries
- Database Access → Create Link: returns ID
- Create Link → Base62 Encoder: encodes ID
- Create Link → Database Access: updates code
- Resolve And Redirect → Read-Through Cache: gets code
- Read-Through Cache → Redis: reads and writes
- Resolve And Redirect → Database Access: looks up on miss
- Resolve And Redirect → Expiry Checks: checks validity
- Expiry Checks → Read-Through Cache: deletes expired entry
- Resolve And Redirect → Read-Through Cache: caches database result
- Resolve And Redirect → Async Click Logging: logs asynchronously
- Async Click Logging → Database Access: inserts click
- Express Server → Cache Metrics: reads metrics
- Cache Metrics → Client: returns metrics
- Express Server → Client: redirects or responds
