How nawinsharma/shrinklyy-t3 works
Main components
• Frontend – Built with Next.js:
• Pages and layouts (e.g., landing page, authentication pages, dashboard, and short link pages found under src/app).
• Client-side hooks (under src/hooks) for functionality such as searching and handling URL short links.
• Backend & API Services:
• Next.js API Routes (in src/app/api) handling authentication ([...nextauth]) and tRPC endpoints ([trpc]).
• tRPC layers (in src/trpc and src/server/api/trpc.ts) ensuring type-safe communication between client and server.
• Server business logic, including authentication and business rules, contained within src/server (api routers for short links, authentication, and database communication).
• Database & ORM:
• Database configuration and access handled with Prisma. The prisma directory contains schema definitions and migration files (which interact with PostgreSQL as per the README).
• Authentication:
• NextAuth configuration to facilitate secure login through providers (GitHub, Google, etc.) with endpoints found under src/app/api/auth.
• Validation & Types:
• Input validation using Zod (as indicated in the README) with validations in src/validations for creating and updating short links.
• Shared TypeScript types (in src/types) ensuring consistent data contracts between various parts of the system.
Establish relationships and interactions
• The Next.js frontend interacts with the backend either via Next.js API routes (direct REST-like interactions) or through the tRPC layer for type-safe API calls.
• API endpoints forward requests to the server business logic in src/server. Business logic then interacts with Prisma to execute database operations.
• Authentication flows are triggered from the frontend and managed by NextAuth calling the appropriate API routes, integrating with third-party providers.
• The database component (PostgreSQL) is abstracted via Prisma with migrations documented in the prisma directory, ensuring type-safe schema and migration histories.
• Client-side hooks and libraries (src/lib) handle utilities such as URL encoding/decoding and formatting (e.g., timeAgo).
Architectural Patterns & Design Principles
• The app leverages a modern full-stack design where Next.js functions as both the frontend renderer and the backend server.
• It follows a modular design separating concerns: views (pages and UI components), business logic (server and API routers), and data access (Prisma with PostgreSQL).
• Type safety across the stack is ensured with TypeScript, Zod for runtime validation, and tRPC for the API layer minimizing boilerplate.
• Clear separation of client-side and server-side logic even within a unified framework (Next.js) is emphasized.
• Rectangles for major system components.
• Annotations where necessary:
• Detail that the Next.js app handles both SSR (server-side rendering) and API routing.
• Use of type safety across the stack (TypeScript, Zod).
• Point out that migrations and schema changes are managed via the Prisma directory.