οΏ½ Try the live application: https://springboot-react-app-production.up.railway.app/
The application is deployed on Railway and ready to use!
οΏ½ Try the live application: https://springboot-react-app-production.up.railway.app/
The application is deployed on Railway and ready to use!
This is a complete URL Shortener application built for the Full Stack Engineer assignment. It demonstrates:
- Backend: Java Spring Boot with REST API
- Frontend: React/HTML with modern UI
- Database: H2 (in-memory) with JPA
- Features: URL shortening, redirection, expiration (5 minutes)
- Deployment: Live on Railway platform
Before you begin, ensure you have the following installed on your system:
- Java 17 or higher - Download here
- Git - Download here
- Node.js and npm (Optional - only for React development) - Download here
# Clone the repository
git clone https://github.com/Srinivas-Mundlamuri/react-spring-boot-app.git
# Navigate to the project directory
cd react-spring-boot-appChoose one of the following options to run the application:
The application comes with pre-built React files already integrated into the Spring Boot server.
# Navigate to server directory
cd server
# Run the application (this includes both frontend and backend)
./mvnw spring-boot:runβ That's it! Open your browser and go to http://localhost:7070
If you want to build the React frontend from source and sync it with the server:
# 1. Build the React frontend
cd client
npm install
npm run build
# 2. Sync the build with server (go back to project root)
cd ..
rm -rf server/src/main/resources/static/*
cp -r client/build/* server/src/main/resources/static/
# 3. Run the Spring Boot server
cd server
./mvnw spring-boot:runβ Application running at: http://localhost:7070
For development with hot reload:
# Terminal 1: Start the backend server
cd server
./mvnw spring-boot:run
# Backend runs at http://localhost:7070
# Terminal 2: Start React development server
cd client
npm install
npm start
# Frontend runs at http://localhost:3000Option A: Try the Live Version
- β Visit the live application: https://springboot-react-app-production.up.railway.app/
- β
Enter a URL:
https://www.google.com - β Click "Shorten URL"
- β
Copy the generated short URL (e.g.,
https://springboot-react-app-production.up.railway.app/r/abc123) - β Open the short URL in a new tab β It redirects to Google! π
Option B: Run Locally
- β Ensure the backend is running on port 7070
- β
Open your browser and go to
http://localhost:7070 - β
Enter a URL:
https://www.google.com - β Click "Shorten URL"
- β
Copy the generated short URL (e.g.,
http://localhost:7070/r/abc123) - β Open the short URL in a new tab β It redirects to Google! π
Test all the available features (replace with live URL if testing production):
Live API Base URL: https://springboot-react-app-production.up.railway.app
Local API Base URL: http://localhost:7070
# Live version
curl -X POST https://springboot-react-app-production.up.railway.app/api/url/shorten \
-H "Content-Type: application/json" \
-d '{"url": "https://www.google.com"}'
# Local version
curl -X POST http://localhost:7070/api/url/shorten \
-H "Content-Type: application/json" \
-d '{"url": "https://www.google.com"}'Response:
{"shortUrl":"https://springboot-react-app-production.up.railway.app/r/abc123"}# Live version
curl https://springboot-react-app-production.up.railway.app/api/url/history
# Local version
curl http://localhost:7070/api/url/historyResponse:
[
{
"original": "https://www.google.com",
"shortCode": "abc123",
"shortUrl": "http://localhost:7070/r/abc123",
"createdAt": "2025-08-06T13:55:00Z",
"isExpired": false,
"expiresIn": 4
}
]curl -I http://localhost:7070/r/abc123Response (if not expired):
HTTP/1.1 302
Location: https://www.google.comResponse (if expired):
HTTP/1.1 400
Content-Type: text/htmlcurl -X DELETE http://localhost:7070/api/url/delete/abc123Response:
{"message": "URL deleted successfully"}curl http://localhost:7070/api/url/testResponse:
{"message": "API is working!", "timestamp": "2025-08-06T13:55:00Z"}# Test non-existent URL
curl -I http://localhost:7070/r/nonexistent
# Test expired URL (wait 5+ minutes after creation)
curl -I http://localhost:7070/r/abc123
# Test invalid URL creation
curl -X POST http://localhost:7070/api/url/shorten \
-H "Content-Type: application/json" \
-d '{"url": "invalid-url"}'react-spring-boot-app/
βββ client/ # React Frontend
β βββ public/
β β βββ index.html # Main HTML template
β β βββ ... # Static assets
β βββ src/
β β βββ App.js # Main React component
β β βββ App.css # Styles
β β βββ index.js # React entry point
β βββ build/ # Built React app (auto-generated)
β βββ package.json # Frontend dependencies
β
βββ server/ # Spring Boot Backend
β βββ src/main/java/com/assignment/project/
β β βββ controller/
β β β βββ UrlShortenerController.java # API endpoints
β β β βββ RedirectController.java # Redirect handling
β β βββ model/
β β β βββ UrlMapping.java # JPA Entity
β β βββ repository/
β β β βββ UrlMappingRepository.java # Data access layer
β β βββ service/
β β β βββ UrlShortenerService.java # Business logic
β β βββ ProjectApplication.java # Main Spring Boot class
β βββ src/main/resources/
β β βββ application.properties # Configuration
β β βββ static/ # Served React build files
β βββ target/ # Built JAR files
β βββ pom.xml # Backend dependencies
β βββ Procfile # Railway deployment config
β βββ railway.json # Railway project config
β βββ system.properties # Java version for deployment
β
βββ README.md # This file
βββ DEPLOYMENT.md # Deployment instructions
- URL Creation: Create short URLs from long URLs with validation
- URL Validation: Ensures URLs start with http:// or https://
- URL History/Fetch: View all created URLs with status and expiration info
- URL Deletion: Delete unwanted short URLs from the system
- Duplicate Prevention: Returns existing short URL for same original URL
- Expiration Handling: Links expire after 5 minutes for security
- Expired URL Detection: Shows expiration status and time remaining
- Not Found Handling: Proper error messages for non-existent URLs
- Random Code Generation: 8-character alphanumeric codes
- Database Persistence: H2 in-memory database with JPA
- Copy to Clipboard: Easy sharing of shortened URLs
- Real-time Status: Shows if URLs are active or expired
| Method | Endpoint | Description | Response |
|---|---|---|---|
| GET | / |
Serve React frontend | HTML page |
| POST | /api/url/shorten |
Create short URL | {"shortUrl": "http://localhost:7070/r/abc123"} |
| GET | /api/url/history |
Fetch all URLs with status | Array of URL objects with expiration info |
| DELETE | /api/url/delete/{shortCode} |
Delete a short URL | {"message": "URL deleted successfully"} |
| GET | /r/{shortCode} |
Redirect to original URL | 302 redirect or error page |
| GET | /api/url/{shortCode} |
Get original URL (API) | 302 redirect or error message |
| GET | /api/url/test |
Test API connectivity | {"message": "API is working!"} |
- URLs automatically expire after 5 minutes
- Expired URLs show friendly error page with navigation back to app
- History shows expiration status and time remaining
- Error message: "β° Link Expired - This short URL has expired after 5 minutes for security reasons."
- Non-existent short codes return 404 with error page
- Error message: "π Short URL Not Found - The requested short URL does not exist."
- Provides navigation back to create new URLs
- Input validation prevents invalid URL formats
- Only accepts URLs starting with
http://orhttps:// - Real-time validation feedback in the UI
- Spring Boot 2.5.5
- Spring Data JPA
- H2 Database
- React 18 (for frontend)
CREATE TABLE url_mappings (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
original_url VARCHAR(2048) NOT NULL,
short_code VARCHAR(16) NOT NULL UNIQUE,
created_at TIMESTAMP NOT NULL
);The application features:
- Clean, modern design with gradient backgrounds and animations
- URL Input & Validation with real-time feedback
- One-click URL shortening with loading indicators
- Copy to clipboard functionality for easy sharing
- URL History Dashboard showing all created URLs
- Expiration Status with countdown timers
- Delete URLs with confirmation dialogs
- Responsive design that works on mobile and desktop
- Error handling with clear, user-friendly messages
- Professional color scheme with intuitive icons
- Real-time updates when URLs are created or deleted
- Duplicate detection alerts for existing URLs
- Status indicators (Active/Expired) for each URL
- URL Creation: Enter any valid URL and get a shortened version instantly
- URL Management: View, copy, and delete your shortened URLs
- History Tracking: See all URLs you've created with timestamps
- Expiration Monitoring: Visual indicators show when URLs will expire
- Error Prevention: Input validation prevents invalid URL submission
- User Feedback: Success/error messages for all actions
- Accessibility: Keyboard navigation and screen reader support
- URL Validation: Only accepts valid HTTP/HTTPS URLs
- Time-based Expiration: Links expire after 5 minutes
- Input Sanitization: Prevents XSS attacks
- CORS Configuration: Proper cross-origin handling
Input: https://www.google.com
Output: http://localhost:7070/xY9kLm2n
Input: https://www.example.com/very/long/path/with/parameters?id=123&name=test
Output: http://localhost:7070/pQ7rT4vW
Issue: "Port 7070 already in use"
# Kill process using port 7070
lsof -ti:7070 | xargs kill -9Issue: "Java not found"
- Make sure Java 17+ is installed
- Check with:
java -version - Download from: https://adoptium.net/
Issue: "npm not found"
- Install Node.js from: https://nodejs.org/
- Or skip React development and use the pre-built version
Issue: React build not reflecting changes
# Rebuild and sync
cd client && npm run build
cd .. && rm -rf server/src/main/resources/static/*
cp -r client/build/* server/src/main/resources/static/
cd server && ./mvnw spring-boot:run# Check Java version
java -version
# Check if application is running
curl http://localhost:7070
# Check API endpoint
curl -X POST http://localhost:7070/api/url/shorten \
-H "Content-Type: application/json" \
-d '{"url": "https://www.google.com"}'- UI for URL input - Beautiful React/HTML interface
- Generate short URL - 8-character random codes
- Redirect functionality - Works seamlessly
- Example working - Google.com β localhost:7070/code β Google.com
- Code Quality - Clean, modular, well-documented
- End-user Experience - Professional UI/UX
- Technology Stack - Java, Spring Boot, React, H2 Database
- URL Creation - Generate short URLs with validation
- URL Deletion - Remove unwanted URLs with confirmation
- URL History/Fetch - View all created URLs with status
- Duplicate Detection - Reuses existing short URLs for same original URL
- Link Expiration - 5-minute security timeout with countdown
- Expired URL Handling - Friendly error pages for expired links
- Not Found Handling - 404 error pages for non-existent URLs
- Real-time Status - Shows active/expired status for all URLs
- Copy to Clipboard - One-click sharing functionality
- Error Handling - Comprehensive error messages and validation
- Loading States - Visual feedback during operations
- Confirmation Dialogs - Prevent accidental deletions
- Responsive Design - Mobile-friendly interface
- Professional UI - Modern design with animations
- Input Validation - Real-time URL format checking
- Status Indicators - Visual cues for URL states
- Production Ready - Railway deployment configuration
- API Testing - Comprehensive endpoint testing
- Error Recovery - Graceful handling of all error scenarios
- Database Management - Efficient CRUD operations
π Ready to use! The application is production-ready with comprehensive features and deployment configuration.
Technologies Used: Java, Spring Boot, React, H2 Database, HTML5, CSS3, JavaScript ES6+