Monorepo for a URL-shortening app with a TypeScript backend and a Vite + React frontend.
Backend: TypeScript + tRPC + Prisma (Postgres). Located in backend/.
Frontend: Vite + React + TypeScript. Located in frontend/.
src/— server source (index.ts,routers/urlRouter.ts,context.ts).prisma/—schema.prismaand migration history.
-
Copy or create a
.envinbackend/with:DATABASE_URL="mysql://USER:PASSWORD@HOST:PORT/DATABASE" PORT=BACKEND_PORT DB_HOST=localhost DB_PORT=3306 DB_USER=_YOUR_DB_USER DB_PASSWORD=YOUR_DB_PASSWORD DB_NAME=YOUR_DB_NAME -
Install dependencies and prepare Prisma:
cd backend npm install npx prisma generate npx prisma migrate dev --name init
-
Run the dev server:
npm run dev
(If dev script differs, check backend/package.json.)
-
Install dependencies and run dev server:
cd frontend npm install npm run dev
-
Open the URL printed by Vite (usually
http://localhost:5173).
- User creates a short link in the frontend which calls the backend (tRPC) API.
- Backend generates a unique short code and stores a record
{ code, originalUrl, createdAt, clicks }in Postgres via Prisma. - Frontend receives the shortened URL and displays it to the user.
- When someone visits
https://your-domain/{code}, the backend route looks up the code, incrementsclicks, and responds with a 302 redirect to the original URL. - The backend exposes procedures (create, fetch, stats) in the tRPC router so the frontend can create links and fetch analytics.
- tRPC router:
backend/src/routers/urlRouter.ts— procedures for creating short links, resolving codes, and retrieving stats. - Redirect route: e.g.
GET /:codehandled by the server entry (backend/src/index.ts) which performs the lookup and redirect.