How ahmetfbalci/url-shortener-api works
This is a FastAPI URL-shortening API: clients submit a URL, the service generates and stores a short code, and later requests resolve that code to a redirect. Its documented capabilities include Redis caching, expiration, click tracking, and health checks. The graph separates API, application logic, persistence, and configuration. Source excerpts show the main request paths; the README supplies some capability details. Note: the redirect service returns immediately on a cache hit, before incrementing the click count, so the documented count behavior is not true for cached redirects.
Main entry points: url_service.py Redirect Resolution · database.py DB Session · main.py FastAPI App · urls.py URL Routes
Components 14
API
- FastAPI App
app/main.py - URL Routes
app/api/routes/urls.py - URL Schemas
app/schemes/url.py
URL Logic
- Short URL Creation
app/services/url_service.py - Redirect Resolution
app/services/url_service.py - Link Expiration
app/services/url_service.py - Click Tracking
app/services/url_service.py
Persistence
- Redis Cache
app/db/redis.py - URL ORM Model
app/models/url_models.py - DB Session
app/db/database.py - PostgreSQL
Runtime Configuration
- Settings
app/core/config.py
Other components
- API Client
- Redirect Recipient
Connections 18
- API Client → FastAPI App: sends requests
README.md - FastAPI App → URL Routes: registers routes
app/main.py - URL Routes → URL Schemas: validates input
app/api/routes/urls.py - URL Routes → Short URL Creation: calls creation
app/api/routes/urls.py - URL Routes → Redirect Resolution: calls resolution
app/api/routes/urls.py - Short URL Creation → URL ORM Model: queries and creates
app/services/url_service.py - Short URL Creation → DB Session: uses session
app/api/routes/urls.py - Redirect Resolution → Redis Cache: reads and populates
app/services/url_service.py - Redirect Resolution → URL ORM Model: looks up URL
app/services/url_service.py - Redirect Resolution → Link Expiration: checks expiration
app/services/url_service.py - Redirect Resolution → Click Tracking: increments count
app/services/url_service.py - Redirect Resolution → Redirect Recipient: returns redirect
app/services/url_service.py - URL ORM Model → DB Session: uses base
app/models/url_models.py - DB Session → PostgreSQL: connects to
app/db/database.py - FastAPI App → Redis Cache: pings health
app/main.py - FastAPI App → DB Session: checks health
app/main.py - DB Session → Settings: loads connection config
app/db/database.py - Redis Cache → Settings: loads connection config
app/db/redis.py