Skip to content

Repository files navigation

URL Shortener - Interview Exercise

This is a minimal URL shortener built with Laravel 12 and FilamentPHP 4 based on the starter repository provided for the interview.

Features

1. Public URL shortener

  • GET /
    Displays a minimal HTML form where anyone can submit a long URL.

  • POST /
    Validates the submitted URL and returns a shortened URL.

Validation rules:

  • required
  • url (basic URL syntax)
  • active_url (domain must exist, DNS-level check)
  • max:2048

If the URL already exists in the database, the existing short code is reused. Otherwise, a new unique short code is generated.

  • GET /r/{code}
    Looks up the original URL by its short code and redirects to it using redirect()->away().

2. Short URL storage

Model: App\Models\ShortUrl

  • Table: short_urls
  • Columns:
    • id
    • code (unique, short string)
    • url (original URL)
    • created_at, updated_at

The model contains a helper method generateUniqueCode() that generates a random 6-character code and ensures uniqueness in the database.

3. Filament admin panel

  • Admin URL: /admin
  • Default user: admin@localhost / abcd1234 (created from the provided setup script or artisan command)
  • Resource: App\Filament\Resources\ShortUrls\ShortUrlResource

The resource provides:

  • List view of all short URLs (ID, code, original URL, created_at)
  • Create / Edit forms with the same validation as the public form:
    • required, url, activeUrl(), max length
  • Delete & bulk delete actions

4. Tests

Feature tests: tests/Feature/UrlShortenerTest.php

Covered scenarios:

  1. A long URL submitted on / creates a short_urls record and redirects back to / with the shortened URL in the session.
  2. GET /r/{code} redirects to the original URL stored for that code.
  3. An unknown short code returns a 404 response.

All tests can be executed with: php artisan test.


5. Running the application

The repository already contains a run.sh helper script as provided in the exercise.

Using the script (Linux / macOS)

First install PHP dependencies:

  • composer install

Then run:

  • ./run.sh

The script will:

  • copy .env.example to .env
  • generate the application key
  • run the database migrations
  • create the admin user (admin@localhost / abcd1234)
  • start the development server

Manual steps (for reference, e.g. on Windows)

  • composer install
  • cp .env.example .env
    Configure the database (SQLite is used in this implementation).
  • php artisan key:generate
  • php artisan migrate
  • php artisan make:filament-user --name=admin --email=admin@localhost --password=abcd1234
  • php artisan serve

Then open:


Possible extensions (not required for the exercise)

  • Expiration / soft delete for short URLs
  • Click statistics per code (number of redirects)
  • Rate limiting or spam protection on the public form
  • Configurable short code length or human-readable codes

About

url-shortener-laravel-filament

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages