How mchaker01/blog_mern_app works
Project Type and Purpose
• This is a full-stack web application built with the MERN stack (MongoDB, Express.js, React, Node.js).
• Purpose: provide a CRUD interface for blog posts (create, read, update, delete) via a REST API and an interactive SPA frontend.
File Structure
• Top-level folders:
• blog_backend/ – Node.js + Express API
• blog_frontend/ – React (Vite) SPA
• blog_backend/
• index.js – Express app entry point
• models/Post.js – Mongoose schema
• blog_frontend/
• public/, index.html – static shell
• src/ – React components, routing, CSS
• vite.config.js – build config
• Config files:
• .env (backend) for PORT and DB_URI
• CORS middleware setup in Express
Key Architecture Insights from README
• Frontend communicates with backend via fetch/Axios to REST endpoints (e.g., GET /posts, POST /posts).
• Server validates input, uses Mongoose to map to MongoDB.
• React Router handles client-side navigation.
• Development servers: Vite (frontend) on port 5173, Express (backend) on port 3000.
Main Components
a. User (Browser)
b. Frontend SPA (React + Vite dev server or static assets in production)
c. API Layer (Express.js server)
d. Business/Data Layer (Mongoose ODM)
e. MongoDB Database
f. Environment Configuration and External Tools (Dotenv, CORS)
Relationships & Data Flows
1. User interacts with React UI → React Router updates view.
2. React components call backend REST endpoints (HTTP).
3. Express.js controllers receive requests → perform server-side validation → invoke Mongoose models.
4. Mongoose queries or mutates MongoDB collections.
5. MongoDB returns data to Mongoose → Express → React.
6. React updates DOM state.
Architectural Patterns & Principles
• Separation of concerns: UI layer vs. API layer vs. data persistence.
• RESTful API design: resource-oriented endpoints for blog posts.
• MVC-lite in backend: models (Mongoose), controllers (Express routes), no separate view layer (API only).
• Client-side routing: React Router for navigation without full-page reloads.
• Environment-driven configuration: .env for ports and DB URI.
• CORS policy to isolate frontend and backend domains / ports.