https://github.com/sinanptm/shortify
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.
https://github.com/sinanptm/shortify
caching express jest jwt nodejs-api passportjs redis rest-api testing url-shortener-api
Last synced: about 2 months ago
JSON representation
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.
- Host: GitHub
- URL: https://github.com/sinanptm/shortify
- Owner: sinanptm
- Created: 2024-12-15T09:16:49.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-03T13:18:08.000Z (over 1 year ago)
- Last Synced: 2025-10-30T01:45:00.462Z (7 months ago)
- Topics: caching, express, jest, jwt, nodejs-api, passportjs, redis, rest-api, testing, url-shortener-api
- Language: TypeScript
- Homepage: https://shortify.avm-ayurvedic.online/api/auth/google
- Size: 461 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.MD
Awesome Lists containing this project
README
# ๐ Shortify - URL Shortener API
[](https://www.typescriptlang.org/)
[](https://nodejs.org/)
[](https://expressjs.com/)
[](https://redis.io/)
[](https://jestjs.io/)
[](https://www.passportjs.org/)
## ๐ Contents
[๐ Overview](#-overview) |
[โ๏ธ Prerequisites](#%EF%B8%8F-prerequisites) |
[๐ Tech Stack](#-tech-stack) |
[๐ Features](#-features) |
[๐ API Endpoints](#-api-endpoints) |
[๐ Authentication Setup](#-authentication-setup) |
[โ๏ธ Environment Variables](#%EF%B8%8F-environment-variables) |
[๐ Installation](#-installation) |
[๐งช Testing](#-testing) |
[๐ API Documentation](#-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
- **Authentication Endpoint**: [https://shortify.avm-ayurvedic.online/api/auth/google](https://shortify.avm-ayurvedic.online/api/auth/google)
- **API Documentation**: [Postman Documentation](https://documenter.getpostman.com/view/32102231/2sAYHzGiKx)
## ๐ 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
```javascript
GET /api/auth/google
GET /api/auth/callback
```
### URL Management
```javascript
POST /api/shorten
{
"longUrl": "https://example.com",
"customAlias": "my-link",
"topic": "acquisition"
}
GET /api/shorten/:alias
```
### Analytics
```javascript
GET /api/analytics/alias/:alias
GET /api/analytics/topic/:topic
GET /api/analytics/overall
```
## ๐ Authentication Setup
### Google OAuth Configuration
1. **Create Google Cloud Project**:
- Go to [Google Cloud Console](https://console.cloud.google.com/)
- Create a new project
- Enable Google+ API and OAuth API
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
```env
# 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:
```bash
git clone https://github.com/sinanptm/shortify.git
cd shortify
```
2. Install dependencies:
```bash
yarn install
```
3. Set up environment:
```bash
cp .env.example .env
```
4. Start development server:
```bash
yarn dev
```
## ๐งช Testing
Run the test suite:
```bash
yarn test
```
## ๐ API Documentation
For detailed API documentation and examples, visit our [Postman Documentation](https://documenter.getpostman.com/view/32102231/2sAYHzGiKx).