# shivanand9019/url-shortener-system architecture

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

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

## Overview

#### Purpose and Entry Points
This is a URL-shortening service: it creates short codes for original URLs, redirects short-code requests, and exposes click analytics. The Spring Boot process starts at `src/main/java/com/backend/url/shortener/UrlshortenerApplication.java`. Its HTTP API is implemented in `src/main/java/com/backend/url/shortener/controller/UrlController.java`.

A separate Vite/React frontend is entered through `frontend/src/main.jsx` and rendered by `frontend/src/App.jsx`. Spring also contains a packaged static entry point at `src/main/resources/static/index.html`.

#### HTTP API Boundary
`UrlController` is the transport boundary for the three documented operations:
- create mapping: `POST /api/shorten`
- resolve and redirect: `GET /s/{shortCode}`
- retrieve analytics: `GET /analytics/{shortCode}`

Request and response shapes are isolated in DTOs:
- `src/main/java/com/backend/url/shortener/dto/UrlRequest.java`
- `src/main/java/com/backend/url/shortener/dto/AnalyticsResponse.java`

#### URL Mapping Domain
The persistent domain record is `src/main/java/com/backend/url/shortener/model/UrlMapping.java`. It represents the original URL, generated short code, click count, and creation metadata needed by redirects and analytics.

The key business boundary is the service abstraction:
- `src/main/java/com/backend/url/shortener/service/UrlService.java`
- `src/main/java/com/backend/url/shortener/service/UrlServiceImpl.java`

Controllers should delegate creation, lookup, click tracking, and analytics assembly to this layer rather than operate on persistence entities directly.

#### Redirect and Analytics Flow
For shortening, the controller accepts `UrlRequest`, the service generates a short code and persists a `UrlMapping`, then returns the resulting shortened link/data.

For a short-code visit, the controller resolves the mapping through the service, increments its click count, and issues an HTTP redirect to the stored original URL. For analytics, the same mapping is read and converted into `AnalyticsResponse`, separating API output from the database entity.

#### Persistence and Infrastructure
Persistence is repository-driven through `src/main/java/com/backend/url/shortener/repository/UrlRepository.java`, with PostgreSQL identified as the backing database. Spring configuration, including database/runtime settings, is in `src/main/resources/application.properties`.

The backend is Maven-based (`pom.xml`) and containerizable through `Dockerfile`. The README identifies Render as the deployment target and provides a deployed service URL.

#### Client Delivery
The active source frontend is a React application built with Vite:
- `frontend/src/App.jsx`
- `frontend/src/main.jsx`
- `frontend/vite.config.js`

It is responsible for the URL submission and analytics dashboard experience and consumes the Spring API. `src/main/resources/static/index.html` provides a separate backend-served static asset path; integration/deployment must determine whether the Vite build is copied into Spring static resources or hosted independently.

#### Architectural Constraints and Extension Points
The system is a compact layered application: frontend/client → REST controller → service → JPA repository → PostgreSQL. Redirect handling is the highest-volume path because it performs both lookup and click mutation. Future additions named by the project—custom aliases, expiration, caching, and rate limiting—belong primarily in the service and persistence boundaries, with cache/rate-limit infrastructure placed before or alongside redirect resolution.

Main entry points: [`src/main/java/com/backend/url/shortener/service/UrlServiceImpl.java`](https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/service/UrlServiceImpl.java) (URL service), [`src/main/java/com/backend/url/shortener/controller/UrlController.java`](https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/controller/UrlController.java) (URL API controller), [`src/main/java/com/backend/url/shortener/UrlshortenerApplication.java`](https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/UrlshortenerApplication.java) (Spring Boot app), [`src/main/java/com/backend/url/shortener/repository/UrlRepository.java`](https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/repository/UrlRepository.java) (URL repository)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Client delivery"]
  node_react_entry["Vite entry<br/>React entry<br/>[main.jsx]"]
  node_react_app["URL dashboard<br/>React app<br/>[App.jsx]"]
  node_vite_config["Vite build<br/>build config<br/>[vite.config.js]"]
  node_static_index["Packaged static page<br/>static entry<br/>[index.html]"]
end

subgraph group_backend["Spring backend"]
  node_spring_entry["Spring Boot app<br/>application entry"]
  node_url_controller["URL API controller<br/>REST controller<br/>[UrlController.java]"]
  node_url_request["Shorten request<br/>DTO<br/>[UrlRequest.java]"]
  node_analytics_response["Analytics response<br/>DTO"]
  node_url_service["URL service contract<br/>service interface<br/>[UrlService.java]"]
  node_url_service_impl["URL service<br/>business service"]
end

subgraph group_data["Persistence"]
  node_url_mapping["URL mapping<br/>JPA entity<br/>[UrlMapping.java]"]
  node_url_repository["URL repository<br/>JPA repository<br/>[UrlRepository.java]"]
  node_postgres[("PostgreSQL<br/>database")]
end

subgraph group_ops["Runtime"]
  node_app_properties["Spring configuration<br/>runtime config"]
  node_maven_build["Maven build<br/>build definition<br/>[pom.xml]"]
  node_docker_image["Container image<br/>container build"]
  node_render{{"Render deployment<br/>hosting platform"}}
end

node_react_entry -->|"renders"| node_react_app
node_vite_config -->|"builds"| node_react_entry
node_react_app -->|"calls API"| node_url_controller
node_spring_entry -->|"registers"| node_url_controller
node_url_controller -->|"accepts"| node_url_request
node_url_controller -->|"returns"| node_analytics_response
node_url_controller -->|"delegates"| node_url_service
node_url_service -->|"implemented by"| node_url_service_impl
node_url_service_impl -->|"persists and resolves"| node_url_repository
node_url_service_impl -->|"creates and updates"| node_url_mapping
node_url_repository -->|"manages"| node_url_mapping
node_url_repository -->|"reads and writes"| node_postgres
node_url_service_impl -->|"assembles"| node_analytics_response
node_url_service_impl -.->|"increments on redirect"| node_url_mapping
node_app_properties -->|"configures"| node_spring_entry
node_maven_build -->|"packages"| node_spring_entry
node_docker_image -->|"builds"| node_maven_build
node_render -->|"runs"| node_docker_image
node_spring_entry -.->|"serves"| node_static_index

click node_react_entry "https://github.com/shivanand9019/url-shortener-system/blob/master/frontend/src/main.jsx"
click node_react_app "https://github.com/shivanand9019/url-shortener-system/blob/master/frontend/src/App.jsx"
click node_vite_config "https://github.com/shivanand9019/url-shortener-system/blob/master/frontend/vite.config.js"
click node_spring_entry "https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/UrlshortenerApplication.java"
click node_url_controller "https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/controller/UrlController.java"
click node_url_request "https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/dto/UrlRequest.java"
click node_analytics_response "https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/dto/AnalyticsResponse.java"
click node_url_service "https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/service/UrlService.java"
click node_url_service_impl "https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/service/UrlServiceImpl.java"
click node_url_mapping "https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/model/UrlMapping.java"
click node_url_repository "https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/repository/UrlRepository.java"
click node_static_index "https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/resources/static/index.html"
click node_app_properties "https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/resources/application.properties"
click node_maven_build "https://github.com/shivanand9019/url-shortener-system/blob/master/pom.xml"
click node_docker_image "https://github.com/shivanand9019/url-shortener-system/blob/master/Dockerfile"

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_react_entry,node_react_app,node_vite_config,node_static_index toneBlue
class node_spring_entry,node_url_controller,node_url_request,node_analytics_response,node_url_service,node_url_service_impl toneAmber
class node_url_mapping,node_url_repository,node_postgres toneMint
class node_app_properties,node_maven_build,node_docker_image,node_render toneRose
```

## Components

### Client delivery

- [Vite entry](https://github.com/shivanand9019/url-shortener-system/blob/master/frontend/src/main.jsx): React entry · `frontend/src/main.jsx`
- [URL dashboard](https://github.com/shivanand9019/url-shortener-system/blob/master/frontend/src/App.jsx): React app · Submission and analytics experience. · `frontend/src/App.jsx`
- [Vite build](https://github.com/shivanand9019/url-shortener-system/blob/master/frontend/vite.config.js): build config · `frontend/vite.config.js`
- [Packaged static page](https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/resources/static/index.html): static entry · Separate backend-served asset path. · `src/main/resources/static/index.html`

### Spring backend

- [Spring Boot app](https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/UrlshortenerApplication.java): application entry · `src/main/java/com/backend/url/shortener/UrlshortenerApplication.java`
- [URL API controller](https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/controller/UrlController.java): REST controller · Owns shorten, redirect, and analytics routes. · `src/main/java/com/backend/url/shortener/controller/UrlController.java`
- [Shorten request](https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/dto/UrlRequest.java): DTO · `src/main/java/com/backend/url/shortener/dto/UrlRequest.java`
- [Analytics response](https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/dto/AnalyticsResponse.java): DTO · `src/main/java/com/backend/url/shortener/dto/AnalyticsResponse.java`
- [URL service contract](https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/service/UrlService.java): service interface · `src/main/java/com/backend/url/shortener/service/UrlService.java`
- [URL service](https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/service/UrlServiceImpl.java): business service · Generates codes, tracks clicks, and assembles analytics. · `src/main/java/com/backend/url/shortener/service/UrlServiceImpl.java`

### Persistence

- [URL mapping](https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/model/UrlMapping.java): JPA entity · Stores original URL, short code, clicks, and creation metadata. · `src/main/java/com/backend/url/shortener/model/UrlMapping.java`
- [URL repository](https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/java/com/backend/url/shortener/repository/UrlRepository.java): JPA repository · `src/main/java/com/backend/url/shortener/repository/UrlRepository.java`
- **PostgreSQL**: database

### Runtime

- [Spring configuration](https://github.com/shivanand9019/url-shortener-system/blob/master/src/main/resources/application.properties): runtime config · Contains database and runtime settings. · `src/main/resources/application.properties`
- [Maven build](https://github.com/shivanand9019/url-shortener-system/blob/master/pom.xml): build definition · `pom.xml`
- [Container image](https://github.com/shivanand9019/url-shortener-system/blob/master/Dockerfile): container build · `Dockerfile`
- **Render deployment**: hosting platform

## Connections

- Vite entry → URL dashboard: renders
- Vite build → Vite entry: builds
- URL dashboard → URL API controller: calls API
- Spring Boot app → URL API controller: registers
- URL API controller → Shorten request: accepts
- URL API controller → Analytics response: returns
- URL API controller → URL service contract: delegates
- URL service contract → URL service: implemented by
- URL service → URL repository: persists and resolves
- URL service → URL mapping: creates and updates
- URL repository → URL mapping: manages
- URL repository → PostgreSQL: reads and writes
- URL service → Analytics response: assembles
- URL service → URL mapping: increments on redirect · Redirect lookup mutates click count.
- Spring configuration → Spring Boot app: configures
- Maven build → Spring Boot app: packages
- Container image → Maven build: builds
- Render deployment → Container image: runs
- Spring Boot app → Packaged static page: serves
