A full-stack URL shortener application built with Node.js (Express), React, Prisma, PostgreSQL, Docker Compose, and Prometheus for metrics.
- User Authentication: Register, login, and manage sessions (JWT-based).
- URL Shortening: Authenticated users can create and manage their own short URLs. Anonymous users can also shorten URLs.
- User Dashboard: View and manage your shortened URLs and see click statistics.
- Prometheus Metrics: Integrated Prometheus client for monitoring HTTP requests and active users.
- Docker Compose: Easily run the backend and PostgreSQL database with Docker Compose.
- Prisma ORM: Type-safe database access and migrations.
- PostgreSQL: Robust relational database.
- React Frontend: Modern, minimal UI with authentication and dashboard.
backend/
├── controller/
├── dao/
├── middleware/
├── prisma/
├── router/
├── services/
├── utils/
├── Dockerfile
├── docker-compose.yml
├── index.js
└── package.json
frontend/
├── src/
├── index.html
├── package.json
└── vite.config.js
-
Configure Environment Variables
Copy.env.exampleto.envand set your secrets (e.g.,JWT_SECRET,DATABASE_URL). -
Run with Docker Compose
From thebackenddirectory:docker-compose up --build
-
Apply Prisma Migrations
npx prisma migrate deploy
-
Seed the Database (optional)
node prisma/seed.js
-
Prometheus Metrics
Metrics are exposed at http://localhost:5000/metrics.
-
Install dependencies
cd frontend npm install -
Start the development server
npm run dev
-
Open http://localhost:5173 in your browser.
POST /api/auth/register— Register a new userPOST /api/auth/login— Login and receive JWTGET /api/auth/me— Get current user (requires JWT)POST /api/create/— Create a short URL (requires JWT for user URLs)POST /api/user/urls— Get all URLs for the authenticated userGET /:shortUrl— Redirect to the original URL
- Prometheus metrics available at
/metricsendpoint.
MIT
Stack: Node.js, Express, React, Prisma, PostgreSQL, Docker, Prometheus