- 🔗 URL Shortening — Create short, memorable links instantly
- 📱 QR Code Generation — Download QR codes for any shortened link
- 📊 Link Analytics — Track clicks, unique visitors, and performance
- 🌙 Dark Mode — Beautiful light and dark themes
- 🔒 Secure — HTTPS-only validation, rate limiting, and input sanitization
- 📝 Link History — Local storage-based history of your created links
- 🚨 Report System — Report suspicious or malicious links
- 📧 Contact Form — Built-in contact functionality
- 📱 Responsive — Works perfectly on desktop and mobile
- Frontend: https://shorty.msyb.dev
| Layer | Technologies |
|---|---|
| Frontend | React 19, React Router 7, Ant Design 6, CSS3 |
| Backend | Node.js 18+, Express 4, MySQL |
| Security | Helmet.js, Rate Limiting, CORS, Input Validation |
| Deployment | Vercel (Serverless Ready) |
url-shorty/
├── frontend/ # React frontend application
│ ├── public/ # Static assets (logo, manifest, etc.)
│ └── src/
│ ├── pages/ # Page components (Home, Contact, Report, etc.)
│ ├── Components/ # Reusable components
│ ├── context/ # React context (Theme)
│ ├── services/ # API service layer
│ ├── App.js # Main app with routing
│ └── App.css # Global styles
│
├── server/ # Express backend API
│ ├── scripts/ # Database initialization scripts
│ └── src/
│ ├── config/ # Database & app configuration
│ ├── controllers/ # Request handlers
│ ├── middlewares/ # Security, validation, rate limiting
│ ├── models/ # Database models
│ ├── routes/ # API route definitions
│ └── utils/ # Helper functions & logger
│
└── README.md # This file
- Node.js 18+ (LTS recommended)
- MySQL 8.0+ (or compatible: MariaDB, PlanetScale, etc.)
- npm or yarn
git clone https://github.com/shehari007/url-shorty.git
cd url-shortycd server
# Install dependencies
npm install
# Configure environment
cp .env.example .env
# Edit .env with your database credentials
# Initialize database (creates all tables)
npm run db:init
# Start development server
npm run devcd frontend
# Install dependencies
npm install
# Start development server
npm startThe frontend will be available at http://localhost:3000 and the API at http://localhost:8080.
| Variable | Description | Default |
|---|---|---|
NODE_ENV |
Environment mode | development |
PORT |
Server port | 8080 |
DBHOST |
MySQL host | - |
DBPORT |
MySQL port | 3306 |
DBUSERNAME |
Database username | - |
DBPASS |
Database password | - |
DBNAME |
Database name | - |
SHORTURLDEF |
Base URL for short links | https://short.msyb.dev/ |
PARAMLEN |
Length of short URL code | 5 |
DOMAINS |
Allowed CORS origins | http://localhost:3000 |
| Variable | Description |
|---|---|
REACT_APP_API_URL |
Backend API URL |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/shorty-url/generate |
Create a short URL |
GET |
/co/:shortCode |
Redirect to original URL |
| Method | Endpoint | Description |
|---|---|---|
GET |
/api/shorty-url/stats |
Get overall statistics |
POST |
/api/shorty-url/perlinkstats |
Get stats for a specific link |
POST |
/api/shorty-url/stats/track-qr |
Track QR code generation |
| Method | Endpoint | Description |
|---|---|---|
POST |
/api/shorty-url/contact |
Submit contact form |
POST |
/api/shorty-url/report |
Report a malicious URL |
| Method | Endpoint | Description |
|---|---|---|
GET |
/health |
Server health check |
- Helmet.js — Secure HTTP headers
- Rate Limiting — Prevent API abuse
- Input Validation — Sanitize all user inputs
- SQL Injection Protection — Parameterized queries
- XSS Protection — Content sanitization
- CORS — Configurable origin whitelist
- HTTPS Validation — Only secure URLs accepted
| Table | Description |
|---|---|
shorty_url |
Main URL storage with click tracking |
shorty_visits |
Individual visit tracking |
shorty_contact |
Contact form submissions |
shorty_report |
URL abuse reports |
shorty_analytics |
Event analytics (QR scans, etc.) |
Run npm run db:init in the server directory to create all tables automatically.
| Script | Description |
|---|---|
npm start |
Start production server |
npm run dev |
Start with hot reload |
npm run db:init |
Initialize database tables |
npm run lint |
Run ESLint |
| Script | Description |
|---|---|
npm start |
Start development server |
npm run build |
Create production build |
npm test |
Run tests |
Both frontend and server are configured for Vercel deployment:
- Connect your GitHub repository to Vercel
- Set environment variables in Vercel dashboard
- Deploy!
# Frontend
cd frontend
npm run build
# Deploy the 'build' folder to your hosting
# Server
cd server
npm startContributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
shehari007
- GitHub: @shehari007
Made with ❤️ by shehari007
⭐ Star this repo if you find it useful!