|
| 1 | +<h1 align="center">🔗 FastAPI URL Shortener</h1> |
| 2 | + |
| 3 | +<p align="center"> |
| 4 | +A high-performance, Dockerized URL Shortener API built with <strong>FastAPI</strong>, <strong>PostgreSQL</strong>, and <strong>Docker</strong>, deployed using <strong>GitHub Actions</strong> and <strong>AWS EC2</strong> with full CI/CD automation. |
| 5 | +</p> |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +<p align="center"> |
| 10 | + <img src="https://github.com/lyushher/fastapi-url-shortener/actions/workflows/deploy.yml/badge.svg" /> |
| 11 | + <img src="https://img.shields.io/badge/FastAPI-⚡-green" /> |
| 12 | + <img src="https://img.shields.io/badge/Database-PostgreSQL-blue" /> |
| 13 | + <img src="https://img.shields.io/badge/platform-ubuntu-lightgrey" /> |
| 14 | +</p> |
| 15 | +<p align="center"> |
| 16 | + <img src="https://img.shields.io/badge/Dockerized-Yes-blue?logo=docker" /> |
| 17 | + <img src="https://img.shields.io/badge/python-3.11+-blue" /> |
| 18 | + <img src="https://img.shields.io/docker/image-size/firdevsakbayir/urlshortener/latest" /> |
| 19 | +</p> |
| 20 | +<p align="center"> |
| 21 | + <img src="https://img.shields.io/github/license/lyushher/fastapi-url-shortener?color=yellow" /> |
| 22 | +</p> |
| 23 | + |
| 24 | +--- |
| 25 | + |
| 26 | +## 🌐 Project Overview |
| 27 | + |
| 28 | +This is a production-ready **URL Shortener API** designed for performance and scalability. |
| 29 | +It allows users to: |
| 30 | + |
| 31 | +- Convert long URLs into short, shareable links |
| 32 | +- Redirect users to original destinations using the short code |
| 33 | +- Easily integrate into frontend apps, internal tools, or public services |
| 34 | + |
| 35 | +Whether you're building a microservice architecture or a personal project, |
| 36 | +this API is optimized for **speed, modularity, and real-world deployment**. |
| 37 | + |
| 38 | +--- |
| 39 | + |
| 40 | +## 🛠️ Tech Stack |
| 41 | + |
| 42 | +This project is built using modern and scalable technologies to ensure high performance, reliability, and maintainability: |
| 43 | + |
| 44 | +- **🚀 Backend Framework:** [FastAPI](https://fastapi.tiangolo.com/) – A modern, high-performance web framework for building APIs with Python 3.11+ based on standard Python type hints. |
| 45 | +- **🐘 Database:** [PostgreSQL](https://www.postgresql.org/) – A powerful, production-grade relational database system used for persistent URL storage. |
| 46 | +- **🐳 Containerization:** [Docker](https://www.docker.com/) & [Docker Compose](https://docs.docker.com/compose/) – For building, packaging, and running the app in isolated environments, ensuring platform consistency. |
| 47 | +- **⚙️ CI/CD Automation:** [GitHub Actions](https://github.com/features/actions) – Automated build, test, and deployment pipeline triggered on code push to `main`. |
| 48 | +- **☁️ Deployment Target:** [AWS EC2 (Ubuntu 22.04)](https://aws.amazon.com/ec2/) – Cloud infrastructure hosting the application, with port `8000` publicly exposed for API access. |
| 49 | +- **🔐 Secure Access:** SSH key-based authentication ensures safe and authorized deployments to the cloud server. |
| 50 | +- **📦 Package Management:** `pip` with a clean `requirements.txt` for dependency management. |
| 51 | + |
| 52 | +--- |
| 53 | + |
| 54 | +## 📈 Features |
| 55 | + |
| 56 | +- ✅ Shortens long URLs with customizable short codes |
| 57 | +- ✅ Redirects to original URL using short code |
| 58 | +- ✅ Generates random short codes if none is provided |
| 59 | +- ✅ Fully Dockerized for consistent builds |
| 60 | +- ✅ PostgreSQL for persistent, scalable storage |
| 61 | +- ✅ Clean, modular architecture for maintainability |
| 62 | +- ✅ One-click deployment to AWS via GitHub Actions |
| 63 | + |
| 64 | +## 🔐 Security & Authentication |
| 65 | + |
| 66 | +> ℹ️ Note: This project does not implement authentication or rate limiting. |
| 67 | +If deployed in a public environment, consider adding access control or usage limits to prevent abuse. |
| 68 | + |
| 69 | +--- |
| 70 | + |
| 71 | +## 📡 API Endpoints |
| 72 | + |
| 73 | +| Method | Route | Description | |
| 74 | +|--------|---------------|-------------------------------| |
| 75 | +| POST | `/shorten` | Shorten a long URL | |
| 76 | +| GET | `/{shortcode}`| Redirect to original URL | |
| 77 | +| GET | `/urls` | (Optional) List all URLs | |
| 78 | +| DELETE | `/{shortcode}`| (Optional) Delete a short URL | |
| 79 | + |
| 80 | + |
| 81 | +### Swagger UI Preview |
| 82 | + |
| 83 | +You can explore the live API docs here: |
| 84 | +👉 [http://16.171.2.202:8001/docs](http://16.171.2.202:8001/docs) |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +## ⚙️ Setup & Local Development |
| 89 | + |
| 90 | +```bash |
| 91 | +# Clone repository |
| 92 | +git clone https://github.com/lyushher/fastapi-url-shortener.git |
| 93 | +cd fastapi-url-shortener |
| 94 | + |
| 95 | +# Start services locally |
| 96 | +docker compose up --build |
| 97 | + |
| 98 | +``` |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +## 🔁 CI/CD Pipeline |
| 103 | + |
| 104 | +This project follows a fully automated CI/CD process using GitHub Actions: |
| 105 | + |
| 106 | +1. **Push to `main`**: Every code change merged into the main branch triggers the pipeline. |
| 107 | +2. **Build & Test**: GitHub Actions builds the Docker image and runs tests to ensure stability. |
| 108 | +3. **SSH into EC2**: Secure connection is established to the production EC2 instance. |
| 109 | +4. **Pull Latest Code**: The latest codebase is pulled from the GitHub repository. |
| 110 | +5. **Rebuild Docker Container**: The container is rebuilt to reflect the new changes. |
| 111 | +6. **Restart Application**: The old container is gracefully stopped and replaced with the new version. |
| 112 | + |
| 113 | +--- |
| 114 | + |
| 115 | +## ⚠️ Known Limitations |
| 116 | + |
| 117 | +Even though the service is production-ready, the current version includes the following constraints: |
| 118 | + |
| 119 | +- ❌ No user authentication or API key validation |
| 120 | +- ❌ No analytics or click tracking system |
| 121 | +- ❌ No expiration or time-to-live (TTL) feature for short URLs |
| 122 | +- ❌ No support for custom domains (e.g., yourdomain.com/xyz) |
| 123 | +- ❌ No frontend interface – this is a pure backend API |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +## 📄 License |
| 128 | + |
| 129 | +This project is licensed under the [MIT License](LICENSE). |
| 130 | + |
0 commit comments