Application for shortening URLs with QR code generation, click counting, search, and pagination. Built with Astro 5, React, Tailwind CSS 4, and Astro DB, ready to deploy on Netlify.
- Site: https://brever.link
- Create short links with custom slugs.
- Automatic QR code generation (base64 Data URL) for each link.
- Redirection via middleware and click counter by slug.
- Listing with slug search and server-side pagination.
- Validation with Zod and React Hook Form, toasts with Sonner.
- Light/dark mode and UI with Tailwind CSS 4.
- Astro 5 (output: server) + @astrojs/netlify
- React 19 + @astrojs/react
- Tailwind CSS 4 (via @tailwindcss/vite)
- Astro DB (@astrojs/db) for persistence
- Astro Actions for server-side operations
- QRCode (qrcode) for QR code generation
db/
config.ts # Astro DB configuration (tables)
seed.ts # Seed data (pending implementation)
tables/
link.table.ts # LinkTable definition
src/
actions/ # Astro Actions (definition and handler)
components/ # React/Astro components (UI)
helpers/ # Utilities (classes, dates, etc.)
layouts/ # Astro layouts
pages/ # Astro pages (home, listing)
schemas/ # Zod schemas (form/action/filter)
services/ # DB services (CRUD, pagination, counters)
middleware.ts # Redirection logic + click increment
public/ # Static assets
Main table LinkTable (fields):
- id (text, PK)
- url (text)
- slug (text, unique)
- shortLink (text)
- createdAt (date)
- clickCount (number, default 0)
- qrCode (text, optional)
- Node.js 18.17+ (recommended 20+)
- pnpm 8+
- Install dependencies
pnpm install- Initialize database (local)
# Push schema to local DB
pnpm astro db push- Run in development
pnpm devThe app will open at http://localhost:4321 (Astro's default).
- Build and preview
pnpm build
pnpm previewNotes on remote DB:
- There are scripts for working with remote DB:
pnpm dev:remote,pnpm push:db(usesastro db push --remote). Remote configuration depends on your provider/environment and variables you configure. Check Astro DB documentation for the remote flow on your deployment platform.
pnpm dev— Starts development environment.pnpm dev:remote— Dev oriented to remote DB (if configured).pnpm build— Builds the project for production.pnpm preview— Serves the build locally.pnpm astro— Direct access to Astro CLI.pnpm lint— Formats with Prettier.pnpm lint:check— Checks code formatting without making changes.pnpm lint:eslint— Runs ESLint linting checks.pnpm lint:eslint:fix— Runs ESLint with automatic fixes.pnpm lint:fix— Formats with Prettier and runs ESLint with fixes.pnpm push:db—astro db push --remote.pnpm test— Runs tests in watch mode.pnpm test:run— Runs all tests once.pnpm test:coverage— Runs tests with coverage report.pnpm test:ui— Opens Vitest web interface.
- The form (
ShortLinkForm.tsx) validates with Zod and sends data to an Astro Action. - The action (
shorten.actions.ts) uses theshorLinkhandler (shorten.service.ts):- Verifies slug duplication.
- Generates
shortLinkandqrCode(withqrcode). - Inserts the record in
LinkTable.
- The
middleware.tsintercepts/{slug}routes:- Looks for the link, increments
clickCountand redirects (302) tourl.
- Looks for the link, increments
getAllPaginatedLinks(page, limit, slug)filters byslugmatch and paginates results. Inindex.astro,limit = 4is used andpageandsearchparameters from the URL are validated.
The project includes comprehensive testing with 261 tests across 15 test files achieving perfect 100% coverage:
- React Components: Complete UI component testing with user interactions (128 tests)
- Business Logic: Services, middleware, and data operations (53 tests)
- Schema Validation: Zod validation for forms and API actions (29 tests)
- URL Security: Comprehensive URL validation with security checks (29 tests) - HTTPS-only, private IP blocking
- Utilities: Helper functions and edge case handling (18 tests)
- Statements: 100% coverage
- Branches: 100% coverage
- Functions: 100% coverage
- Lines: 100% coverage
Run tests with:
# Watch mode for development
pnpm test
# Run all tests once
pnpm test:run
# Coverage report
pnpm test:coverage
# Web interface
pnpm test:uiFor detailed testing documentation, see TEST_README.md.
This project uses Husky to enforce code quality standards through Git hooks:
Automatically runs before each commit to ensure code quality:
- Code Formatting: Runs Prettier to fix formatting issues (
pnpm lint:fix) - Format Check: Verifies code formatting is consistent (
pnpm lint:check) - ESLint: Performs linting checks on TypeScript, JSX, and Astro files (
pnpm lint:eslint)
Validates commit messages follow Conventional Commits format:
- Uses commitlint with
@commitlint/config-conventional - Enforces structured commit messages for better project history
- See COMMIT_CONVENTIONS.md for detailed rules
- ESLint Configuration: Custom rules for TypeScript, React, and Astro files
- Prettier: Consistent code formatting across the project
- TypeScript: Strict type checking with custom rules
- Testing: Comprehensive test suite with 261 tests across 15 files achieving perfect 100% coverage
# Skip pre-commit hook (not recommended)
git commit --no-verify -m "emergency fix"
# Skip commit-msg validation (not recommended)
git commit --no-verify -m "fix: emergency commit"- Adapter:
@astrojs/netlify. - Define necessary variables/credentials for your remote DB in Netlify if you use them. Then build and publish with Netlify commands (build:
pnpm build).
- Implement
db/seed.tswith example data. - Add endpoint/action to delete/edit links if management is required.
- Consider implementing rate limiting for URL shortening.
- Add analytics dashboard for link performance tracking.
