# prashanthart/url-shortener architecture

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

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

## Overview

This is a URL-shortening application: users submit a URL with an optional alias and expiry, receive a short link, and follow that link to redirect to the original. The graph shows the frontend request path and backend creation and redirect paths, including URL validation, code generation, persistence, and expiry checks. README material was not supplied; additional capability claims are therefore limited to the source index and excerpts. Some relationships to unsampled DTO, configuration, and error-handling code are not expanded.

Main entry points: [`backend/src/main/java/com/prashanth/urlshortener/service/UrlService.java`](https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/service/UrlService.java) (URL service), [`frontend/src/App.jsx`](https://github.com/prashanthart/url-shortener/blob/master/frontend/src/App.jsx) (App state), [`backend/src/main/java/com/prashanth/urlshortener/controller/UrlController.java`](https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/controller/UrlController.java) (Create endpoint), [`backend/src/main/java/com/prashanth/urlshortener/controller/RedirectController.java`](https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/controller/RedirectController.java) (Redirect endpoint)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Link interface"]
  node_form["Shorten form<br/>[ShorturlForm.jsx]"]
  node_app["App state<br/>[App.jsx]"]
  node_api_client["API client<br/>[urlApi.js]"]
  node_result["Short-link result<br/>[ShortUrlResult.jsx]"]
end

subgraph group_api["HTTP entry points"]
  node_api_handler["Create endpoint<br/>[UrlController.java]"]
  node_redirect_handler["Redirect endpoint"]
  node_error_handler["Error responses"]
end

subgraph group_domain["Short-link domain"]
  node_url_service["URL service<br/>[UrlService.java]"]
  node_validator["URL validator<br/>[UrlValidator.java]"]
  node_counter_service["Sequence counter"]
  node_base62["Base62 encoder<br/>[Base62.java]"]
end

subgraph group_storage["Persistence"]
  node_mapping["URL mapping<br/>[UrlMapping.java]"]
  node_repository[("Mapping repository")]
  node_counter_store[("Counter store<br/>[Counter.java]")]
end

node_user(("Link user"))

node_user -->|"enters link"| node_form
node_form -->|"submits fields"| node_app
node_app -->|"requests shortening"| node_api_client
node_api_client -->|"posts request"| node_api_handler
node_api_handler -->|"creates link"| node_url_service
node_url_service -->|"validates URL"| node_validator
node_url_service -->|"gets sequence"| node_counter_service
node_url_service -->|"encodes code"| node_base62
node_url_service -->|"saves mapping"| node_repository
node_repository -->|"stores records"| node_mapping
node_counter_service -->|"increments sequence"| node_counter_store
node_api_handler -.->|"formats errors"| node_error_handler
node_app -->|"renders result"| node_result
node_result -->|"shows short link"| node_user
node_user -.->|"opens short link"| node_redirect_handler
node_redirect_handler -->|"resolves code"| node_url_service
node_url_service -->|"looks up mapping"| node_repository
node_redirect_handler -->|"redirects browser"| node_user

click node_form "https://github.com/prashanthart/url-shortener/blob/master/frontend/src/components/ShorturlForm.jsx"
click node_app "https://github.com/prashanthart/url-shortener/blob/master/frontend/src/App.jsx"
click node_api_client "https://github.com/prashanthart/url-shortener/blob/master/frontend/src/apis/urlApi.js"
click node_result "https://github.com/prashanthart/url-shortener/blob/master/frontend/src/components/ShortUrlResult.jsx"
click node_api_handler "https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/controller/UrlController.java"
click node_redirect_handler "https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/controller/RedirectController.java"
click node_url_service "https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/service/UrlService.java"
click node_validator "https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/validation/UrlValidator.java"
click node_counter_service "https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/service/CounterService.java"
click node_base62 "https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/util/Base62.java"
click node_mapping "https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/modal/UrlMapping.java"
click node_repository "https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/repository/UrlMappingRepository.java"
click node_counter_store "https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/modal/Counter.java"
click node_error_handler "https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/exception/GlobalExceptionHandler.java"

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_form,node_app,node_api_client,node_result,node_user toneBlue
class node_api_handler,node_redirect_handler,node_error_handler toneAmber
class node_url_service,node_validator,node_counter_service,node_base62 toneMint
class node_mapping,node_repository,node_counter_store toneRose
```

## Components

### Link interface

- [Shorten form](https://github.com/prashanthart/url-shortener/blob/master/frontend/src/components/ShorturlForm.jsx): `frontend/src/components/ShorturlForm.jsx`
- [App state](https://github.com/prashanthart/url-shortener/blob/master/frontend/src/App.jsx): `frontend/src/App.jsx`
- [API client](https://github.com/prashanthart/url-shortener/blob/master/frontend/src/apis/urlApi.js): `frontend/src/apis/urlApi.js`
- [Short-link result](https://github.com/prashanthart/url-shortener/blob/master/frontend/src/components/ShortUrlResult.jsx): `frontend/src/components/ShortUrlResult.jsx`

### HTTP entry points

- [Create endpoint](https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/controller/UrlController.java): `backend/src/main/java/com/prashanth/urlshortener/controller/UrlController.java`
- [Redirect endpoint](https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/controller/RedirectController.java): `backend/src/main/java/com/prashanth/urlshortener/controller/RedirectController.java`
- [Error responses](https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/exception/GlobalExceptionHandler.java): `backend/src/main/java/com/prashanth/urlshortener/exception/GlobalExceptionHandler.java`

### Short-link domain

- [URL service](https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/service/UrlService.java): `backend/src/main/java/com/prashanth/urlshortener/service/UrlService.java`
- [URL validator](https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/validation/UrlValidator.java): `backend/src/main/java/com/prashanth/urlshortener/validation/UrlValidator.java`
- [Sequence counter](https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/service/CounterService.java): `backend/src/main/java/com/prashanth/urlshortener/service/CounterService.java`
- [Base62 encoder](https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/util/Base62.java): `backend/src/main/java/com/prashanth/urlshortener/util/Base62.java`

### Persistence

- [URL mapping](https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/modal/UrlMapping.java): `backend/src/main/java/com/prashanth/urlshortener/modal/UrlMapping.java`
- [Mapping repository](https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/repository/UrlMappingRepository.java): `backend/src/main/java/com/prashanth/urlshortener/repository/UrlMappingRepository.java`
- [Counter store](https://github.com/prashanthart/url-shortener/blob/master/backend/src/main/java/com/prashanth/urlshortener/modal/Counter.java): `backend/src/main/java/com/prashanth/urlshortener/modal/Counter.java`

### Other components

- **Link user**

## Connections

- Link user → Shorten form: enters link (evidence: `frontend/src/components/ShorturlForm.jsx`)
- Shorten form → App state: submits fields (evidence: `frontend/src/App.jsx`)
- App state → API client: requests shortening (evidence: `frontend/src/App.jsx`)
- API client → Create endpoint: posts request (evidence: `frontend/src/apis/urlApi.js`)
- Create endpoint → URL service: creates link (evidence: `backend/src/main/java/com/prashanth/urlshortener/controller/UrlController.java`)
- URL service → URL validator: validates URL (evidence: `backend/src/main/java/com/prashanth/urlshortener/service/UrlService.java`)
- URL service → Sequence counter: gets sequence (evidence: `backend/src/main/java/com/prashanth/urlshortener/service/UrlService.java`)
- URL service → Base62 encoder: encodes code (evidence: `backend/src/main/java/com/prashanth/urlshortener/service/UrlService.java`)
- URL service → Mapping repository: saves mapping (evidence: `backend/src/main/java/com/prashanth/urlshortener/service/UrlService.java`)
- Mapping repository → URL mapping: stores records (evidence: `backend/src/main/java/com/prashanth/urlshortener/repository/UrlMappingRepository.java`)
- Sequence counter → Counter store: increments sequence (evidence: `backend/src/main/java/com/prashanth/urlshortener/service/CounterService.java`)
- Create endpoint → Error responses: formats errors
- App state → Short-link result: renders result (evidence: `frontend/src/App.jsx`)
- Short-link result → Link user: shows short link (evidence: `frontend/src/components/ShortUrlResult.jsx`)
- Link user → Redirect endpoint: opens short link
- Redirect endpoint → URL service: resolves code (evidence: `backend/src/main/java/com/prashanth/urlshortener/controller/RedirectController.java`)
- URL service → Mapping repository: looks up mapping (evidence: `backend/src/main/java/com/prashanth/urlshortener/service/UrlService.java`)
- Redirect endpoint → Link user: redirects browser (evidence: `backend/src/main/java/com/prashanth/urlshortener/controller/RedirectController.java`)
