A fast URL shortener with analytics dashboard and custom domain support.
- Next.js 14 (App Router) - Full-stack React framework
- TypeScript - Type safety throughout
- PostgreSQL - Database via Vercel Postgres or Neon
- Prisma - Type-safe ORM
- Tailwind CSS - Styling
- Vercel - Deployment with edge functions
- Node.js 20+
- PostgreSQL database (local or hosted)
-
Clone the repository:
git clone <repo-url> cd shorty
-
Install dependencies:
npm install
-
Set up environment variables:
cp .env.example .env.local
Edit
.env.localwith your database URL and other settings. -
Generate Prisma client:
npm run db:generate
-
Run database migrations:
npm run db:migrate
-
Start the development server:
npm run dev
-
Open http://localhost:3000 in your browser.
| Command | Description |
|---|---|
npm run dev |
Start development server |
npm run build |
Build for production |
npm run start |
Start production server |
npm run lint |
Run ESLint |
npm run type-check |
Run TypeScript type checking |
npm run test |
Run tests in watch mode |
npm run test:run |
Run tests once |
npm run test:coverage |
Run tests with coverage |
npm run db:generate |
Generate Prisma client |
npm run db:migrate |
Run database migrations |
npm run db:push |
Push schema to database |
npm run db:studio |
Open Prisma Studio |
shorty/
├── app/ # Next.js App Router
│ ├── (dashboard)/ # Dashboard routes
│ ├── [slug]/ # Redirect handler (edge)
│ └── api/ # API routes
├── components/ # React components
├── lib/ # Utilities and helpers
├── prisma/ # Database schema
└── public/ # Static assets
Production: https://shorty-ten-lime.vercel.app
This project is configured for deployment on Vercel:
# Link to Vercel (first time)
vercel link
# Deploy to preview/staging
vercel
# Deploy to production
vercel --prodSet the following environment variables in your Vercel project:
| Variable | Description | Example |
|---|---|---|
DATABASE_URL |
PostgreSQL connection string (pooled) | postgresql://user:pass@host/db?sslmode=require |
DIRECT_URL |
PostgreSQL direct connection (for migrations) | postgresql://user:pass@host/db?sslmode=require |
NEXT_PUBLIC_APP_URL |
Public URL of the app | https://shorty-ten-lime.vercel.app |
DEFAULT_DOMAIN |
Default domain for short links | shorty-ten-lime.vercel.app |
ENABLE_GEO_TRACKING |
Enable geolocation tracking | true |
- Go to Vercel Dashboard → Your Project → Storage
- Add Neon Postgres integration
- The
DATABASE_URLandDIRECT_URLwill be automatically configured - Run migrations:
npx prisma db push
The project includes comprehensive monitoring capabilities:
- Health Check Endpoint:
GET /api/health- Returns database status and application health - Error Tracking: Sentry integration for error capture and performance monitoring
- Structured Logging: JSON-formatted logs in production for log aggregation
-
Set up Sentry:
SENTRY_DSN="your-sentry-dsn" NEXT_PUBLIC_SENTRY_DSN="your-sentry-dsn"
-
Configure uptime monitoring to poll
/api/health
See docs/MONITORING.md for full monitoring documentation including alerting setup.
The project uses Vitest for testing. Tests are organized as follows:
lib/__tests__/ # Unit tests for utilities
├── validators.test.ts # Zod schema validation tests
├── utils.test.ts # Utility function tests
└── geo.test.ts # Geolocation helper tests
app/api/__tests__/ # API integration tests
├── links.test.ts # Links API tests
└── domains.test.ts # Domains API tests
Run all tests:
npm run test:run- URL validator accepts any protocol: The Zod
.url()validator accepts any valid URL includingftp://,file://, etc. For a URL shortener, you may want to restrict tohttp://andhttps://only. - Domain verification requires DNS propagation: After adding a TXT record, DNS propagation can take up to 48 hours. The verification endpoint will fail until propagation completes.
- No rate limiting: API endpoints have no rate limiting implemented. For production, add rate limiting to prevent abuse.
- No authentication: The dashboard and API are currently unprotected. Add authentication before deploying to production.
- Add user authentication (e.g., NextAuth.js)
- Implement rate limiting
- Add link expiration dates
- Add QR code generation
- Add bulk link creation/import
- Add link password protection
MIT