How mrdxtr/urlshortener works
Project Type and Purpose
• This is a full‑stack web application (“URL Shortener”) built on the T3 Stack (Next.js App Router, tRPC, NextAuth, Prisma).
• Purpose: allow users to create, manage, and track shortened URLs with optional custom slugs, analytics, and secure authentication.
File Structure
• Frontend (Client):
• /src/app – Next.js App Router pages and layouts (React + TypeScript + Tailwind).
• /src/app/_components & /src/components – UI primitives and custom “magicui” components.
• API Layer:
• /src/app/api/trpc – Next.js API routes for tRPC handlers.
• /src/app/api/auth – NextAuth.js route implementing sign‑in, callbacks, sessions.
• Server / Business Logic:
• /src/server/api/routers/url.ts – tRPC router exposing CRUD and analytics.
• /src/server/auth – NextAuth configuration (OAuth providers, session callbacks).
• /src/server/db.ts – Prisma client setup.
• Shared / Utilities:
• /src/trpc – tRPC client and server wrappers.
• /src/lib/utils.ts – general helper functions.
• /src/hooks – React hooks (theme, mobile‐detection).
• Data Layer:
• prisma/schema.prisma – database schema for URLs, users, analytics.
• Underlying DB: PostgreSQL (or any supported by Prisma).
• Config & Deployment Files:
• next.config.js, .env.example, package.json, Dockerfile (optional), Vercel/Netlify settings.
README Insights
• Confirms tech stack and highlights features: authentication, custom slugs, analytics.
• Suggests deployment targets (Vercel, Netlify, Docker).
• Describes project structure at a high level.
Main Components
a. Frontend Layer
– Next.js App Router (pages, layouts, components)
– UI Components (Tailwind CSS, magicui)
– React Query/trpc client
b. API & Auth Layer
– NextAuth.js (authentication, session management)
– tRPC API Server (type‑safe RPC endpoints)
c. Business Logic / Service Layer
– tRPC routers (URL management, analytics)
– Validation / Content‑filtering logic
d. Data Access Layer
– Prisma ORM
– PostgreSQL Database
e. External / Infrastructure
– CDN or Static files host (serving /public assets)
– Hosting platform (Vercel, Docker, etc.)
– Optional: Analytics dashboard or third‑party services
Relationships & Data Flows
• User’s Browser → (HTTPS) → Next.js Frontend
• Frontend → tRPC Client → tRPC API Routes
• Auth flow: NextAuth calls external OAuth providers or email links → NextAuth callbacks → session cookie
• tRPC Routers → Prisma Client → PostgreSQL
• Redirect requests (public slug routes) → Lookup via Prisma → Increment analytics → Redirect response
Architectural Patterns & Design Principles
• Layered architecture: Presentation → API → Business Logic → Data Access
• Separation of concerns: UI, authentication, API, data.
• Type safety & end‑to‑end types (TypeScript + tRPC).
• Server‑side rendering / streaming via Next.js App Router.
• Stateless functions (API routes) and stateful DB.
Essential Elements
• Notes on environment variables or config store (e.g., .env for DB URL, OAuth secrets).