Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

21 Commits

Repository files navigation

LinkBin

LinkBin is a full-stack MERN URL shortener and paste sharing platform. It is built as an interview-ready backend-focused project that demonstrates REST API design, authentication, Redis caching, rate limiting, expiry handling, analytics, API documentation, testing, Docker, and CI.

Features

URL Shortener

  • Create short URLs from long URLs
  • Generate random short codes
  • Create custom aliases
  • Redirect users to the original URL
  • Disable or delete short URLs
  • Set expiry time for short links
  • Generate QR codes for short URLs
  • Track detailed click analytics

Paste Sharing

  • Create and share text, code, logs, JSON, or notes
  • Public, unlisted, and private paste visibility
  • Syntax highlighting and readable paste view
  • Copy paste content
  • Set paste expiry time
  • Disable or delete pastes
  • Track lightweight paste view analytics

Authentication And Dashboard

  • Register and login with JWT authentication
  • Secure password hashing with bcrypt
  • Protected dashboard routes
  • Manage URLs and pastes from a user dashboard
  • View URL analytics and paste analytics

Tech Stack

LayerTechnology
FrontendReact, React Router, Axios, Vite
BackendNode.js, Express.js
DatabaseMongoDB, Mongoose
Cache / Rate LimitingRedis
AuthJWT, bcrypt
ValidationZod
API DocsSwagger / OpenAPI
TestingJest, Supertest, mongodb-memory-server
DevOpsDocker, Docker Compose, GitHub Actions

Architecture

React Frontend
|
v
Express API
|
|-- MongoDB: users, URLs, pastes, analytics
|-- Redis: short URL lookup cache
|-- Redis: rate limiting

Redis Usage

LinkBin uses Redis in two important places:

  1. Cache-aside redirects

    • The backend checks Redis before MongoDB for short URL redirects.
    • Frequently accessed short URLs avoid repeated MongoDB lookups.
    • On cache miss, MongoDB is queried and Redis is updated.
  2. Rate limiting

    • Redis-backed rate limits protect auth, URL creation, paste creation, and redirect endpoints.
    • This helps prevent spam, brute-force login attempts, and API abuse.

Analytics

URL analytics include:

  • Total clicks
  • Unique visitors
  • Clicks by date
  • Referrer
  • Browser and device
  • Approximate country/city
  • Last clicked time

Paste analytics include:

  • Total views
  • Unique views
  • Views by date
  • Last viewed time

API Overview

MethodEndpointDescription
POST/api/auth/registerRegister user
POST/api/auth/loginLogin user
GET/api/auth/meGet current user
POST/api/urlsCreate short URL
GET/api/urlsList user's short URLs
GET/:shortCodeRedirect short URL
POST/api/pastesCreate paste
GET/api/pastesList user's pastes
GET/p/:slugView public/unlisted paste
GET/api/dashboard/summaryDashboard summary
GET/api/docsSwagger API docs

Local Setup

Run With Docker Compose

Create backend environment file:

cd backend
cp .env.example .env
cd ..

Start the full stack:

docker compose up --build

Services:

Frontend: http://localhost:5173
Backend: http://localhost:5000
MongoDB: localhost:27018
Redis: localhost:6379

Run Backend Manually

MongoDB and Redis should already be running.

cd backend
npm install
cp .env.example .env
npm run dev

Run Frontend Manually

cd frontend
npm install
cp .env.example .env
npm run dev

Environment Variables

Backend:

PORT=5000NODE_ENV=developmentMONGO_URI=mongodb://localhost:27017/linkbinJWT_SECRET=replace_with_strong_secretJWT_EXPIRES_IN=7dCLIENT_URL=http://localhost:5173REDIS_URL=redis://localhost:6379BASE_URL=http://localhost:5000

Frontend:

VITE_API_URL=http://localhost:5000

Testing

Run backend API integration tests:

cd backend
npm test

The backend tests use Jest and Supertest to validate Express API behavior, authentication flows, validation, and database-backed routes.

CI

GitHub Actions is configured to validate the project on push/PR. The pipeline checks backend tests, frontend builds, and Docker image builds.

This project demonstrates:

  • REST API design with Express.js
  • MongoDB schema design and indexing
  • JWT authentication and protected routes
  • Redis cache-aside pattern
  • Redis-backed rate limiting
  • Expiry handling for URLs and pastes
  • Analytics/event tracking
  • Swagger API documentation
  • Docker Compose orchestration
  • Backend API integration testing
  • GitHub Actions CI

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages