Source: Jolli-sample-repos/url-shortener Last Updated: 4/8/2026
Data Models
TypeScript interfaces and schemas defining the application’s data structures.
ShortUrl
Core data model representing a shortened URL.
// models.ts
interface ShortUrl {
shortCode: string; // "AbC123" or custom
longUrl: string; // Destination
createdAt: string; // ISO 8601
expiresAt?: string; // Optional ISO 8601
clicks: number; // Redirect count
lastAccessedAt?: string; // ISO 8601
}Validation - Zod schemas for request validation:
// validator.ts - Zod schemas
createUrlSchema = z.object({
longUrl: z.string().url(), // RFC 3986
customCode: z.string().regex(/^[a-zA-Z0-9]+$/).min(4).max(20).optional(),
expiresAt: z.string().datetime().optional()
});Constraints - Field-level validation rules:
shortCode: 4-20 alphanumeric, uniquelongUrl: Must include protocol (https://example.comnotexample.com)expiresAt: Returns 410 Gone after expiration
Responses
API response structures for various endpoints.
PaginatedResponse - List endpoint response:
{
urls: ShortUrl[],
total: number,
page: number,
limit: number,
hasMore: boolean
}GlobalStats - Analytics endpoint response:
{
totalUrls: number,
totalClicks: number,
activeUrls: number,
expiredUrls: number
}