Skip to content

Shortify is a powerful and secure URL shortening service designed for developers who need an efficient way to manage and shorten long URLs. Built using modern technologies like Node.js, TypeScript, Express, and Redis, this API ensures high performance, scalability, and security for users.

Notifications You must be signed in to change notification settings

sinanptm/shortify

Repository files navigation

πŸ”— Shortify - URL Shortener API

TypeScript Node.js Express Redis Jest Passport

πŸ“š Contents

πŸ“– Overview | βš™οΈ Prerequisites | πŸ›  Tech Stack | πŸ“Š Features | πŸ”Œ API Endpoints | πŸ” Authentication Setup | βš™οΈ Environment Variables | πŸš€ Installation | πŸ§ͺ Testing | πŸ“š API Documentation

πŸ“– Overview

Shortify is a powerful URL shortening service built with scalability and analytics in mind. It provides advanced features including topic-based organization, detailed analytics, and Google Sign-In authentication, making it perfect for both personal and enterprise use.

🌐 Live Endpoints

πŸ›  Tech Stack

  • Backend: Node.js with Express
  • Database: MongoDB with Mongoose
  • Caching: Redis
  • Authentication: Passport.js with Google OAuth 2.0
  • Testing: Jest
  • Analytics: Custom implementation with geolocation tracking

βš™οΈ Prerequisites

Before running the application, ensure you have:

  • Node.js 22.x or higher
  • Redis Server
  • MongoDB
  • Yarn package manager
  • Google Cloud Console account

πŸ“Š Features

1. User Authentication

  • Google Sign-In integration
  • Secure session management
  • JWT token-based authentication
  • HTTP-only cookie implementation

2. URL Shortening

  • Custom alias support
  • Topic-based organization
  • Automatic URL validation
  • Collision detection
  • Rate limiting protection

3. Advanced Analytics

  • Click Tracking

    • Total clicks
    • Unique visitors
    • Geographic distribution
    • Time-based analytics
  • Device Analytics

    • Operating system tracking
    • Device type detection
    • Browser statistics
    • Screen resolution data
  • Topic-Based Insights

    • Category-wise performance
    • Comparative analytics
    • Trend analysis
    • Engagement metrics

4. Performance Features

  • Redis caching
  • Load balancing ready
  • Rate limiting
  • Response compression

5. Security Measures

  • URL sanitization
  • XSS protection
  • Rate limiting
  • CORS configuration
  • Input validation

πŸ”Œ API Endpoints

Authentication

GET /api/auth/google
GET /api/auth/callback

URL Management

POST /api/shorten
{
  "longUrl": "https://example.com",
  "customAlias": "my-link",
  "topic": "acquisition"
}

GET /api/shorten/:alias

Analytics

GET /api/analytics/alias/:alias
GET /api/analytics/topic/:topic
GET /api/analytics/overall

πŸ” Authentication Setup

Google OAuth Configuration

  1. Create Google Cloud Project:

  2. Configure OAuth Consent Screen:

    • Set application name
    • Add authorized domains
    • Configure scopes (email, profile)
  3. Get OAuth Credentials:

    • Create OAuth Client ID
    • Configure redirect URIs
    • Save Client ID and Secret

βš™οΈ Environment Variables

# Environment Configuration
NODE_ENV=development
MONGO_URI=mongodb://localhost:27017/Shortify
CLIENT_URL=http://localhost:3000
PORT=8000

# Redis Configuration
REDIS_HOST=127.0.0.1
REDIS_PORT=6379

# Security
TOKEN_SECRET=your_jwt_secret_key

# External Services
GEOLOCATION_PROVIDER=http://ip-api.com/json/

# URLs
SERVER_URL=http://localhost:8000

# Google OAuth
GOOGLE_CLIENT_ID=your_client_id
GOOGLE_CLIENT_SECRET=your_client_secret

πŸš€ Installation

  1. Clone the repository:
git clone https://github.com/sinanptm/shortify.git
cd shortify
  1. Install dependencies:
yarn install
  1. Set up environment:
cp .env.example .env
  1. Start development server:
yarn dev

πŸ§ͺ Testing

Run the test suite:

yarn test

πŸ“š API Documentation

For detailed API documentation and examples, visit our Postman Documentation.

About

Shortify is a powerful and secure URL shortening service designed for developers who need an efficient way to manage and shorten long URLs. Built using modern technologies like Node.js, TypeScript, Express, and Redis, this API ensures high performance, scalability, and security for users.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published