A modern, containerized URL shortener service built with FastAPI, React, and PostgreSQL. This application allows users to create shortened URLs with optional custom paths and tracks usage statistics.
- Create shortened URLs with auto-generated or custom paths
- Track click statistics for each shortened URL
- Modern, responsive UI built with React and Tailwind CSS
- RESTful API with FastAPI
- Containerized deployment with Docker and Docker Compose
- Persistent storage with PostgreSQL
-
FastAPI: A modern, high-performance web framework for building APIs with Python. It provides automatic API documentation, request/response validation, and asynchronous support out of the box, making it ideal for building fast and reliable web services.
-
SQLAlchemy: A comprehensive database toolkit for Python that provides both a SQL abstraction layer (ORM) and a powerful query builder. As our ORM (Object-Relational Mapper), it allows us to work with database objects in a Pythonic way while maintaining fine-grained control over SQL performance.
-
PostgreSQL: Our chosen database system, known for its reliability, feature richness, and excellent performance with structured data. PostgreSQL excels at handling concurrent users and complex queries, making it perfect for storing URL mappings and tracking analytics.
-
Uvicorn: A lightning-fast ASGI (Asynchronous Server Gateway Interface) server implementation that powers our FastAPI application. It provides the production-grade server capabilities needed to handle concurrent requests efficiently, which is crucial for a URL shortening service that needs to process many redirects quickly.
-
React (18): A declarative JavaScript library for building user interfaces, providing powerful features like hooks and component-based architecture.
-
Vite: A modern frontend build tool that offers lightning-fast development server and optimized production builds.
-
Tailwind CSS: A highly customizable, low-level CSS framework that enables rapid UI development through utility classes.
-
Lucide Icons: A comprehensive icon library that provides consistent, high-quality SVG icons.
- Docker
- PostgreSQL 16
Before starting, ensure you have:
- Docker for containerized deployment
- Node.js runtime (version 18+) to run the development tools for the React/Vite frontend
- Python 3.9 or higher for backend development
-
Clone the repository:
git clone https://github.com/vib795/tiny-url-code-challenge.git cd tiny-url-code-challenge
-
Create environment files:
Example file
Backend (.env in backend directory):POSTGRES_USER=postgres POSTGRES_PASSWORD=postgres POSTGRES_DB=postgres POSTGRES_DB_NAME=urlshortener POSTGRES_APP_USER=urlshortener_user POSTGRES_APP_PASSWORD=your_secure_password DATABASE_URL=postgresql://urlshortener_user:your_secure_password@postgres:5432/urlshortener
Frontend (.env in frontend directory):
VITE_API_URL=http://localhost:8000
-
Start the application:
docker compose --env-file ./backend/.env up --build
-
Access the application:
- Frontend: http://localhost:5173
- Backend API: http://localhost:8000
- API Documentation: http://localhost:8000/docs
-
Navigate to the backend directory:
cd backend
-
Create a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: .\venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Run the development server:
python main.py
-
Navigate to the frontend directory:
cd frontend
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
-
POST /shorten
: Create a shortened URL- Request body:
{"url": "https://example.com", "custom_path": "optional-custom-path"}
- Request body:
-
GET /{short_url}
: Redirect to original URL -
GET /stats/{short_url}
: Get URL statistics -
GET /health
: Service health check
- Fork the repository
- Create your feature branch:
git checkout -b feature/my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin feature/my-new-feature
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details
This project was built as part of the Coding Challenges (https://codingchallenges.fyi/challenges/challenge-url-shortener)