Skip to content

SamridhiiiGupta/SNIP--Short_links_that_work

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

19 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation


  โœ‚  s n i p

Snip โ€” Short links that actually work.

A production-grade URL shortener with real-time analytics, custom aliases, QR codes, and link expiry controls.
Built with Node.js, React, and SQLite. Zero signup required.


Node.js React Vite SQLite License: MIT Status


View Live Demo ยท GitHub Repo ยท Report Bug



๐Ÿ“ธ Preview


Landing Page

Snip Landing Page

Clean hero section with an instant URL shortener form, animated gradient background, and feature grid.


Dashboard

Snip Dashboard

Full link management dashboard โ€” search, filter, click tracking, and one-click analytics per link.



โœจ Features

Core

  • โœ‚๏ธ Instant shortening โ€” Collision-resistant NanoID-based short codes generated in milliseconds
  • ๐Ÿ”— Custom aliases โ€” Choose your own slug for branded, memorable links (/my-launch)
  • โฑ๏ธ Link expiry โ€” Set links to auto-deactivate after N minutes
  • ๐Ÿ—‘๏ธ Link deletion โ€” Full CRUD management from the dashboard

Analytics

  • ๐Ÿ“Š Click tracking โ€” Every redirect is logged with browser, device type, and referrer
  • ๐Ÿ“ˆ Daily click charts โ€” Area chart showing click trends over time (powered by Recharts)
  • ๐ŸŒ Geo insights โ€” Country detection on each redirect event
  • ๐Ÿฅง Browser & device breakdown โ€” Pie chart + progress bars for device type distribution
  • ๐Ÿ• Recent events log โ€” Live feed of the last N clicks with timestamps

Extras

  • ๐Ÿ“ฑ QR code generation โ€” Auto-generated, downloadable QR code for every short link
  • ๐Ÿ“‹ One-click copy โ€” Instant clipboard copy with visual feedback
  • ๐Ÿ” Search & filter โ€” Filter links by status: All / Active / Expired / Custom
  • ๐Ÿ’€ Skeleton loaders โ€” Smooth loading states on every async operation
  • ๐Ÿ”” Toast notifications โ€” Animated slide-in toasts with success / error / info states
  • ๐Ÿ“ Fully responsive โ€” Works on mobile, tablet, and desktop

๐Ÿ› ๏ธ Tech Stack

Layer Technology
Frontend React 18, Vite, React Router v6
Styling Pure CSS with custom design system (CSS variables, Geist font)
Charts Recharts (AreaChart, PieChart)
Backend Node.js, Express 5
Database SQLite via better-sqlite3 (WAL mode for concurrent reads)
ID Generation NanoID (collision-resistant 8-char IDs)
QR Codes qrcode npm package
Security Helmet.js, CORS, express-rate-limit
Logging Morgan HTTP logger
Dev tooling Nodemon, Concurrently

๐Ÿง  How It Works

User pastes URL  โ†’  POST /api/shorturls  โ†’  NanoID generated  โ†’  Saved to SQLite
                                                                         โ”‚
User visits /abc  โ†’  GET /:code  โ†’  Lookup in DB  โ†’  Log analytics  โ†’  302 Redirect
                                                                         โ”‚
Dashboard  โ†’  GET /api/shorturls  โ†’  List all links with click counts
           โ†’  GET /api/shorturls/:code/stats  โ†’  Full analytics breakdown
           โ†’  GET /api/shorturls/:code/qr  โ†’  Base64 QR code image
  1. Shortening โ€” A POST to /api/shorturls validates the URL, generates a NanoID (or uses your custom alias), stores it in SQLite, and returns the short link.
  2. Redirection โ€” Any GET /:code request looks up the code, logs the click event (browser, device, country, referrer), and immediately redirects with a 302.
  3. Analytics โ€” The dashboard fetches per-link stats including daily aggregated clicks, browser/device breakdowns, and a raw event log.

โš™๏ธ Installation & Setup

Prerequisites

  • Node.js v18+
  • npm v9+

1. Clone the repo

git clone https://github.com/SamridhiiiGupta/SNIP-Short_links_that_work
cd snip

2. Install all dependencies (root + frontend)

npm run setup

This runs npm install in the root and cd frontend && npm install automatically.

3. Configure environment

cp .env.example .env

Edit .env:

PORT=3000
BASE_URL=http://localhost:3000
NODE_ENV=development

4. Start the development server

npm run dev

This starts both the backend (port 3000) and the frontend (port 5173) concurrently, and automatically opens the browser.

Service URL
Frontend http://localhost:5173
Backend API http://localhost:3000/api

๐Ÿ—๏ธ Project Structure

snip/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ db/
โ”‚   โ”‚   โ””โ”€โ”€ connection.js       # SQLite connection + schema init
โ”‚   โ”œโ”€โ”€ middlewares/
โ”‚   โ”‚   โ””โ”€โ”€ logger.js           # Morgan HTTP logger
โ”‚   โ”œโ”€โ”€ routes/
โ”‚   โ”‚   โ””โ”€โ”€ shorturls.js        # All /api/shorturls routes
โ”‚   โ””โ”€โ”€ index.js                # Express app entry point
โ”‚
โ”œโ”€โ”€ frontend/
โ”‚   โ”œโ”€โ”€ src/
โ”‚   โ”‚   โ”œโ”€โ”€ components/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Navbar.jsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ ShortenerForm.jsx
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ StatsModal.jsx
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Toast.jsx
โ”‚   โ”‚   โ”œโ”€โ”€ hooks/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ useToast.js
โ”‚   โ”‚   โ”œโ”€โ”€ lib/
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ api.js          # Typed API client
โ”‚   โ”‚   โ”œโ”€โ”€ pages/
โ”‚   โ”‚   โ”‚   โ”œโ”€โ”€ Home.jsx
โ”‚   โ”‚   โ”‚   โ””โ”€โ”€ Dashboard.jsx
โ”‚   โ”‚   โ”œโ”€โ”€ App.jsx
โ”‚   โ”‚   โ”œโ”€โ”€ main.jsx
โ”‚   โ”‚   โ””โ”€โ”€ index.css           # Full design system
โ”‚   โ”œโ”€โ”€ index.html
โ”‚   โ””โ”€โ”€ vite.config.js
โ”‚
โ”œโ”€โ”€ db.sqlite                   # Auto-created on first run
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ nginx.conf.example
โ””โ”€โ”€ package.json

๐Ÿš€ Deployment

Docker (Recommended)

docker build -t snip .
docker run -p 3000:3000 -v $(pwd)/data:/app/data snip

Manual (VPS / Cloud VM)

# Build frontend
npm run build:frontend

# Start production server
NODE_ENV=production npm start

Then point Nginx to port 3000 using the included nginx.conf.example.

Vercel + Railway

Service Platform
Frontend Vercel โ€” connect /frontend as root
Backend + DB Railway โ€” attach a persistent volume for SQLite

Tip: For high-traffic production use, consider replacing SQLite with PostgreSQL and using a managed database like Supabase or Neon.


๐Ÿ“Š API Reference

Method Endpoint Description
POST /api/shorturls Create a short link
GET /api/shorturls List all short links
GET /api/shorturls/:code/stats Get analytics for a link
GET /api/shorturls/:code/qr Get QR code (base64 PNG)
DELETE /api/shorturls/:code Delete a link
GET /:code Redirect to original URL
GET /health Health check

Create short link โ€” request body:

{
  "url": "https://example.com/very/long/path",
  "shortcode": "my-link",
  "validity": 1440,
  "title": "My link label"
}

๐Ÿ”ฎ Roadmap

  • Authentication โ€” User accounts with private link collections
  • Link passwords โ€” Password-protect any short link
  • Bulk import โ€” CSV upload to shorten many URLs at once
  • Click maps โ€” Visual geo heatmap of click origins
  • API keys โ€” Programmatic access for developers
  • Teams โ€” Shared workspaces and link collaboration
  • Custom domains โ€” Use your own domain for short links
  • PostgreSQL support โ€” For larger deployments beyond SQLite

๐Ÿค Contributing

Contributions are welcome! Here's how to get started:

# Fork the repo, then:
git clone https://github.com/SamridhiiiGupta/SNIP-Short_links_that_work
git checkout -b feature/your-feature-name

# Make your changes, then:
git commit -m "feat: add your feature"
git push origin feature/your-feature-name
# Open a Pull Request

Please follow the existing code style and include a clear PR description.


๐Ÿ“„ License

MIT License โ€” see LICENSE for details.


Built with โ˜• and care.
If you found this useful, consider giving it a โญ on GitHub.

About

๐Ÿš€ Production-ready URL shortener with real-time analytics ๐Ÿ“Š, custom aliases ๐Ÿ”—, QR codes ๐Ÿ“ฑ, and smart expiry โฑ๏ธ โ€” built using Node.js โšก, React โš›๏ธ, and SQLite ๐Ÿ’พ

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages