Skip to content

Sri-Varshith/url_shortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

29 Commits
 
 
 
 
 
 
 
 

Repository files navigation

URL Shortener

A full-stack URL shortener built with Go, React, PostgreSQL, and Supabase. The application allows users to create short URLs, redirect using short codes, update existing mappings, delete mappings, and retrieve URL statistics.

Features

  • Create short URLs from long URLs
  • Redirect users using short codes
  • Update existing URL mappings
  • Delete URL mappings
  • Retrieve URL statistics

Tech Stack

Frontend

  • React
  • Vite
  • Tailwind CSS
  • JavaScript

Backend

  • Go
  • Chi Router
  • pgx PostgreSQL Driver

Database

  • PostgreSQL
  • Supabase

Deployment

  • Render (Backend)
  • Vercel (Frontend)

Architecture

┌─────────────┐      REST API     ┌─────────────┐      PostgreSQL      ┌─────────────┐
│ React (UI)  │ ────────────────► │ Go Backend  │ ───────────────────► │  Supabase   │
└─────────────┘                   └─────────────┘                      └─────────────┘

URL Creation Flow

User enters URL
        │
        ▼
React Frontend
        │
POST /shorten
        │
        ▼
Go Backend
        │
Generate Short Code
        │
Store in PostgreSQL
        │
        ▼
Return Short Code
        │
        ▼
Display Short URL

Redirect Flow

User visits /{shortcode}
        │
        ▼
Go Backend
        │
Lookup URL in Database
        │
        ▼
HTTP Redirect
        │
        ▼
Original Website

Project Structure

url_shortener/
│
├── backend/
│   ├── main.go
│   ├── routes.go
│   ├── handlers.go
│   ├── database.go
│   ├── config.go
│   ├── models.go
│   ├── utils.go
│   ├── go.mod
│   └── go.sum
│
├── client/
│   ├── src/
│   │   ├── App.jsx
│   │   ├── main.jsx
│   ├── package.json
│   ├── vite.config.js
│   └── index.html
│
└── README.md

Backend Responsibilities

main.go

Application entry point.

Responsibilities:

  • Load configuration
  • Connect to database
  • Initialize routes
  • Start HTTP server

config.go

Handles application configuration.

Responsibilities:

  • Read environment variables
  • Provide configuration values

database.go

Responsible for database connection and queries.

Responsibilities:

  • Establish PostgreSQL connection
  • Store global database instance
  • Execute database operations

handlers.go

Contains HTTP request handlers.

Responsibilities:

  • Parse incoming requests
  • Validate data
  • Call database functions
  • Return JSON responses

routes.go

Responsible for API route registration.

Responsibilities:

  • Configure router
  • Register endpoints
  • Configure middleware

utils.go

Contains helper functions.

Responsibilities:

  • Generate random short codes
  • Reusable utility logic

Environment Variables

Backend

DATABASE_URL=your_postgresql_connection_string
PORT=8000

Running Locally

Clone Repository

git clone https://github.com/Sri-Varshith/url_shortener.git
cd url_shortener

Backend

cd backend

go mod download

go run .

Server starts on:

http://localhost:8000

Frontend

cd client

npm install

npm run dev

Frontend starts on:

http://localhost:5173

Future Improvements

  • Custom short codes
  • URL analytics dashboard
  • Authentication
  • Rate limiting
  • QR code generation
  • Custom domains
  • Expiring URLs
  • Improved statistics and tracking

About

A full-stack URL shortener application built from scratch using Go, React, PostgreSQL, and Supabase.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors