A production-ready FastAPI application with JWT authentication and URL shortening capabilities, built with async support and capability to generate user-friendly URLs.
- ✅ User registration and authentication (JWT)
- ✅ URL shortening with custom short codes
- ✅ Public URL redirection (no auth required)
- ✅ Click tracking and analytics
- ✅ User-specific URL management
- ✅ Pagination support
- ✅ Filtering support
- ✅ Async/await throughout the application
- ✅ SQLite with async support (aiosqlite)
- ✅ Password hashing with bcrypt
- ✅ CORS support
- Python 3.11+
- Poetry
# Install dependencies
poetry install
# Copy environment file
cp .env.example .env
# Run the server
poetry run uvicorn app.main:app --reload
# Visit http://localhost:8000/docsPOST /api/v1/auth/signup- Register new userPOST /api/v1/auth/login- Login and get JWT tokenPOST /api/v1/auth/logout- Logout userGET /api/v1/auth/me- Get current user info
POST /api/v1/urls- Create shortened URLGET /api/v1/urls- Get all user URLs (paginated)GET /api/v1/urls/{short_code}- Get URL detailsGET /api/v1/urls/{short_code}/resolve- Get resolved URLGET /api/v1/urls/{short_code}/stats- Get URL statisticsPATCH /api/v1/urls/{short_code}- Update URLDELETE /api/v1/urls/{short_code}- Delete URL
- Users can specify their preferred short code (e.g., "my-link")
- If available, the custom code is used
- If taken, a random code is generated automatically
- Validation: 3-50 characters, alphanumeric + hyphens/underscores
- Default: 6-character random alphanumeric
- Excludes confusing characters (0, O, I, l)
- Collision detection with automatic retry
- Automatic click counting on each redirect
- View statistics via
/urls/{short_code}/stats - Per-user analytics available
- Enable/disable URLs without deletion
- Update titles and metadata
- Pagination for URL lists
- Owner-only modifications
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
# Run tests
poetry run pytest
# Run with coverage
poetry run pytest --cov
# Run specific test file
poetry run pytest tests/test_auth.py# Sort import alphabatically
poetry run isort
# Lint code
poetry run ruff check
# Type checking
poetry run mypyDocker compose is being used for deploying it on Docker. In the root directory run:
docker compose up -d
Set the environment variables related to application and database in the
compose.ymlfile.
Docker deployment will use PostgreSQL database.