How codinginflow/nextjs-15-social-media-app works
Project Type and Purpose
• This is a full-stack social media web application built with Next.js 15’s App Router.
• Key features: authentication (email/password + Google OAuth), infinite scrolling feeds, optimistic UI updates, direct messaging (real-time chat), notifications, file/image uploads.
File Structure
• Top-level “src/app” directory: Next.js App Router routes, React Server Components, and client components.
• (auth) pages handle login/signup and OAuth callbacks.
• (main) pages cover feeds, posts, profiles, DMs, notifications, search.
• “src/app/api” folder: Next.js API route handlers (REST endpoints for auth, posts, comments, likes, bookmarks, notifications, search, uploads, user data).
• “prisma/schema.prisma”: data model for relational DB (PostgreSQL or MySQL) via Prisma ORM.
• “src/lib”: client-side utilities (ky for HTTP, prisma client, validation, uploadthing, real-time stream helper).
• “src/components”: reusable UI bits (buttons, dialogs, posts, comments, chat UI).
• Configuration: next.config.mjs, vercel.json (deployment), tailwind.config.ts.
README for Additional Insights
• Confirms it’s a tutorial app demonstrating real-world features: infinite loading, optimistic updates, file uploads, DMs, notifications.
Main Components & Their Relationships
a. Client (Browser):
• Renders React components (UI), interacts via Server Components and Client Components.
• Uses React-Query for data fetching/caching, calls Next.js API endpoints.
b. Next.js Application Server:
• Serves pages (SSR+RSC), hosts API routes, orchestrates authentication (NextAuth or custom).
• Invokes Prisma Client to query/update the database.
c. Database (PostgreSQL/MySQL):
• Holds users, posts, comments, likes, bookmarks, messages, notifications.
d. External Services:
• OAuth Provider (Google for social login).
• File Upload Service (UploadThing, backing store could be S3).
• Real-time Messaging Service (stream or pusher, used for live chat/notifications).
e. Deployment:
• Hosted on Vercel (serverless functions for API routes, static asset CDN).
Data Flows & Interactions
• Authentication Flow:
User enters credentials → Next.js Auth API → OAuth provider (if Google) → Session cookie.
• Data Fetching:
Client uses React-Query → calls Next.js REST endpoints → Prisma → Database → JSON back to client.
• Infinite Scroll & Optimistic Updates:
Client paginates via “for-you” / “following” endpoints, updates UI immediately, syncs with server.
• File Upload:
Client requests upload token → calls UploadThing API route → gets upload URL → posts file directly to storage.
• Real-time Chat / Notifications:
Client subscribes to messaging service via SDK initialized in useInitializeChatClient.ts → server—via webhooks or triggers—pushes updates.
Architectural Patterns & Design Principles
• Monolithic Full-stack: Single codebase, clear separation between frontend routes and API routes.
• React Server Components for data fetching and rendering on the server.
• Client Components for interactivity (e.g., message input, like buttons).
• API Layer: Thin REST layer using Next.js “/api” routes.
• ORM Layer: Prisma for DB abstraction.
• CQRS-style split: Queries (feeds, search) vs. Mutations (like, comment, bookmark) organized under separate routes and “actions.ts” files.