Blueprint
Short links
CRUD, resolve, batch, public redirect pages.
API (/api/short-links/*)
| Route | Role |
|---|---|
GET/POST /api/short-links | List (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/generate | Generate short code / path |
POST /api/short-links/batch | Batch operations |
GET /api/short-links/search | Search |
GET /api/short-links/validate | Validate code before save |
GET /api/short-links/resolve/[code] | Resolve code → target URL (server) |
GET /api/short-links/stats | Aggregated 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
- Authenticated client calls POST
/api/short-linkswith validatedcreateShortLinkSchema. generateUserShortLink/ model layer persist rows.- Visitors hit
/i/[code]or resolve via/api/short-links/resolve/[code]— clicks may be tracked elsewhere (e.g.websites/track-clickif applicable).
Key files
src/app/api/short-links/**src/services/short-links.tssrc/lib/validations/short-links.ts
Dependencies
Environment
DATABASE_URL
Database (src/db/schema.ts)
short_links(target_user_id→users.id)users(owner /custom_usernamefor path-style links)