How williamzshih/instagram works
Main Components
A. Client-Side Layer:
• Next.js Frontend (React Components)
• Route Structure (/src/app/(routes))
• UI Components (/src/components)
• Modal System (@modal parallel route)
• State Management (React Query)
• Theme System (Dark/Light mode)
B. Server-Side Layer:
• Next.js API Routes (/src/app/api)
• Authentication System (Auth.js)
• Database Layer (Prisma + MongoDB)
C. External Services:
• Pinata IPFS (Image Storage)
• MongoDB Atlas
• Google OAuth
Component Relationships
[Client Layer]
• ↑↓
[Next.js Server Layer]
• ↑↓
[External Services]
Detailed Component Breakdown
Frontend (Blue Components):
• Component hierarchy from /src/components
• Shared UI components from /src/components/ui
API Layer (Green Components):
• Authentication endpoints (/api/auth)
• User management endpoints (/api/user)
• Action handlers (/src/actions)
Database Layer (Yellow Components):
• Prisma schema relationships
• Models: User, Post, Comment, Like, Bookmark, Follow
External Services (Purple Components):
• Pinata IPFS connection
• MongoDB Atlas
• Auth providers
Data Flow Visualization
• Client-server communication
• Authentication flow
• Image upload process
• Database operations
• Real-time updates
[Google OAuth] ←→ [Auth.js] ←→ [Next.js API] ←→ [Database]
[Client] → [Next.js API] → [Pinata IPFS] → [MongoDB Storage]
[Client Query Cache] ←→ [Server Actions] ←→ [Database]
Important Elements to Highlight
• Server Actions (/src/actions) for data mutations
• Modal system implementation (@modal route group)
• Authentication middleware
• React Query integration for state management
• Prisma ORM layer
Additional Notes
Architectural patterns:
• Route Groups pattern (Next.js file-system routing)
• Server Components vs Client Components
• Parallel Routes for modal implementation
• Repository pattern in database access
• Optimistic updates pattern
This system design should reflect the modern Next.js 14 architecture while showing how all the pieces work together to create a robust Instagram clone.