Skip to content

PresidentAnderson/shorty

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shorty

A fast URL shortener with analytics dashboard and custom domain support.

Tech Stack

  • 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

Getting Started

Prerequisites

  • Node.js 20+
  • PostgreSQL database (local or hosted)

Installation

  1. Clone the repository:

    git clone <repo-url>
    cd shorty
  2. Install dependencies:

    npm install
  3. Set up environment variables:

    cp .env.example .env.local

    Edit .env.local with your database URL and other settings.

  4. Generate Prisma client:

    npm run db:generate
  5. Run database migrations:

    npm run db:migrate
  6. Start the development server:

    npm run dev
  7. Open http://localhost:3000 in your browser.

Scripts

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

Project Structure

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

Deployment

Production URL

Production: https://shorty-ten-lime.vercel.app

Deploy to Vercel

This project is configured for deployment on Vercel:

# Link to Vercel (first time)
vercel link

# Deploy to preview/staging
vercel

# Deploy to production
vercel --prod

Environment Variables

Set 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

Database Setup

  1. Go to Vercel Dashboard → Your Project → Storage
  2. Add Neon Postgres integration
  3. The DATABASE_URL and DIRECT_URL will be automatically configured
  4. Run migrations: npx prisma db push

Monitoring

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

Quick Setup

  1. Set up Sentry:

    SENTRY_DSN="your-sentry-dsn"
    NEXT_PUBLIC_SENTRY_DSN="your-sentry-dsn"
  2. Configure uptime monitoring to poll /api/health

See docs/MONITORING.md for full monitoring documentation including alerting setup.

Testing

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

TODO

Known Issues

  • URL validator accepts any protocol: The Zod .url() validator accepts any valid URL including ftp://, file://, etc. For a URL shortener, you may want to restrict to http:// and https:// 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.

Future Improvements

  • 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

License

MIT

About

URL shortener with analytics dashboard and custom domains

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published