A production-ready URL shortener API built with FastAPI, PostgreSQL, and SQLAlchemy. Designed for scalability, clean architecture, and real-world usage.
- Short URL generation (Base62)
- Fast redirection using indexed lookup
- User-based URL management (optional auth)
- Optional expiration support
- Collision-safe unique code generation
- PostgreSQL + SQLAlchemy ORM
- Clean modular architecture
- Docker-ready
- Backend: FastAPI
- Database: PostgreSQL
- ORM: SQLAlchemy
- Server: Uvicorn / Gunicorn
- Language: Python 3.13+
Requirements: Docker and Docker Compose installed
git clone https://github.com/ghanteyyy/URL-Shortner.git
cd URL-Shortnerdocker-compose up --buildThe backend will be avilable at:
http://localhost:8000/docker-compose downgit clone https://github.com/ghanteyyy/URL-Shortner.git
cd URL-Shortnerpython -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
Create a .env file
DATABASE_URL=postgresql://postgres:admin@localhost/fastapi_url_shortner
BASE_URL=http://localhost:8000
alembic upgrade head