# swoggoi/url-shorter architecture

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

- Interactive diagram: https://gitdiagram.com/swoggoi/url-shorter
- Repository: https://github.com/swoggoi/url-shorter

## Overview

This repository is structured as a URL-shortening service with URL and user domain models, service interfaces, HTTP transport, and PostgreSQL/Redis repository implementations. The apparent workflow is HTTP requests through transport and services to storage, but the sampled transport and operation files do not expose those calls, and main is empty; those connections are therefore omitted. The graph preserves the visible service/domain and DTO/domain relationships, plus the distinct rate-limit component, without claiming unshown wiring.

Main entry points: [`internal/domain/url.go`](https://github.com/swoggoi/url-shorter/blob/main/internal/domain/url.go) (URL model), [`internal/domain/user.go`](https://github.com/swoggoi/url-shorter/blob/main/internal/domain/user.go) (User model), [`internal/errors/errors.go`](https://github.com/swoggoi/url-shorter/blob/main/internal/errors/errors.go) (Domain errors), [`internal/transport/http/url/dto_common.go`](https://github.com/swoggoi/url-shorter/blob/main/internal/transport/http/url/dto_common.go) (URL DTO mapping)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_transport["HTTP transport"]
  node_http_url["URL transport<br/>[transport.go]"]
  node_url_dto["URL DTO mapping<br/>[dto_common.go]"]
end

subgraph group_services["Domain services"]
  node_url_service["URL service"]
  node_user_service["User service"]
end

subgraph group_domain["Domain models"]
  node_url_domain["URL model<br/>[url.go]"]
  node_user_domain["User model<br/>[user.go]"]
  node_domain_errors["Domain errors<br/>[errors.go]"]
end

subgraph group_storage["Persistence and cache"]
  node_url_pg["URL PostgreSQL repository"]
  node_user_pg["User PostgreSQL repository"]
  node_url_cache["URL Redis repository"]
  node_user_cache["User Redis repository"]
  node_url_rate_limit["URL rate limiting<br/>[redis.go]"]
end

node_client(("HTTP client"))

node_url_service -->|"uses types"| node_url_domain
node_user_service -->|"uses types"| node_user_domain
node_url_dto -->|"maps from"| node_url_domain
node_url_domain -->|"returns errors"| node_domain_errors
node_user_domain -->|"returns errors"| node_domain_errors

click node_http_url "https://github.com/swoggoi/url-shorter/blob/main/internal/transport/http/url/transport.go"
click node_url_dto "https://github.com/swoggoi/url-shorter/blob/main/internal/transport/http/url/dto_common.go"
click node_url_service "https://github.com/swoggoi/url-shorter/tree/main/internal/service/url"
click node_user_service "https://github.com/swoggoi/url-shorter/tree/main/internal/service/user"
click node_url_domain "https://github.com/swoggoi/url-shorter/blob/main/internal/domain/url.go"
click node_user_domain "https://github.com/swoggoi/url-shorter/blob/main/internal/domain/user.go"
click node_domain_errors "https://github.com/swoggoi/url-shorter/blob/main/internal/errors/errors.go"
click node_url_pg "https://github.com/swoggoi/url-shorter/tree/main/internal/repository/url/postgres"
click node_user_pg "https://github.com/swoggoi/url-shorter/tree/main/internal/repository/user/postgres"
click node_url_cache "https://github.com/swoggoi/url-shorter/tree/main/internal/repository/url/redis"
click node_user_cache "https://github.com/swoggoi/url-shorter/tree/main/internal/repository/user/redis"
click node_url_rate_limit "https://github.com/swoggoi/url-shorter/blob/main/internal/repository/url/ratelimit/redis.go"

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_http_url,node_url_dto,node_client toneBlue
class node_url_service,node_user_service toneAmber
class node_url_domain,node_user_domain,node_domain_errors toneMint
class node_url_pg,node_user_pg,node_url_cache,node_user_cache,node_url_rate_limit toneRose
```

## Components

### HTTP transport

- [URL transport](https://github.com/swoggoi/url-shorter/blob/main/internal/transport/http/url/transport.go): `internal/transport/http/url/transport.go`
- [URL DTO mapping](https://github.com/swoggoi/url-shorter/blob/main/internal/transport/http/url/dto_common.go): `internal/transport/http/url/dto_common.go`

### Domain services

- [URL service](https://github.com/swoggoi/url-shorter/tree/main/internal/service/url): `internal/service/url`
- [User service](https://github.com/swoggoi/url-shorter/tree/main/internal/service/user): `internal/service/user`

### Domain models

- [URL model](https://github.com/swoggoi/url-shorter/blob/main/internal/domain/url.go): `internal/domain/url.go`
- [User model](https://github.com/swoggoi/url-shorter/blob/main/internal/domain/user.go): `internal/domain/user.go`
- [Domain errors](https://github.com/swoggoi/url-shorter/blob/main/internal/errors/errors.go): `internal/errors/errors.go`

### Persistence and cache

- [URL PostgreSQL repository](https://github.com/swoggoi/url-shorter/tree/main/internal/repository/url/postgres): `internal/repository/url/postgres`
- [User PostgreSQL repository](https://github.com/swoggoi/url-shorter/tree/main/internal/repository/user/postgres): `internal/repository/user/postgres`
- [URL Redis repository](https://github.com/swoggoi/url-shorter/tree/main/internal/repository/url/redis): `internal/repository/url/redis`
- [User Redis repository](https://github.com/swoggoi/url-shorter/tree/main/internal/repository/user/redis): `internal/repository/user/redis`
- [URL rate limiting](https://github.com/swoggoi/url-shorter/blob/main/internal/repository/url/ratelimit/redis.go): `internal/repository/url/ratelimit/redis.go`

### Other components

- **HTTP client**

## Connections

- URL service → URL model: uses types (evidence: `internal/service/url/service.go`)
- User service → User model: uses types (evidence: `internal/service/user/service.go`)
- URL DTO mapping → URL model: maps from (evidence: `internal/transport/http/url/dto_common.go`)
- URL model → Domain errors: returns errors (evidence: `internal/domain/url.go`)
- User model → Domain errors: returns errors (evidence: `internal/domain/user.go`)
