A modern, scalable, and secure backend service for URL shortening, QR generation, and link analytics.
ShortLink is a backend API platform that powers the ShortLink web application.
It provides core functionalities such as URL shortening, QR code generation, authentication, and analytics.
Built with Node.js, Express, and TypeScript, it follows a clean modular architecture ensuring scalability, maintainability, and developer productivity.
| Category | Description |
|---|---|
| π Authentication | Secure login, registration, and token refresh using JWT. |
| π URL Shortening (CRUD) | Create, update, retrieve, and delete short URLs with optional password protection. |
| π· QR Code Generation | Generate downloadable QR codes for shortened URLs using built-in QR utilities. |
| π§Ύ QR History Management | Track user QR scans and store them with pagination. |
| π Link Analytics | Count and visualize number of visits per alias. |
| π§ Rate Limiting | Prevent abuse with request throttling. |
| π§° Validation Layer | Schema validation via Zod and Joi equivalents. |
| βοΈ File & Image Storage | AWS S3 integration for uploaded assets. |
| π¬ Email Service | Nodemailer for password recovery and notifications. |
| π§± ServiceResponse Model | Standard response structure across APIs. |
| π‘οΈ Error Handling Middleware | Centralized error management & logging. |
| π§© Modular Architecture | Each API (auth, user, url) is self-contained for clarity and scalability. |
π¦ shortlink-backend/
βββ src/
β βββ api/
β β βββ auth/ # Authentication (JWT, login/register)
β β βββ url/ # URL Shortening & QR
β β βββ user/ # User management
β βββ common/
β β βββ constant/ # Enums, messages, config
β β βββ middleware/ # Logger, rateLimiter, errorHandler
β β βββ models/ # Mongoose models & response objects
β β βββ services/ # Database & utility services
β β βββ utils/ # Helper modules (JWT, email, QR, random, etc.)
β βββ server.ts # Express app setup
β βββ index.ts # Entry point
β βββ type.d.ts # Type declarations
βββ Dockerfile
βββ package.json
βββ tsconfig.json
βββ .env.example
βββ README.md
# 1. Install dependencies
pnpm install
# 2. Set up environment variables
cp .env.example .env
# 3. Run development server
pnpm dev
# 4. Build production bundle
pnpm build
# 5. Start production server
pnpm start| Method | Endpoint | Description |
|---|---|---|
POST |
/auth/register |
Register new user |
POST |
/auth/login |
User login |
POST |
/auth/refresh-token |
Refresh JWT token |
GET |
/auth/forgot-password |
Send email forgot password |
POST |
/auth/reset-password |
Reset password |
POST |
/auth/logout |
Logout to the application |
GET |
/user/get-me |
Get user information |
POST |
/ |
Create short URL |
GET |
/my-urls |
Get list userβs URLs |
PATCH |
/:alias |
Update URL |
DELETE |
/my-urls |
Delete URL |
POST |
/qr-history |
Save QR scan history |
GET |
/:alias |
Resolve short link to destination |
... |
.... |
And more... |
ShortLink Backend follows a Layered Architecture for better scalability:
- Controller Layer β Handles HTTP requests and responses.
- Service Layer β Core business logic and database operations.
- Model Layer β Mongoose schemas and document modeling.
- Middleware Layer β Security, validation, and logging.
- Utility Layer β Shared helpers (QR, JWT, Email, etc).
The project supports integration tests with Vitest.
# Run all tests
pnpm test
# Run a specific test
pnpm test src/api/user/__tests__/user.integration.test.tsπ¨βπ» Project: ShortLink
π§ Contact: shortlink.tool@gmail.com
π Website: https://shortlinkz.online
Made by duyaivy with π.