Skip to content

Latest commit

 

History

39 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener

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.


Run Locally

python -m uvicorn src.main:app --reload

App runs at:

http://127.0.0.1:8000

Database

Uses PostgreSQL.

Local development connects using host/port. Production connects to Cloud SQL using the Cloud SQL Unix socket.

Tables

url_map

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

click_log

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

Endpoints

Health Check

GET /health

Response

{
  "status": "ok"
}

Login

GET /login

Starts GitHub OAuth login flow.

OAuth Callback

GET /auth/github/callback

Completes login and stores the user session.

Logout

GET /logout

Clears session and redirects to /.

Create Short URL

POST /shorten

Form field:

url=<original_url>

Response: rendered HTML page containing

  • short URL
  • short code
  • admin key

Example:

https://short.raghavsethi.in/abc12

Redirect

GET /{short_code}

Redirects to the original URL and logs click data.

Logged data includes:

  • IP address
  • user agent
  • referer
  • timestamp

View User Links

GET /my-links

Shows all links created by the logged-in user.

Admin Stats

POST /admin-stats

Form inputs:

short_code
admin_key

Displays:

  • total clicks
  • unique visitors
  • first click
  • last click
  • click logs

HTML Interface

Rendered using Jinja2 templates.

Home Page

GET /
  • If not logged in → login page
  • If logged in → URL creation page

Features

  • 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

About

A minimalistic URL Shortener currently hosted on Google Cloud Run using PostgresSQL, built on the FastAPI framework with authentication through Github OAuth

Topics

Resources

Stars

1 star

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages