How thangnv-pegasus/instagram-client works
Project Type and Purpose
• This is a full-stack web application using Next.js. Its purpose is to provide a dynamic, interactive web interface that supports different user states (guests and authenticated users), including features such as login/registration, user profiles, posts (including likes, comments, and reels), messaging, notifications, and explore/search functionalities.
• The project integrates both a frontend (with React components, layouts, and pages) and backend API endpoints handled via Next.js serverless functions.
Main Components
a. Frontend/UI Layer:
• Guest Layout: Contains pages for login, registration, and other public features (located under src/app/(guest-layout)).
• User Layout: Contains pages for authenticated users (profile, messages, explore, reels, search, notifications, etc.), organized under src/app/(user-layout).
• Shared and Reusable Components: Represent key UI components such as navigation bar, footer, modals, buttons, post components, comments, sliders, and story elements. These are organized in the src/components directory.
• Global Page Layout and Styles: Central layouts (src/app/layout.tsx, globals.css) and theming aspects (tailwind.config.ts, postcss.config.js).
b. Backend/API Layer:
• API Routes: Under src/app/api (and additional endpoints in src/pages/api for authentication with NextAuth), show components for handling authentication (login/logout), posts (like/unlike, details), comments, home feed (paginated posts and stories), and user profile updates.
• Authentication Module: auth.ts and NextAuth integration in src/pages/api/[...nextauth].ts.
• Utility and Type Definitions: Shared types (src/types) and utility functions (src/utils) that support the application logic.
c. External Dependencies and Infrastructure:
• Next.js configuration: next.config.mjs and related config files indicate that deployment may target Vercel or other Node environments.
• Environment Variables: Managed via .env.
• Package Dependencies: Provided by package.json and package-lock.json for npm management.
Relationships and Interactions
• User interactions from the browser (UI components and pages) communicate with server-side API routes.
• The UI layer (with its distinct guest and user layouts) makes AJAX/fetch calls to various API endpoints for data manipulation (authentication, comments, posts, profiles, etc.).
• That API routes are handled internally as Next.js serverless functions — typically a request coming to a certain URL (e.g., /api/auth, /api/post/[post_id]/like) invokes a specific handler.
Architectural Patterns and Design Principles
• File-based Routing: Emphasize Next.js’s file system-based routing both for pages and API endpoints.
• Component-based UI: The frontend is built using modular, reusable components.
• Separation of Layouts: Differentiate between guest and user layouts for better clarity in rendering for different user states.
• Serverless/API Functions: Note the use of serverless functions in Next.js for building the backend API, which facilitates a decoupled design between UI and server logic.
• Component Labels: Label directories or groups (e.g., src/app/(guest-layout), src/app/(user-layout), src/app/api) to map the physical structure.
• System Boundaries: Clearly illustrate where the frontend ends and where the API/backend begins.