How viswassomapongu/mern-blog works
Project Type & Purpose
• This is a MERN (MongoDB, Express, React, Node.js) full-stack blog application.
• It is designed to provide secure user authentication (including Google OAuth), an interactive commenting system, user/post management (including admin-level controls), advanced search functionality, and a responsive UI that supports dark mode.
• The frontend is built with React (using Vite as the bundler and Tailwind CSS for styling), and the backend uses Node.js with Express.js to expose API endpoints to handle data storage and user management using MongoDB.
Breakdown of the File Structure
• The top-level file tree shows two main directories: "api" (which houses the backend code) and "client" (which contains the frontend code).
• The client folder holds the React frontend components, pages, and configuration files (e.g., vite.config.js, tailwind.config.js). The structure (components, pages, redux, assets) suggests a modular approach with state management (using redux).
Key Components
• Client (Frontend):
• React application (components, pages, and global state management via Redux).
• Utilizes Tailwind CSS and Flowbite for UI styling.
• Supports authentication, navigation (private routes, OAuth component), and dark mode.
• Server (Backend):
• Express.js application that serves as the API layer.
• Organized into controllers (auth, post, comment, user), models (for corresponding data structures in MongoDB), and routes that capture API endpoints for authentication, CRUD operations, and comment handling.
• Utility modules for error handling and verification (verifyUser middleware).
• Database:
• MongoDB interacts with the backend, storing data for users, posts, and comments.
• External Services:
• Google OAuth for authentication.
• Possibly third-party libraries/frameworks used in both frontend (Vite, TailwindCSS) and backend (Express.js, Mongoose).
Relationships & Interactions
• The Client sends HTTP requests (GET, POST, PUT, DELETE) to the Server’s RESTful API endpoints.
• The API routes in the "api/routes" directory direct the requests to the appropriate controllers, which in turn interact with MongoDB using the defined models.
• The authentication flow (including Google OAuth) involves coordination between client-side components (e.g., OAuth.jsx) and backend authentication controllers.
• Admin-specific routes and functionalities are also handled by the backend, with the client presenting dedicated dashboard components for managing posts, comments, and users.
Architectural Patterns & Design Principles
• MVC-like separation in the backend.
• Component-based architecture on the frontend with clear separation of pages, shared components, and state management.
• Clear division between client and server along with well-defined API endpoints.
• Usage of utility modules (e.g., verifyUser middleware) to encapsulate cross-cutting concerns like authentication and error handling.