URL Shortener
A URL shortener is a common full-stack machine-coding project.
Features
- submit long URL,
- generate short slug,
- redirect short URL,
- track click count,
- show analytics,
- optional login for managing links.
Backend routes
POST /api/urls
GET /:slug
GET /api/urls/:id/stats
MongoDB model
const urlSchema = new Schema({
longUrl: { type: String, required: true },
slug: { type: String, required: true, unique: true },
clickCount: { type: Number, default: 0 },
userId: { type: Schema.Types.ObjectId, ref: 'User' },
}, { timestamps: true })
Redirect flow
- User visits
/:slug. - Backend finds URL by slug.
- Backend increments click count.
- Backend redirects to long URL.
res.redirect(url.longUrl)
Edge cases
- invalid URL,
- slug collision,
- missing slug,
- expired URL,
- malicious links,
- analytics accuracy.
What this project proves
- routing,
- validation,
- unique indexes,
- redirect behavior,
- analytics updates,
- practical API/UI integration.