The core URL shortener API for dev.ly. Handles user authentication, URL creation/management, short-code redirects, and pushes click events to the analytics pipeline via BullMQ. Built with Express 5 and PostgreSQL.
- JWT Authentication — Secure register/login with bcrypt password hashing
- URL Shortening — Base62-encoded short codes with custom expiry
- Redirect Engine —
GET /:shortCode→ 302 redirect with async click logging - Redis URL Cache — Sub-millisecond redirects via cached URL lookups
- BullMQ Click Queue — Fire-and-forget click events with guaranteed delivery to the analytics worker
- Rate Limiting — Redis-backed rate limiting on auth & API endpoints (redirects are never blocked)
- Database Migrations — Auto-run SQL migrations on startup
| Technology | Purpose |
|---|---|
| Express 5 | HTTP framework |
| PostgreSQL 15 | Primary database |
| Redis 7 | URL caching & rate limiting |
| BullMQ | Job queue for click events |
| JSON Web Tokens | Auth tokens |
| bcrypt | Password hashing |
| Axios | Internal HTTP calls |
backend/
├── index.js # Entry point
├── Dockerfile # Docker build
├── package.json
└── src/
├── config/
│ ├── db.js # PostgreSQL pool
│ └── redis.js # Redis/IORedis client
├── controllers/
│ ├── authController.js # Register, Login, Profile
│ └── urlController.js # Create, List, Delete, Redirect
├── db/
│ ├── migrate.js # Auto-migration runner
│ └── migrations/
│ ├── 001_initial_schema.sql
│ ├── 002_increase_short_code_length.sql
│ ├── 003_add_analytics_columns.sql
│ └── 004_add_utm_and_unique.sql
├── middlewares/
│ ├── authMiddleware.js # JWT verification
│ └── rateLimiter.js # Redis-backed rate limiter
├── queues/
│ └── clickQueue.js # BullMQ producer
├── routes/
│ ├── authRoutes.js # /api/auth/*
│ └── urlRoutes.js # /api/url/*
└── utils/
└── base62.js # Short code encoding
| Method | Endpoint | Auth | Description |
|---|---|---|---|
POST |
/api/auth/register |
✗ | Register a new user |
POST |
/api/auth/login |
✗ | Login, returns JWT |
GET |
/api/auth/profile |
✓ | Get current user profile |
POST |
/api/url |
✓ | Create a short URL |
GET |
/api/url |
✓ | List user's URLs |
DELETE |
/api/url/:id |
✓ | Delete a URL |
GET |
/:shortCode |
✗ | Redirect → original URL |
| Endpoint | Limit | Behavior |
|---|---|---|
POST /api/auth/* |
10 req/min | Returns 429 |
POST /api/url |
30 req/min | Returns 429 |
GET /:shortCode |
No limit | Always redirects |
- Node.js 18+
- PostgreSQL 15+
- Redis 7+
npm install
node index.jsThe server starts on port 5001 (default).
Migrations run automatically on startup. To run manually:
npm run migrateCreate a .env file:
PORT=5001
DB_USER=postgres
DB_PASSWORD=postgres
DB_HOST=localhost
DB_NAME=devly
DB_PORT=5432
JWT_SECRET=supersecretkey_change_me_in_prod
ANALYTICS_URL=http://localhost:5002
REDIS_URL=redis://localhost:6379Docker: Use
DB_HOST=db,ANALYTICS_URL=http://analytics:5002,REDIS_URL=redis://redis:6379
| Repo | Description |
|---|---|
| dev.ly | Main repo (system design & orchestration) |
| dev.ly-frontend | Next.js dashboard |
| dev.ly-analytics | Analytics microservice |