How shivanand9019/url-shortener-system works
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: UrlServiceImpl.java URL service · UrlController.java URL API controller · UrlshortenerApplication.java Spring Boot app · UrlRepository.java URL repository
Components 17
Client delivery
- Vite entry
frontend/src/main.jsx - URL dashboard · Submission and analytics experience.
frontend/src/App.jsx - Vite build
frontend/vite.config.js - Packaged static page · Separate backend-served asset path.
src/main/resources/static/index.html
Spring backend
- Spring Boot app
src/main/java/com/backend/url/shortener/UrlshortenerApplication.java - URL API controller · Owns shorten, redirect, and analytics routes.
src/main/java/com/backend/url/shortener/controller/UrlController.java - Shorten request
src/main/java/com/backend/url/shortener/dto/UrlRequest.java - Analytics response
src/main/java/com/backend/url/shortener/dto/AnalyticsResponse.java - URL service contract
src/main/java/com/backend/url/shortener/service/UrlService.java - URL service · Generates codes, tracks clicks, and assembles analytics.
src/main/java/com/backend/url/shortener/service/UrlServiceImpl.java
Persistence
- URL mapping · Stores original URL, short code, clicks, and creation metadata.
src/main/java/com/backend/url/shortener/model/UrlMapping.java - URL repository
src/main/java/com/backend/url/shortener/repository/UrlRepository.java - PostgreSQL
Runtime
- Spring configuration · Contains database and runtime settings.
src/main/resources/application.properties - Maven build
pom.xml - Container image
Dockerfile - Render deployment
Connections 19
- 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