PHP backend case study

URL Shortener

Context: a small REST API for shortening links. The problem is that even a simple endpoint needs URL validation, custom aliases, repeatable shortening, and click statistics.

Case study

Technical scope

Some repositories are private until the work is closed. Project scope, technical decisions, and operating scenarios are described on the page. I can discuss the code during a technical conversation.

01

Problem

  • A short-link service needs stable short codes, input validation, and duplicate prevention for the same original URL.
  • The main risks are invalid URLs, alias conflicts, divergent web and CLI behavior, and no visibility into click activity.
02

Technical decision

  • Service layer, reverse lookup for repeated shortening, alias validation, separate ClickTracker, and a persistence boundary that can be replaced later.
  • UrlShortenerService coordinates validation, reverse lookup, persistence, and code generation so entrypoints stay thin.
  • Repository interfaces hide file persistence, while ClickTracker separates redirect behavior from statistics recording.
03

Result

  • The project shows discipline in a small API: predictable redirects, no duplicates for the same URL, click stats, and a simple path to changing storage.
  • Base62 code generation, URL validation, and custom alias handling.
  • Shared web/CLI logic for shortening, lookup, and statistics.
  • Click tracking and a simple statistics endpoint for shortened links.
04

Stack

  • PHP / REST API / Base62 / Stats
  • composer install
  • composer serve
  • composer demo-idempotency