# karthikeyapolakonda/url-shortener architecture

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

- Interactive diagram: https://gitdiagram.com/karthikeyapolakonda/url-shortener
- Repository: https://github.com/karthikeyapolakonda/url-shortener

## Overview

Stub is an authenticated URL-shortening product: users sign in, create owned short links, inspect or delete them, while visitors resolve codes to redirects and generate click analytics. The graph includes the frontend-to-API path, backend domain stages, persistence, and Redis-backed services. README documents frontend history and stats; several route/service implementations were not excerpted, so those links are shown only where documentation or indexed references support them.

Main entry points: [`backend/app/main.py`](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/main.py) (FastAPI app), [`backend/app/routers/redirect.py`](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/routers/redirect.py) (Redirect route), [`backend/app/routers/links.py`](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/routers/links.py) (Link routes), [`backend/app/routers/auth.py`](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/routers/auth.py) (Auth routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_webui["Shortener UI<br/>[page.tsx]"]
  node_dash["Dashboard<br/>[page.tsx]"]
  node_stats["Link stats<br/>[page.tsx]"]
  node_history["Browser history<br/>[storage.ts]"]
  node_api_client["Fetch client<br/>[api.ts]"]
  node_link_service["Link API service<br/>[links.ts]"]
  node_auth_web["Auth experience<br/>[AuthContext.tsx]"]
  node_auth_service["Auth API service<br/>[auth.ts]"]
end

subgraph group_api["API surface"]
  node_api_app["FastAPI app<br/>[main.py]"]
  node_link_routes["Link routes<br/>[links.py]"]
  node_redirect_route["Redirect route<br/>[redirect.py]"]
  node_auth_routes["Auth routes<br/>[auth.py]"]
  node_health_routes["Health routes<br/>[health.py]"]
  node_schemas["Request schemas<br/>[schemas.py]"]
end

subgraph group_domain["Identity and links"]
  node_crud["Link and user logic<br/>[crud.py]"]
  node_security["Token security<br/>[security.py]"]
  node_models["Domain models<br/>[models.py]"]
end

subgraph group_infra["Runtime services"]
  node_database[("SQL database<br/>[database.py]")]
  node_cache["Link cache<br/>[cache.py]"]
  node_analytics["Click analytics<br/>[analytics.py]"]
  node_limiter["Rate limiter<br/>[rate_limit.py]"]
  node_redis["Redis gateway<br/>[redis_client.py]"]
end

node_visitor(("Visitor"))
node_destination(("Destination URL"))

node_visitor -->|"uses"| node_webui
node_webui -.->|"requests links"| node_link_service
node_dash -.->|"loads links"| node_link_service
node_stats -.->|"loads stats"| node_link_service
node_webui -->|"stores codes"| node_history
node_history -->|"refreshes stats"| node_link_service
node_link_service -.->|"calls"| node_api_client
node_api_client -->|"HTTP requests"| node_api_app
node_auth_web -.->|"auth requests"| node_auth_service
node_auth_service -.->|"uses"| node_api_client
node_api_app -->|"registers"| node_link_routes
node_api_app -->|"registers last"| node_redirect_route
node_api_app -->|"registers"| node_auth_routes
node_api_app -->|"registers"| node_health_routes
node_link_routes -->|"validates and responds"| node_schemas
node_auth_routes -->|"validates and responds"| node_schemas
node_link_routes -->|"creates and manages"| node_crud
node_redirect_route -->|"looks up link"| node_crud
node_auth_routes -->|"manages users"| node_crud
node_auth_routes -->|"hashes and signs"| node_security
node_link_routes -->|"caches and invalidates"| node_cache
node_redirect_route -->|"reads cache"| node_cache
node_redirect_route -->|"records clicks"| node_analytics
node_link_routes -->|"checks limits"| node_limiter
node_auth_routes -->|"checks limits"| node_limiter
node_redirect_route -->|"checks limits"| node_limiter
node_limiter -->|"increments counters"| node_redis
node_crud -->|"queries and persists"| node_models
node_models -->|"maps to"| node_database
node_health_routes -->|"checks connection"| node_database
node_api_app -->|"closes on shutdown"| node_redis
node_redis -.->|"backs storage"| node_cache
node_redirect_route -->|"redirects"| node_destination

click node_webui "https://github.com/karthikeyapolakonda/url-shortener/blob/main/frontend/app/page.tsx"
click node_dash "https://github.com/karthikeyapolakonda/url-shortener/blob/main/frontend/app/dashboard/page.tsx"
click node_stats "https://github.com/karthikeyapolakonda/url-shortener/blob/main/frontend/app/stats/%5Bcode%5D/page.tsx"
click node_history "https://github.com/karthikeyapolakonda/url-shortener/blob/main/frontend/lib/storage.ts"
click node_api_client "https://github.com/karthikeyapolakonda/url-shortener/blob/main/frontend/lib/api.ts"
click node_link_service "https://github.com/karthikeyapolakonda/url-shortener/blob/main/frontend/services/links.ts"
click node_auth_web "https://github.com/karthikeyapolakonda/url-shortener/blob/main/frontend/contexts/AuthContext.tsx"
click node_auth_service "https://github.com/karthikeyapolakonda/url-shortener/blob/main/frontend/services/auth.ts"
click node_api_app "https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/main.py"
click node_link_routes "https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/routers/links.py"
click node_redirect_route "https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/routers/redirect.py"
click node_auth_routes "https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/routers/auth.py"
click node_health_routes "https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/routers/health.py"
click node_schemas "https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/schemas.py"
click node_crud "https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/crud.py"
click node_security "https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/core/security.py"
click node_models "https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/models.py"
click node_database "https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/database.py"
click node_cache "https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/services/cache.py"
click node_analytics "https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/services/analytics.py"
click node_limiter "https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/services/rate_limit.py"
click node_redis "https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/services/redis_client.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_webui,node_dash,node_stats,node_history,node_api_client,node_link_service,node_auth_web,node_auth_service toneBlue
class node_api_app,node_link_routes,node_redirect_route,node_auth_routes,node_health_routes,node_schemas toneAmber
class node_crud,node_security,node_models toneMint
class node_database,node_cache,node_analytics,node_limiter,node_redis toneRose
class node_visitor,node_destination toneIndigo
```

## Components

### Web experience

- [Shortener UI](https://github.com/karthikeyapolakonda/url-shortener/blob/main/frontend/app/page.tsx): `frontend/app/page.tsx`
- [Dashboard](https://github.com/karthikeyapolakonda/url-shortener/blob/main/frontend/app/dashboard/page.tsx): `frontend/app/dashboard/page.tsx`
- [Link stats](https://github.com/karthikeyapolakonda/url-shortener/blob/main/frontend/app/stats/%5Bcode%5D/page.tsx): `frontend/app/stats/[code]/page.tsx`
- [Browser history](https://github.com/karthikeyapolakonda/url-shortener/blob/main/frontend/lib/storage.ts): `frontend/lib/storage.ts`
- [Fetch client](https://github.com/karthikeyapolakonda/url-shortener/blob/main/frontend/lib/api.ts): `frontend/lib/api.ts`
- [Link API service](https://github.com/karthikeyapolakonda/url-shortener/blob/main/frontend/services/links.ts): `frontend/services/links.ts`
- [Auth experience](https://github.com/karthikeyapolakonda/url-shortener/blob/main/frontend/contexts/AuthContext.tsx): `frontend/contexts/AuthContext.tsx`
- [Auth API service](https://github.com/karthikeyapolakonda/url-shortener/blob/main/frontend/services/auth.ts): `frontend/services/auth.ts`

### API surface

- [FastAPI app](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/main.py): `backend/app/main.py`
- [Link routes](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/routers/links.py): `backend/app/routers/links.py`
- [Redirect route](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/routers/redirect.py): `backend/app/routers/redirect.py`
- [Auth routes](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/routers/auth.py): `backend/app/routers/auth.py`
- [Health routes](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/routers/health.py): `backend/app/routers/health.py`
- [Request schemas](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/schemas.py): `backend/app/schemas.py`

### Identity and links

- [Link and user logic](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/crud.py): `backend/app/crud.py`
- [Token security](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/core/security.py): `backend/app/core/security.py`
- [Domain models](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/models.py): `backend/app/models.py`

### Runtime services

- [SQL database](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/database.py): `backend/app/database.py`
- [Link cache](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/services/cache.py): `backend/app/services/cache.py`
- [Click analytics](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/services/analytics.py): `backend/app/services/analytics.py`
- [Rate limiter](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/services/rate_limit.py): `backend/app/services/rate_limit.py`
- [Redis gateway](https://github.com/karthikeyapolakonda/url-shortener/blob/main/backend/app/services/redis_client.py): `backend/app/services/redis_client.py`

### Other components

- **Visitor**
- **Destination URL**

## Connections

- Visitor → Shortener UI: uses
- Shortener UI → Link API service: requests links
- Dashboard → Link API service: loads links
- Link stats → Link API service: loads stats
- Shortener UI → Browser history: stores codes
- Browser history → Link API service: refreshes stats
- Link API service → Fetch client: calls
- Fetch client → FastAPI app: HTTP requests
- Auth experience → Auth API service: auth requests
- Auth API service → Fetch client: uses
- FastAPI app → Link routes: registers (evidence: `backend/app/main.py`)
- FastAPI app → Redirect route: registers last (evidence: `backend/app/main.py`)
- FastAPI app → Auth routes: registers (evidence: `backend/app/main.py`)
- FastAPI app → Health routes: registers (evidence: `backend/app/main.py`)
- Link routes → Request schemas: validates and responds (evidence: `backend/app/routers/links.py`)
- Auth routes → Request schemas: validates and responds (evidence: `backend/app/routers/auth.py`)
- Link routes → Link and user logic: creates and manages (evidence: `backend/app/routers/links.py`)
- Redirect route → Link and user logic: looks up link (evidence: `backend/app/routers/redirect.py`)
- Auth routes → Link and user logic: manages users (evidence: `backend/app/routers/auth.py`)
- Auth routes → Token security: hashes and signs (evidence: `backend/app/routers/auth.py`)
- Link routes → Link cache: caches and invalidates (evidence: `backend/app/routers/links.py`)
- Redirect route → Link cache: reads cache (evidence: `backend/app/routers/redirect.py`)
- Redirect route → Click analytics: records clicks (evidence: `backend/app/routers/redirect.py`)
- Link routes → Rate limiter: checks limits (evidence: `backend/app/routers/links.py`)
- Auth routes → Rate limiter: checks limits (evidence: `backend/app/routers/auth.py`)
- Redirect route → Rate limiter: checks limits (evidence: `backend/app/routers/redirect.py`)
- Rate limiter → Redis gateway: increments counters (evidence: `backend/app/services/rate_limit.py`)
- Link and user logic → Domain models: queries and persists (evidence: `backend/app/crud.py`)
- Domain models → SQL database: maps to (evidence: `backend/app/models.py`)
- Health routes → SQL database: checks connection (evidence: `backend/app/routers/health.py`)
- FastAPI app → Redis gateway: closes on shutdown (evidence: `backend/app/main.py`)
- Redis gateway → Link cache: backs storage
- Redirect route → Destination URL: redirects
