Skip to content
LICObrPublic

About

URL shortener with click analytics — TypeScript, Express, SQLite, clean architecture.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

TinyTrail

CI

A URL shortener with click analytics, written in TypeScript. Create a short link, share it, and see every click it gets — count and last-accessed time.

Why this project

Shortening a URL is the easy part; the interesting bit is the click tracking: every redirect has to record an event without slowing down the redirect itself, and the storage layer has to hold up under one write per click.

Architecture

src/domain/       Link, Click, and the short code generator — no I/O
src/repository/    SQLite persistence (one shared connection, WAL mode)
src/service/         LinkService (create/resolve) and StatsService (clicks)
src/http/              Express app, route handlers, error middleware

LinkRepository and ClickRepository both receive an already-open better-sqlite3 connection instead of opening their own — sharing one connection avoids write contention on the same database file.

Running locally

npm install
npm run dev

The server starts on :3000 (override with PORT). Data is stored in data/tinytrail.db (override with DB_PATH).

API

Method Path Description
POST /links Create a short link ({ "url": "..." })
GET /:code Redirect to the original URL, records a click
GET /links/:code/stats Total clicks and last click time for a link

Example

curl -X POST localhost:3000/links -H "Content-Type: application/json" \
  -d '{"url":"https://example.com"}'

curl -i localhost:3000/<code>

curl localhost:3000/links/<code>/stats

Tests

npm test

16 tests: unit tests for the short code generator and both services, plus HTTP integration tests exercising the full create → redirect → stats flow with supertest.

Tech stack

TypeScript, Express, better-sqlite3 (synchronous SQLite driver — no ORM), Vitest. Kept intentionally small.

About

URL shortener with click analytics — TypeScript, Express, SQLite, clean architecture.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages