How kartik-212004/social-media works
Main Components
• Frontend Client: Represented by the Next.js pages and UI components. This includes the various pages (account, dashboard, profile, search, etc.) and client-side components (navbar, middle/bar sidebars, login/signup forms, dark/light theme components, etc.).
• API & Server: The backend functions are implemented as Next.js API routes—organized under the app/api directory. These endpoints handle authentication, posts (create, delete, like, upload), likes, user settings, search functionalities, and AWS S3 operations.
• Real-Time Communication: Include the WebSocket server module (app/server/socket.js) which manages real-time notifications, messaging, or updates.
• Database: A PostgreSQL instance managed through Prisma (prisma/schema.prisma and migrations) that stores user data, posts, likes, and other application state.
• Media Storage: AWS S3 integration for handling media uploads and retrieval.
• External Services & Authentication: NextAuth.js for secure user authentication, alongside integrations with supporting libraries and services noted in the README.
Relationships and Interactions
• The Client (user’s browser) communicates with the Next.js application which serves both the UI and performs server-side rendering (SSR/SSG).
• The UI layer makes HTTP calls to the API endpoints to manage user actions (signup, login, posting content, liking posts, etc.).
• API endpoints interact with the PostgreSQL database via Prisma for CRUD operations on user data and posts.
• When handling media, API endpoints offload upload and deletion operations to AWS S3.
• Real-time communications are managed by a separate service (WebSocket server) that pushes notifications or live updates back to the client.
• NextAuth.js hooks into the API layer to manage secure authentication flows.
Important Architectural Patterns
• Separation of Concerns: Clear division between presentation (client-side UI) and data/API logic (server-side API routes).
• Modular Routing: The API routes are logically organized by functionality (auth, posts, settings, search, AWS S3 endpoints) to keep functionality isolated.
• Server-Side Rendering (SSR) and Static Site Generation (SSG): Leveraging Next.js’s built-in capabilities for improved performance and SEO.
• Real-Time Updates: Utilizing a WebSocket server to provide immediate feedback for notifications and messages.
• Use of Environment Configuration and Containerization: With Docker, GitHub workflows, and environment settings (.env.example) to manage deployment and consistency.
• The separation of the Next.js frontend and backend/API routes is crucial for understanding the flow of data.