Back to All Projects
Problem Statement
Long URLs are hard to share, remember, and paste cleanly into messages and documents. This project explores how a lightweight link-shortening service works, from validating input to redirecting visitors, using a simple web stack.
Proposed Solution
The app accepts a long URL through a web form, validates it, and generates a unique random short code. The code and original URL are stored in SQLite, and the app returns a shareable short link. Opening that link triggers a Flask route that looks up the code and redirects to the original destination.
Key Features
- URL input form with validation for empty or malformed submissions.
- Random short-code generation with a uniqueness check before saving.
- SQLite storage of original URL and short-code pairs.
- Redirect from a short link to the original URL.
- Result page showing the generated short link next to the original URL.
- Friendly 404 page when a short code does not exist.
System Architecture Flow
Browser (index page) -> Flask routes and validation (app.py) -> SQLite database (database.py) -> Short code generated and saved -> Redirect route looks up the code -> Browser opens the original URL
Engineering Challenges
- Two URLs could end up with the same short code, so the app keeps generating a new random code until it finds one that is not already stored.
- Invalid submissions needed to be blocked before saving, so empty values and URLs that do not start with http:// or https:// are rejected.
- Unknown short links should not crash the app, so the redirect route returns a 404 page instead of a server error.
Lessons Learned
- Separating request handling, validation, and database operations into clear modules in a Flask app.
- Implementing redirect logic and unique code generation for link-based systems.
- Using templates to handle success and error states cleanly.
Results
Built as a self-learning project to practice Flask, SQLite, and request validation fundamentals.