Built with Dark Factory v4 — autonomous AI software development pipeline
A URL shortener API with analytics dashboard built with Next.js 15, TypeScript, and Tailwind CSS.
- Shorten URLs with 6-character alphanumeric codes
- Click tracking and analytics
- Dark-themed responsive dashboard
- In-memory storage (no database required)
- RESTful API endpoints
- Node.js 18+
- npm
- Clone the repository:
git clone <repository-url>
cd link-shortener- Install dependencies:
npm install- Set up environment variables:
cp .env.example .env- Start the development server:
npm run devThe application will be available at http://localhost:4004.
npm run build
npm startShorten a URL.
Request Body:
{
"url": "https://example.com"
}Response:
{
"shortCode": "abc123",
"shortUrl": "http://localhost:4004/api/abc123",
"originalUrl": "https://example.com"
}Redirect to the original URL and increment click count.
Response: 302 redirect or 404 if code not found.
Get analytics for all shortened URLs.
Response:
[
{
"shortCode": "abc123",
"originalUrl": "https://example.com",
"clicks": 5,
"createdAt": "2024-01-01T00:00:00.000Z"
}
]PORT: Server port (default: 4004)NEXT_PUBLIC_BASE_URL: Base URL for short links
- Framework: Next.js 15 (App Router)
- Language: TypeScript (strict mode)
- Styling: Tailwind CSS
- Storage: In-memory Map
- Validation: Zod
src/
├── app/
│ ├── api/
│ │ ├── [code]/route.ts # Redirect endpoint
│ │ ├── shorten/route.ts # URL shortening endpoint
│ │ └── stats/route.ts # Analytics endpoint
│ ├── globals.css # Global styles
│ ├── layout.tsx # Root layout
│ └── page.tsx # Dashboard page
└── lib/
├── store.ts # In-memory storage
├── types.ts # TypeScript interfaces
└── utils.ts # Utility functions
MIT — see LICENSE