Blueprint

Short links

CRUD, resolve, batch, public redirect pages.

RouteRole
GET/POST /api/short-linksList (paginated, filters) / create short links for the logged-in user; Zod in src/lib/validations/short-links.ts; services in src/services/short-links.ts
GET/PATCH/DELETE /api/short-links/[id]Single link CRUD
POST /api/short-links/generateGenerate short code / path
POST /api/short-links/batchBatch operations
GET /api/short-links/searchSearch
GET /api/short-links/validateValidate code before save
GET /api/short-links/resolve/[code]Resolve code → target URL (server)
GET /api/short-links/statsAggregated stats

App routes

  • /[locale]/i/[code] — public redirect/landing for a short code (src/app/[locale]/(default)/i/[code]/page.tsx).
  • /[locale]/u/[shortId] — user-facing short profile path (src/app/[locale]/u/[shortId]/page.tsx).
  • /u/[username] — root-level username page (src/app/u/[username]/page.tsx).

Data flow

  1. Authenticated client calls POST /api/short-links with validated createShortLinkSchema.
  2. generateUserShortLink / model layer persist rows.
  3. Visitors hit /i/[code] or resolve via /api/short-links/resolve/[code] — clicks may be tracked elsewhere (e.g. websites/track-click if applicable).

Key files

  • src/app/api/short-links/**
  • src/services/short-links.ts
  • src/lib/validations/short-links.ts

Dependencies

Environment

  • DATABASE_URL

Database (src/db/schema.ts)

  • short_links (target_user_id → users.id)
  • users (owner / custom_username for path-style links)
Short links | Tracker Dog Docs