A simple URL shortening web application built with Flask.
Supports web-browsers and cli (e.g. curl) for shortening URLs.
- Shorten long URLs to shorter ones
- Redirect shortened URLs to the original long URLs
- Simple and user-friendly web interface
- CLI support for URL shortening
- QR code generation for shortened URLs
$ curl "http://localhost:8088/shortener?url-string=https://example.com"In this scenario the application looks for User-Agent header to determine the type of client. CLI clients (like curl) currently supported are:
curlhttpiewget
Alternatively, you can explicitly request CLI output by requesting shortener-cli path:
$ curl "http://localhost:8088/shortener-cli?url-string=https://example.com"The application is built using the Flask web framework and packed with Docker and docker-compose for easy deployment.
shortener_flask_app/: Main Flask application codeapp/: Application packageroutes.py: Defines the web routes and their handlersmodels.py: Database models for storing URLsutils.py: Utility functionsdatabase.py: Database setupcache.py: Caching setupconsts.py: Application constants
static/: Static files (CSS, JS, images)main.css: Main stylesheet
templates/: HTML templatesindex.html: Main page templateshortened.html: Shortened URL display template
tests/: Unit and integration tests for the applicationconfig.py: Application configurationfactory.py: Application factorygunicorn_cfg.py: Gunicorn configuration for production deployment__main__.py: Entry point for running the application with uv
Dockerfile: Dockerfile for building the application imagecompose.yml: Docker Compose configuration for running the application and all its other components (database, cache, proxy)README.md: This readme filedocs/: Documentation files and diagramsnginx.conf: Nginx configuration file for reverse proxy.python-version: Python version file for pyenvexample.env: Example environment variables fileuv.lock: uv lock file for dependenciespyproject.toml: uv configuration file for dependencies.gitignore: Git ignore file
There are two ways to run the application: using Docker and docker compose or running it locally with Python and uv.
- Make sure you have Docker/podman and Docker Compose/podman compose installed on your machine.
- Prepare env file. See
example.envfor reference. You need to have the files:web.env- for the Flask applicationdb.env- for the databasecache.env- for the Redis cache
- Run the following command to start the application:
docker-compose upThe application will be accessible at http://localhost:8088.
- Make sure you have Python 3.14+ installed on your machine.
- Install dependencies using uv:
uv sync- Export the necessary environment variables. You can use the
example.envfile as a reference. But in this case you, probably, want to set the following variables as it shown:
- unset or remove
DATABASE_URIso by default it will use a sqlite database (sqlite:///app.dbin the application folder) CACHE_OPTIONS="SimpleCache"- to use simple in-memory cache instead of Redis
- Run the Flask application using uv:
uv run shortener_flask_appThe application will be accessible at http://localhost:8088.


