# dunkrick/url-shortener architecture

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

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

## Overview

Nip shortens submitted URLs, redirects visitors, and reports an aggregate redirect count. The browser app submits URLs and polls statistics through a shared API client; the Go API uses PostgreSQL for mappings and Redis for redirect caching, creation limits, and the total count. The README documents the backend storage behavior and API routes, but backend implementation excerpts were not provided, so backend relationships rely on README evidence rather than inspected handler code.

Main entry points: [`frontend/src/App.tsx`](https://github.com/dunkrick/url-shortener/blob/main/frontend/src/App.tsx) (Shortener app), [`main.go`](https://github.com/dunkrick/url-shortener/blob/main/main.go) (Go HTTP API), [`frontend/src/lib/api-client.ts`](https://github.com/dunkrick/url-shortener/blob/main/frontend/src/lib/api-client.ts) (HTTP client), [`init.sql`](https://github.com/dunkrick/url-shortener/blob/main/init.sql) (URL mappings)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web application"]
  node_app["Shortener app<br/>[App.tsx]"]
  node_form["URL form<br/>[UrlForm.tsx]"]
  node_result["Link result<br/>[ShortUrlResult.tsx]"]
  node_shorten_hook["Shorten state<br/>[useShortenUrl.ts]"]
  node_shorten_api["Shorten API<br/>[api.ts]"]
  node_stats_hook["Stats polling<br/>[useStats.ts]"]
  node_stats_api["Stats API<br/>[api.ts]"]
  node_client["HTTP client<br/>[api-client.ts]"]
  node_api_config["API configuration<br/>[env.ts]"]
end

subgraph group_api["Go API"]
  node_server["Go HTTP API<br/>[main.go]"]
  node_create["URL creation<br/>[main.go]"]
  node_redirect["Redirect resolution<br/>[main.go]"]
  node_rate_limit["Creation rate limit<br/>[main.go]"]
  node_stats["Redirect statistics<br/>[main.go]"]
end

subgraph group_state["Persistence and cache"]
  node_mappings[("URL mappings<br/>[init.sql]")]
  node_redis[("Redis state")]
  node_postgres[("PostgreSQL")]
end

node_visitor(("Link visitor"))
node_browser(("Browser user"))
node_redis_service[("Redis service")]

node_browser -->|"uses"| node_app
node_app -->|"renders"| node_form
node_app -->|"renders"| node_result
node_app -->|"uses"| node_shorten_hook
node_app -->|"uses"| node_stats_hook
node_shorten_hook -->|"calls"| node_shorten_api
node_stats_hook -->|"polls"| node_stats_api
node_shorten_api -->|"calls"| node_client
node_stats_api -->|"calls"| node_client
node_client -->|"reads"| node_api_config
node_client -->|"requests"| node_server
node_visitor -->|"requests code"| node_redirect
node_server -->|"routes"| node_create
node_server -->|"routes"| node_redirect
node_server -->|"routes"| node_stats
node_create -->|"applies"| node_rate_limit
node_create -->|"stores mapping"| node_mappings
node_redirect -->|"checks cache"| node_redis
node_redirect -->|"reads on miss"| node_mappings
node_stats -->|"reads count"| node_redis
node_rate_limit -->|"uses limits"| node_redis
node_mappings -->|"stored in"| node_postgres
node_redis -->|"uses"| node_redis_service

click node_app "https://github.com/dunkrick/url-shortener/blob/main/frontend/src/App.tsx"
click node_form "https://github.com/dunkrick/url-shortener/blob/main/frontend/src/components/UrlForm.tsx"
click node_result "https://github.com/dunkrick/url-shortener/blob/main/frontend/src/components/ShortUrlResult.tsx"
click node_shorten_hook "https://github.com/dunkrick/url-shortener/blob/main/frontend/src/features/shorten/useShortenUrl.ts"
click node_shorten_api "https://github.com/dunkrick/url-shortener/blob/main/frontend/src/features/shorten/api.ts"
click node_stats_hook "https://github.com/dunkrick/url-shortener/blob/main/frontend/src/features/stats/useStats.ts"
click node_stats_api "https://github.com/dunkrick/url-shortener/blob/main/frontend/src/features/stats/api.ts"
click node_client "https://github.com/dunkrick/url-shortener/blob/main/frontend/src/lib/api-client.ts"
click node_api_config "https://github.com/dunkrick/url-shortener/blob/main/frontend/src/config/env.ts"
click node_server "https://github.com/dunkrick/url-shortener/blob/main/main.go"
click node_create "https://github.com/dunkrick/url-shortener/blob/main/main.go"
click node_redirect "https://github.com/dunkrick/url-shortener/blob/main/main.go"
click node_rate_limit "https://github.com/dunkrick/url-shortener/blob/main/main.go"
click node_stats "https://github.com/dunkrick/url-shortener/blob/main/main.go"
click node_mappings "https://github.com/dunkrick/url-shortener/blob/main/init.sql"

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_app,node_form,node_result,node_shorten_hook,node_shorten_api,node_stats_hook,node_stats_api,node_client,node_api_config,node_browser toneBlue
class node_server,node_create,node_redirect,node_rate_limit,node_stats,node_redis_service toneAmber
class node_mappings,node_redis,node_postgres toneMint
class node_visitor toneIndigo
```

## Components

### Web application

- [Shortener app](https://github.com/dunkrick/url-shortener/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [URL form](https://github.com/dunkrick/url-shortener/blob/main/frontend/src/components/UrlForm.tsx): `frontend/src/components/UrlForm.tsx`
- [Link result](https://github.com/dunkrick/url-shortener/blob/main/frontend/src/components/ShortUrlResult.tsx): `frontend/src/components/ShortUrlResult.tsx`
- [Shorten state](https://github.com/dunkrick/url-shortener/blob/main/frontend/src/features/shorten/useShortenUrl.ts): `frontend/src/features/shorten/useShortenUrl.ts`
- [Shorten API](https://github.com/dunkrick/url-shortener/blob/main/frontend/src/features/shorten/api.ts): `frontend/src/features/shorten/api.ts`
- [Stats polling](https://github.com/dunkrick/url-shortener/blob/main/frontend/src/features/stats/useStats.ts): `frontend/src/features/stats/useStats.ts`
- [Stats API](https://github.com/dunkrick/url-shortener/blob/main/frontend/src/features/stats/api.ts): `frontend/src/features/stats/api.ts`
- [HTTP client](https://github.com/dunkrick/url-shortener/blob/main/frontend/src/lib/api-client.ts): `frontend/src/lib/api-client.ts`
- [API configuration](https://github.com/dunkrick/url-shortener/blob/main/frontend/src/config/env.ts): `frontend/src/config/env.ts`

### Go API

- [Go HTTP API](https://github.com/dunkrick/url-shortener/blob/main/main.go): `main.go`
- [URL creation](https://github.com/dunkrick/url-shortener/blob/main/main.go): `main.go`
- [Redirect resolution](https://github.com/dunkrick/url-shortener/blob/main/main.go): `main.go`
- [Creation rate limit](https://github.com/dunkrick/url-shortener/blob/main/main.go): `main.go`
- [Redirect statistics](https://github.com/dunkrick/url-shortener/blob/main/main.go): `main.go`

### Persistence and cache

- [URL mappings](https://github.com/dunkrick/url-shortener/blob/main/init.sql): `init.sql`
- **Redis state**
- **PostgreSQL**

### Other components

- **Link visitor**
- **Browser user**
- **Redis service**

## Connections

- Browser user → Shortener app: uses (evidence: `frontend/src/App.tsx`)
- Shortener app → URL form: renders (evidence: `frontend/src/App.tsx`)
- Shortener app → Link result: renders (evidence: `frontend/src/App.tsx`)
- Shortener app → Shorten state: uses (evidence: `frontend/src/App.tsx`)
- Shortener app → Stats polling: uses (evidence: `frontend/src/App.tsx`)
- Shorten state → Shorten API: calls (evidence: `frontend/src/features/shorten/useShortenUrl.ts`)
- Stats polling → Stats API: polls (evidence: `frontend/src/features/stats/useStats.ts`)
- Shorten API → HTTP client: calls (evidence: `frontend/src/features/shorten/api.ts`)
- Stats API → HTTP client: calls (evidence: `frontend/src/features/stats/api.ts`)
- HTTP client → API configuration: reads (evidence: `frontend/src/lib/api-client.ts`)
- HTTP client → Go HTTP API: requests (evidence: `README.md`)
- Link visitor → Redirect resolution: requests code (evidence: `README.md`)
- Go HTTP API → URL creation: routes (evidence: `README.md`)
- Go HTTP API → Redirect resolution: routes (evidence: `README.md`)
- Go HTTP API → Redirect statistics: routes (evidence: `README.md`)
- URL creation → Creation rate limit: applies (evidence: `README.md`)
- URL creation → URL mappings: stores mapping (evidence: `README.md`)
- Redirect resolution → Redis state: checks cache (evidence: `README.md`)
- Redirect resolution → URL mappings: reads on miss (evidence: `README.md`)
- Redirect statistics → Redis state: reads count (evidence: `README.md`)
- Creation rate limit → Redis state: uses limits (evidence: `README.md`)
- URL mappings → PostgreSQL: stored in (evidence: `README.md`)
- Redis state → Redis service: uses (evidence: `README.md`)
