How mdsaad09/news works
Project Type and Purpose
• NewsHub is a full-stack MERN (MongoDB, Express, React, Node.js) application.
• Purpose: a personalized, real-time news platform with user roles (admin, reporter, consumer), CRUD operations for news, categories, pages, user management, and file uploads.
File Structure
• Top level:
• client/ – React app (Tailwind CSS + Redux)
• server/ – Node.js + Express API
• README.md, package.json, .gitignore
• client/ subdivisions:
• src/components → reusable UI components (auth guards, news cards, layout)
• src/pages → page-level routes (Home, Login, Admin panel, Reporter panel)
• src/redux → slices (auth), store
• src/services → Axios wrappers for backend endpoints
• server/ subdivisions:
• config/db.js → MongoDB connection
• models/ → Mongoose schemas (User, News, Category, Page, Settings, Comment)
• controllers/ → Express route handlers (MVC “Controller”)
• routes/ → endpoint definitions, grouped by feature
• middleware/authMiddleware.js → JWT authentication/authorization
• utils/ → file upload, document parsing
• uploads/ → file-system storage for images & temp files
• Key config: server/server.js (entry point), .env, client/vite.config.js
README for Insights
• Stack: MongoDB, Express, React, Node.js, Tailwind CSS, Redux, Axios, NewsAPI
• Features: category feeds, search, bookmarks, dark/light mode, push notifications
• Roles: Admin, Reporter, Consumer
Main Components
a. Frontend (React):
• Components: Pages, Layout, Auth components, Redux store, HTTP services
b. API Server (Node.js/Express):
• Authentication layer (JWT middleware)
• Controllers & Routes (Auth, News, Category, Page, Settings, User, Uploads)
• Services & utils (fileUpload, documentParser)
c. Database: MongoDB (Users, News, Categories, Pages, Settings, Comments)
d. File Storage: Local filesystem under server/uploads (images + temp)
e. External Service: NewsAPI for live feeds (optional integration point)
Relationships and Data Flows
• User’s Browser ↔ (HTTPS) ↔ React Frontend
• React Frontend → dispatches Redux actions → calls Axios services → HTTP requests
• Express API receives requests → authMiddleware → controllers → models → MongoDB
• Controllers that accept file uploads → utils/fileUpload → server/uploads
• (Optional) API Server → fetch → NewsAPI for external news ingestion
• Real-time updates via HTTP polling or WebSockets (if implemented in future)
Architectural Patterns & Design Principles
• Separation of concerns:
• Presentation (React) vs Business logic (Express controllers/services) vs Data layer (Mongoose models)
• MVC-style on backend: models, controllers, routes
• Layered Security: JWT auth middleware protects routes; role-based guards (AdminRoute/ReporterRoute) on frontend
• State management: Redux central store, slices (authSlice)
• Service abstraction: client/src/services/* wraps all API calls
Technologies & Frameworks to Highlight
• React + Vite + Tailwind CSS
• Redux Toolkit for state
• Axios for HTTP
• Node.js + Express for REST API
• Mongoose/MongoDB for persistence
• JWT for authentication
• Local filesystem storage for uploads