# izenberk/url-shortener-api architecture

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

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

## Overview

This Go/Fiber service creates expiring short links and redirects requests for them, using Redis for link mappings and per-IP quotas. The main workflow is POST creation: validate input, enforce quota, generate or accept a code, and store the mapping; GET resolves the code and returns a redirect. It also serves embedded Swagger UI and an OpenAPI contract. The README documents the broader behavior; unsampled routing details are omitted where wiring is uncertain.

Main entry points: [`main.go`](https://github.com/izenberk/url-shortener-api/blob/main/main.go) (Fiber app), [`internal/handlers/shorten.go`](https://github.com/izenberk/url-shortener-api/blob/main/internal/handlers/shorten.go) (Create link), [`internal/database/database.go`](https://github.com/izenberk/url-shortener-api/blob/main/internal/database/database.go) (Redis DB 1), [`internal/handlers/resolve.go`](https://github.com/izenberk/url-shortener-api/blob/main/internal/handlers/resolve.go) (Resolve redirect)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API runtime"]
  node_app["Fiber app<br/>[main.go]"]
  node_middleware["Logging and CORS<br/>[main.go]"]
end

subgraph group_links["Link workflow"]
  node_shorten["Create link<br/>[shorten.go]"]
  node_validate["Request validation<br/>[validation.go]"]
  node_generate["Code generation<br/>[shorten.go]"]
  node_resolve["Resolve redirect<br/>[resolve.go]"]
  node_urlhelper["URL formatting<br/>[url.go]"]
end

subgraph group_state["Redis state"]
  node_dbinit["Redis clients<br/>[database.go]"]
  node_linksdb[("Redis DB 0<br/>[database.go]")]
  node_quotadb[("Redis DB 1<br/>[database.go]")]
end

subgraph group_documentation["API documentation"]
  node_docs["Docs routes<br/>[docs.go]"]
  node_swagger["Swagger UI assets<br/>[index.html]"]
  node_spec["OpenAPI contract<br/>[openapi.yaml]"]
end

node_client(("API client"))
node_browser(("Browser"))

node_client -->|"HTTP requests"| node_app
node_browser -->|"HTTP requests"| node_app
node_app -->|"applies"| node_middleware
node_app -->|"initializes"| node_dbinit
node_app -->|"dispatches POST"| node_shorten
node_app -->|"dispatches GET"| node_resolve
node_app -->|"registers routes"| node_docs
node_shorten -->|"validates input"| node_validate
node_shorten -->|"checks quota"| node_quotadb
node_shorten -->|"generates code"| node_generate
node_shorten -->|"stores mapping"| node_linksdb
node_shorten -->|"updates quota"| node_quotadb
node_shorten -->|"formats link"| node_urlhelper
node_resolve -->|"looks up code"| node_linksdb
node_resolve -->|"increments counter"| node_quotadb
node_dbinit -->|"connects"| node_linksdb
node_dbinit -->|"connects"| node_quotadb
node_docs -->|"serves"| node_swagger
node_docs -->|"serves"| node_spec
node_swagger -->|"loads contract"| node_spec
node_app -->|"returns creation result"| node_client
node_app -->|"returns redirect"| node_browser

click node_app "https://github.com/izenberk/url-shortener-api/blob/main/main.go"
click node_middleware "https://github.com/izenberk/url-shortener-api/blob/main/main.go"
click node_shorten "https://github.com/izenberk/url-shortener-api/blob/main/internal/handlers/shorten.go"
click node_validate "https://github.com/izenberk/url-shortener-api/blob/main/internal/validation/validation.go"
click node_generate "https://github.com/izenberk/url-shortener-api/blob/main/internal/handlers/shorten.go"
click node_resolve "https://github.com/izenberk/url-shortener-api/blob/main/internal/handlers/resolve.go"
click node_urlhelper "https://github.com/izenberk/url-shortener-api/blob/main/internal/handlers/url.go"
click node_dbinit "https://github.com/izenberk/url-shortener-api/blob/main/internal/database/database.go"
click node_linksdb "https://github.com/izenberk/url-shortener-api/blob/main/internal/database/database.go"
click node_quotadb "https://github.com/izenberk/url-shortener-api/blob/main/internal/database/database.go"
click node_docs "https://github.com/izenberk/url-shortener-api/blob/main/docs.go"
click node_swagger "https://github.com/izenberk/url-shortener-api/blob/main/docs/index.html"
click node_spec "https://github.com/izenberk/url-shortener-api/blob/main/openapi.yaml"

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_middleware,node_client,node_browser toneBlue
class node_shorten,node_validate,node_generate,node_resolve,node_urlhelper toneAmber
class node_dbinit,node_linksdb,node_quotadb toneMint
class node_docs,node_swagger,node_spec toneRose
```

## Components

### API runtime

- [Fiber app](https://github.com/izenberk/url-shortener-api/blob/main/main.go): `main.go`
- [Logging and CORS](https://github.com/izenberk/url-shortener-api/blob/main/main.go): `main.go`

### Link workflow

- [Create link](https://github.com/izenberk/url-shortener-api/blob/main/internal/handlers/shorten.go): `internal/handlers/shorten.go`
- [Request validation](https://github.com/izenberk/url-shortener-api/blob/main/internal/validation/validation.go): `internal/validation/validation.go`
- [Code generation](https://github.com/izenberk/url-shortener-api/blob/main/internal/handlers/shorten.go): `internal/handlers/shorten.go`
- [Resolve redirect](https://github.com/izenberk/url-shortener-api/blob/main/internal/handlers/resolve.go): `internal/handlers/resolve.go`
- [URL formatting](https://github.com/izenberk/url-shortener-api/blob/main/internal/handlers/url.go): `internal/handlers/url.go`

### Redis state

- [Redis clients](https://github.com/izenberk/url-shortener-api/blob/main/internal/database/database.go): `internal/database/database.go`
- [Redis DB 0](https://github.com/izenberk/url-shortener-api/blob/main/internal/database/database.go): `internal/database/database.go`
- [Redis DB 1](https://github.com/izenberk/url-shortener-api/blob/main/internal/database/database.go): `internal/database/database.go`

### API documentation

- [Docs routes](https://github.com/izenberk/url-shortener-api/blob/main/docs.go): `docs.go`
- [Swagger UI assets](https://github.com/izenberk/url-shortener-api/blob/main/docs/index.html): `docs/index.html`
- [OpenAPI contract](https://github.com/izenberk/url-shortener-api/blob/main/openapi.yaml): `openapi.yaml`

### Other components

- **API client**
- **Browser**

## Connections

- API client → Fiber app: HTTP requests
- Browser → Fiber app: HTTP requests
- Fiber app → Logging and CORS: applies
- Fiber app → Redis clients: initializes
- Fiber app → Create link: dispatches POST
- Fiber app → Resolve redirect: dispatches GET
- Fiber app → Docs routes: registers routes
- Create link → Request validation: validates input
- Create link → Redis DB 1: checks quota
- Create link → Code generation: generates code
- Create link → Redis DB 0: stores mapping
- Create link → Redis DB 1: updates quota
- Create link → URL formatting: formats link
- Resolve redirect → Redis DB 0: looks up code
- Resolve redirect → Redis DB 1: increments counter
- Redis clients → Redis DB 0: connects
- Redis clients → Redis DB 1: connects
- Docs routes → Swagger UI assets: serves
- Docs routes → OpenAPI contract: serves
- Swagger UI assets → OpenAPI contract: loads contract
- Fiber app → API client: returns creation result
- Fiber app → Browser: returns redirect
