A full‑stack URL shortener built with React (Vite) frontend and an Express + MongoDB backend. Features include user authentication (JWT via cookies), custom short IDs, click tracking with Redis caching, and rate limiting.
Core Features
- Email/password authentication with JWT cookies
- Shorten URLs with optional custom short IDs
- Fast redirect/retrieval via Redis caching
- Click tracking with real-time counters
- Per-user URL management dashboard
- Rate limiting on auth and URL creation endpoints
- Input validation with Zod
- Client: React + Vite in
client/(uses Tailwind-style UI components) - Server: Express app in
server/connecting to MongoDB and Redis - Authentication: JWT stored in HTTP-only cookie
- Redis: Caching shortId → longUrl mappings and click counters
Frontend
- React 19 with Vite
- TailwindCSS 4 for styling
- React Router for navigation
- Axios for API calls
- Radix UI components
- React Hook Form + Zod validation
Backend
- Express 5
- MongoDB with Mongoose
- Redis for caching
- JWT authentication
- bcryptjs for password hashing
- Winston for logging
- Helmet & CORS for security
# Clone the repository
git clone https://github.com/vansh4117v/url-shortener.git
cd url-shortener
# Install server dependencies
cd server
npm install
# Install client dependencies
cd ../client
npm installCreate .env files in both server/ and client/ directories.
Server (server/.env):
NODE_ENV=development
PORT=5000
MONGO_URI=mongodb+srv://<user>:<pass>@cluster.mongodb.net/urlshortener
JWT_SECRET=your-super-secret-jwt-key-min-32-chars-long
JWT_EXPIRES_IN=7d
ALLOWED_ORIGINS=http://localhost:5173
REDIS_URL=redis://localhost:6379Client (client/.env):
VITE_API_BASE_URL=http://localhost:5000/apiTip: Copy from
.env.examplefiles if available
Make sure Redis is running locally:
redis-server
# or use Docker: docker run -d -p 6379:6379 redisOpen two terminal windows:
Terminal 1 - Server:
cd server
npm run devTerminal 2 - Client:
cd client
npm run devThe client will open at http://localhost:5173 and connect to the API at http://localhost:5000.
Base URL: http://localhost:5000/api
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/auth/signup |
Register new user | ❌ |
POST |
/auth/signin |
Sign in user | ❌ |
GET |
/auth/me |
Get current user | ✅ |
POST |
/auth/logout |
Logout user | ✅ |
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
POST |
/url/shorten |
Create short URL | ✅ |
GET |
/url/ |
Get all user URLs | ✅ |
GET |
/url/:shortId |
Redirect to long URL | ❌ |
GET |
/url/:shortId/info |
Get URL metadata | ✅ |
DELETE |
/url/:shortId |
Delete URL | ✅ |
Made with by vansh4117v