A full-stack URL shortening service built with React, Node.js, and PostgreSQL. Generate short links, track clicks over time, and manage all your links from a clean dashboard.
graph TD
User([User Browser]) <--> Frontend[Frontend - React/Vite]
Frontend <--> API[Backend API - Express.js]
API <--> DB[(PostgreSQL Database)]
API <--> Auth[Auth Middleware - JWT]
subgraph "Backend Services"
URL[URL Shortening]
ANLY[Analytics Tracking]
AUTH_S[User Authentication]
end
API --- URL
API --- ANLY
API --- AUTH_S
- Shorten URLs: Quickly generate short, shareable links.
- Custom Aliases: Create easy-to-remember custom URLs (e.g.,
link.com/my-portfolio). - Link Expiration: Set expiration dates for links (optional).
- Analytics & Trends:
- Total click counts.
- Clicks over time (30-day timeline visualization).
- User Dashboard: Manage your links, see stats, and delete old URLs.
- Secure Authentication: JWT-based login and registration.
- Rate Limiting: Protection against brute-force and spam.
- Framework: React 18
- Styling: Vanilla CSS (Modern Aesthetics)
- State Management: Context API
- Routing: React Router
- Charts: Analytics visualization via custom components.
- Runtime: Node.js
- Framework: Express.js
- Database: PostgreSQL
- Auth: JSON Web Tokens (JWT) & bcrypt
- Middlewares: CORS, Express Rate Limit.
├── backend/
│ ├── src/
│ │ ├── config/ # Database configuration
│ │ ├── controllers/ # Request handlers (logic)
│ │ ├── middleware/ # Auth guards
│ │ ├── models/ # SQL schemas
│ │ ├── routes/ # Express API endpoints
│ │ └── utils/ # Helper functions
│ └── .env # Environment variables
├── frontend/
│ ├── src/
│ │ ├── api/ # API service calls
│ │ ├── components/ # Reusable UI components
│ │ ├── context/ # Global state (Auth)
│ │ ├── pages/ # Main application views
│ │ └── index.css # Core design system
│ └── vite.config.js # Vite dev server & proxy config
└── README.md
- Node.js (v18 or higher)
- PostgreSQL running locally
git clone https://github.com/10KRITESH/url-shortner.git
cd url-shortnerCreate a PostgreSQL database and run the schema:
psql -U postgres -c "CREATE DATABASE urlshortener;"
psql -U postgres -d urlshortener -f backend/src/models/schema.sqlCreate a .env file inside the backend/ folder:
POSTGRES_URL=postgresql://postgres:your_password@localhost:5432/urlshortener
JWT_SECRET=your_super_secret_key
PORT=5000
BASE_URL=http://localhost:3000cd backend
npm install
npm run devcd frontend
npm install
npm run dev- Frontend:
http://localhost:3000 - Backend API:
http://localhost:5000
The frontend's Vite dev server automatically proxies
/apirequests to the backend on port 5000.
- Password Hashing: Bcrypt is used for secure password storage.
- Protected Routes: Sensitive API actions require a valid JWT bearer token.
- Rate Limiting: 100 requests per 15 minutes per IP on all API endpoints.
The system uses three tables:
users: Stores user credentials.urls: Stores original URLs, short codes, and associations.clicks: Stores a timestamp record for every redirect.
Developed by Kritesh Goud