A simple URL shortener with GitHub login, click tracking, and link analytics built with FastAPI and PostgreSQL.
The service is deployed on Google Cloud Run and uses Google Cloud SQL for the database.
python -m uvicorn src.main:app --reloadApp runs at:
http://127.0.0.1:8000
Uses PostgreSQL.
Local development connects using host/port. Production connects to Cloud SQL using the Cloud SQL Unix socket.
Stores shortened links.
| Field | Type | Description |
|---|---|---|
| id | Integer | Primary key |
| original_url | String | Original long URL |
| short_code | String | Unique short identifier |
| admin_key | String | Admin analytics key |
| owner_id | Integer | GitHub user ID |
| owner_login | String | GitHub username |
Stores redirect analytics.
| Field | Type | Description |
|---|---|---|
| id | Integer | Primary key |
| url_map_id | Integer | Linked URL |
| ip_address | String | Visitor IP |
| user_agent | String | Browser info |
| referer | String | Source of traffic |
| timestamp | DateTime | Click time |
GET /health
Response
{
"status": "ok"
}GET /login
Starts GitHub OAuth login flow.
GET /auth/github/callback
Completes login and stores the user session.
GET /logout
Clears session and redirects to /.
POST /shorten
Form field:
url=<original_url>
Response: rendered HTML page containing
- short URL
- short code
- admin key
Example:
https://short.raghavsethi.in/abc12
GET /{short_code}
Redirects to the original URL and logs click data.
Logged data includes:
- IP address
- user agent
- referer
- timestamp
GET /my-links
Shows all links created by the logged-in user.
POST /admin-stats
Form inputs:
short_code
admin_key
Displays:
- total clicks
- unique visitors
- first click
- last click
- click logs
Rendered using Jinja2 templates.
GET /
- If not logged in → login page
- If logged in → URL creation page
- GitHub OAuth login
- Random short code generation
- Admin-key protected analytics
- Click tracking
- IP + user agent logging
- Referer tracking
- Server-rendered HTML interface
- Deployed on Google Cloud Run
- Uses Cloud SQL PostgreSQL