How sujan58/url_shortner works
Purpose and Shape
This repository implements a URL-shortening system with a static browser client and a Java/Spring Boot backend. The backend owns URL creation, lookup, persistence, redirect behavior, and error translation; the frontend provides the user-facing interaction.
Entry Points
• Backend Spring Boot bootstrap: version1/src/main/java/com/url_shortner/version1/Version1Application.java
• Backend HTTP boundary: version1/src/main/java/com/url_shortner/version1/Controller/URLController.java
• Static frontend entry document and behavior: url_shortener_frontend/index.html, url_shortener_frontend/script.js
• Frontend presentation: url_shortener_frontend/style.css
HTTP/API Layer
URLController is the API/redirect ingress layer. It should accept browser or client requests, bind request DTOs, invoke the service layer, and return response DTOs or redirect results.
• version1/src/main/java/com/url_shortner/version1/Controller/URLController.java
• version1/src/main/java/com/url_shortner/version1/Model/URLRequestDTO.java
• version1/src/main/java/com/url_shortner/version1/Model/URLResponseDTO.java
The static frontend is separate from the Spring Boot source tree, so deployment must explicitly serve it independently or configure a host/proxy for backend API access.
URL Shortening Domain and Service Flow
URLService is the central application layer. The expected primary flow is: client submits an original URL → controller passes a request DTO to the service → service creates or resolves a shortened identifier → persistence stores/retrieves the mapping → response DTO returns the shortened URL. Resolution follows the reverse direction for redirects.
• version1/src/main/java/com/url_shortner/version1/Service/URLService.java
• version1/src/main/java/com/url_shortner/version1/Model/URLDetails.java
• version1/src/main/java/com/url_shortner/version1/Model/URLResponseDTO.java
URLDetails is the persisted domain representation; DTOs separate external request/response contracts from storage state.
Persistence Boundary
URLRepository is the data-access boundary used by the service. It abstracts the database operations required to save URL mappings and find them during redirect resolution.
• version1/src/main/java/com/url_shortner/version1/Repository/URLRepository.java
• version1/src/main/java/com/url_shortner/version1/Model/URLDetails.java
• version1/src/main/resources/application.properties
The concrete database/provider is configured outside Java code through application.properties; pom.xml determines the Spring persistence/runtime dependencies.
Error and Missing-Link Handling
Missing short codes and other application failures are centralized rather than handled ad hoc in controllers.
• version1/src/main/java/com/url_shortner/version1/Exception/NotFoundHandler.java
• version1/src/main/java/com/url_shortner/version1/Exception/GlobalExceptionHandler.java
• version1/src/main/java/com/url_shortner/version1/Controller/URLController.java
This boundary should convert service/repository failures into stable HTTP responses and prevent persistence exceptions from leaking to frontend consumers.
Runtime and Build Infrastructure
The backend is a Maven-wrapped Java/Spring Boot application, launched through its application class or Maven wrapper. Runtime configuration is externalized in Spring properties.
• version1/pom.xml
• version1/mvnw
• version1/src/main/resources/application.properties
The frontend is plain static HTML/CSS/JavaScript with no visible package-manager or bundler layer.
Main entry points: URLController.java URL Controller · URLService.java URL Service · index.html HTML Client · pom.xml Maven Runtime
Components 16
Static Frontend
Independently hosted browser client.
- Browser User
- HTML Client
url_shortener_frontend/index.html - Client Behavior · Submits URLs and consumes API responses.
url_shortener_frontend/script.js - Presentation
url_shortener_frontend/style.css
Spring Boot Backend
- Spring Boot Bootstrap
version1/src/main/java/com/url_shortner/version1/Version1Application.java - URL Controller
version1/src/main/java/com/url_shortner/version1/Controller/URLController.java - URL Request DTO
version1/src/main/java/com/url_shortner/version1/Model/URLRequestDTO.java - URL Response DTO
version1/src/main/java/com/url_shortner/version1/Model/URLResponseDTO.java - URL Service · Creates mappings and resolves short codes.
version1/src/main/java/com/url_shortner/version1/Service/URLService.java - Global Error Handling · Translates failures into stable HTTP responses.
version1/src/main/java/com/url_shortner/version1/Exception/GlobalExceptionHandler.java - Missing Link Handler
version1/src/main/java/com/url_shortner/version1/Exception/NotFoundHandler.java - Maven Runtime
version1/pom.xml - Maven Wrapper
version1/mvnw
Persistence
- URL Repository
version1/src/main/java/com/url_shortner/version1/Repository/URLRepository.java - URL Details · Stores the original URL and shortened identifier mapping.
version1/src/main/java/com/url_shortner/version1/Model/URLDetails.java - Configured Database · Provider and connection are externalized in Spring properties.
version1/src/main/resources/application.properties
Connections 19
- Browser User → HTML Client: loads
- HTML Client → Client Behavior: runs
- HTML Client → Presentation: styles with
- Client Behavior → URL Controller: API requests · Requires explicit cross-host serving or proxy configuration.
- Browser User → URL Controller: follows short URL
- Maven Wrapper → Maven Runtime: invokes
- Maven Runtime → Spring Boot Bootstrap: builds and launches
- Spring Boot Bootstrap → URL Controller: registers
- URL Controller → URL Request DTO: binds
- URL Controller → URL Service: creates or resolves
- URL Service → URL Response DTO: produces
- URL Controller → URL Response DTO: returns
- URL Service → URL Repository: saves and finds mappings
- URL Repository → URL Details: maps
- URL Repository → Configured Database: persists
- Maven Runtime → Configured Database: configures provider dependencies
- URL Controller → Global Error Handling: routes failures
- URL Service → Missing Link Handler: signals missing code
- Missing Link Handler → Global Error Handling: handled by