- β¨ Features
- π οΈ Tech Stack
- ποΈ Architecture
- π Quick Start
- π± Usage Guide
- π Security
- π Performance
- π Deployment
- π€ Contributing
- π License
- Instant URL Shortening: Create short, memorable links in seconds
- Custom Aliases: Choose your own custom short URLs
- Bulk URL Management: Handle multiple URLs efficiently
- Secure Authentication: JWT-based login with refresh tokens
- User Dashboard: Centralized management of all shortened URLs
- Session Management: Secure logout and token refresh
-
Click Analytics: Monitor traffic and engagement metrics
-
Referrer Tracking: Track where your clicks are coming from
-
Time-based Analytics: Track clicks over time periods
- RESTful API: Complete API for integration
- Rate Limiting: Prevent abuse with configurable limits
- API Documentation: Comprehensive API docs with examples
- Webhook Support: Real-time notifications for events
| Technology | Version | Purpose |
|---|---|---|
| React | 19.1.1 | UI Framework |
| Vite | 7.1.7 | Build Tool & Dev Server |
| Tailwind CSS | 4.1.14 | Styling Framework |
| React Router | 7.9.4 | Client-side Routing |
| Axios | 1.12.2 | HTTP Client |
| React Hot Toast | 2.6.0 | Notifications |
| React Icons | 5.5.0 | Icon Library |
| Technology | Version | Purpose |
|---|---|---|
| Node.js | Latest | Runtime Environment |
| Express.js | 5.1.0 | Web Framework |
| MongoDB | Latest | Database |
| Mongoose | 8.19.0 | ODM |
| JWT | 9.0.2 | Authentication |
| bcryptjs | 3.0.2 | Password Hashing |
| Helmet | 8.1.0 | Security Headers |
| Morgan | 1.10.1 | HTTP Logging |
| Tool | Purpose |
|---|---|
| Vercel | Frontend Deployment |
| Render | Backend Deployment |
| GitHub Actions | CI/CD Pipeline |
| ESLint | Code Quality |
| Nodemon | Development Hot Reload |
graph TB
subgraph "Client Layer"
A[React Frontend]
B[Mobile App]
C[Third-party Apps]
end
subgraph "API Gateway"
D[Express.js Server]
E[Rate Limiting]
F[CORS & Security]
end
subgraph "Business Logic"
G[Auth Controller]
H[URL Controller]
I[Analytics Controller]
end
subgraph "Data Layer"
J[MongoDB Database]
K[User Collection]
L[URL Collection]
M[Analytics Collection]
end
A --> D
B --> D
C --> D
D --> E
E --> F
F --> G
F --> H
F --> I
G --> J
H --> J
I --> J
J --> K
J --> L
J --> M
URL Shortener/
βββ π frontend/ # React frontend application
β βββ π src/
β β βββ π components/ # Reusable UI components
β β βββ π pages/ # Page components
β β βββ π hooks/ # Custom React hooks
β β βββ π utils/ # Utility functions
β β βββ π api.js # API client configuration
β βββ π vite.config.mjs # Vite configuration
β βββ π vercel.json # Deployment configuration
β
βββ π backend/ # Node.js backend API
β βββ π src/
β β βββ π config/ # Configuration files
β β βββ π controllers/ # Request handlers
β β βββ π middlewares/ # Express middlewares
β β βββ π models/ # Database models
β β βββ π routes/ # API routes
β β βββ π utils/ # Utility functions
β β βββ π logs/ # Application logs
β βββ π .env # Environment variables
β
βββ π docs/ # Documentation
βββ π API.md # API documentation
βββ π DEPLOYMENT.md # Deployment guide
βββ π CONTRIBUTING.md # Contribution guidelines
- Node.js (v18 or higher)
- MongoDB (v6 or higher)
- npm or yarn
- Git
-
Clone the repository
git clone https://github.com/yourusername/url-shortener.git cd url-shortener -
Set up the backend
cd backend npm install # Create environment file cp .env.example .env # Edit .env with your configuration # Start development server npm run backend
-
Set up the frontend
cd ../frontend npm install # Start development server npm run dev
-
Access the application
- Frontend: http://localhost:5173
- Backend API: http://localhost:5000
- API Docs: http://localhost:5000/api-docs
Create a .env file in the backend directory:
# Server Configuration
PORT=5000
NODE_ENV=development
# Database
MONGODB_URI=mongodb://localhost:27017/url-shortener
# Authentication
JWT_SECRET=your-super-secret-jwt-key
JWT_EXPIRE=7d
JWT_REFRESH_SECRET=your-refresh-token-secret
JWT_REFRESH_EXPIRE=30d
# Security
BCRYPT_ROUNDS=12
RATE_LIMIT_WINDOW=15
RATE_LIMIT_MAX=100
# Frontend URL (for CORS)
FRONTEND_URL=http://localhost:5173- Create Account: Register with email and password
- ** Shorten URLs**: Paste long URLs to get short links
- Customize: Create custom aliases for your links
- Track Performance: Monitor clicks and analytics
// Shorten a URL
const response = await fetch("/api/v1/urls", {
method: "POST",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer YOUR_JWT_TOKEN",
},
body: JSON.stringify({
originalUrl: "https://example.com/very-long-url",
customShortId: "my-custom-link", // Optional
}),
});
const data = await response.json();
console.log(data.shortUrl); // https://yoursite.com/my-custom-link- β JWT Tokens: Secure token-based authentication
- β Refresh Tokens: Automatic token renewal
- β Password Hashing: bcrypt with salt rounds
- β Session Management: Secure logout and cleanup
- Rate Limiting: Prevent abuse and DDoS attacks
- CORS Protection: Configured for specific origins
- Helmet.js: Security headers implementation
- Input Validation: Comprehensive request validation
- HTTPS Only: All communications encrypted
- Environment Variables: Sensitive data protection
- Cookie Security: HttpOnly and Secure flags
- Data Sanitization: XSS prevention
- Connection Pooling: Efficient database connections
- Code Splitting: Lazy loading of components
- Performance Metrics: Response time tracking
- Error Monitoring: Comprehensive error logging
- Usage Analytics: User behavior tracking
- Health Checks: Automated system monitoring
# Install Vercel CLI
npm i -g vercel
# Deploy
cd frontend
vercel --prod# Connect your repository
# Set environment variables
# Deploy automatically on push# Build and run with Docker Compose
docker-compose up -d- Production Database: MongoDB Atlas
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- ESLint: Follow the configured linting rules
- Prettier: Consistent code formatting
- Documentation: Update docs for API changes
Amritanshu Goutam
Made with β€οΈ and JavaScript