How elion74/tblogs works
Project Type & Purpose
• TBlogs is a full-stack social media application.
• Frontend: React.js SPA (single-page application).
• Backend: Node.js + Express REST API.
• Persistence: MongoDB (with Mongoose models) + local file storage for images (via multer).
File Structure
• Top-level split:
• /client → React app (components, pages, services).
• /backend → Express.js API (controllers, models, routes, config, middlewares).
• Key backend files:
• backend/server.js – entry point, sets up Express, CORS, cookie parsing, routes.
• backend/config/Storage.js – multer config for file uploads.
• controllers/*_controller.js – business logic for auth, posts, articles, home.
• models/*_model.js – Mongoose schemas for users and posts.
• routes/*_routes.js – route definitions (mount controllers).
• middlewares/checkAuth.js – JWT authentication guard.
• Key frontend files:
• client/src/index.js – React root.
• client/src/components & client/src/pages – UI components and page layouts.
• client/src/services/*.js – modules to call backend API endpoints.
Extract Insights from README
• Uses JWT + bcrypt for auth, CORS and cookies for sessions.
• Image uploads handled with multer.
• Two separate npm processes: npm start on client (port 3000) and backend (port 5000).
Main Components & Their Interactions
a. Frontend (React SPA)
• Hosts UI pages (Home, Article, Create, Login, MyBlog, Update, Error).
• Calls backend via fetch/axios in services/*.js.
b. Backend API (Express)
• Exposes endpoints: /auth/*, /article/*, /post/*, /home/*.
• Middlewares: CORS, cookie-parser, body-parsing, JWT auth.
c. Business Logic
• Controllers receive HTTP requests, perform validation, talk to models.
d. Data Layer
• Mongoose models connect to MongoDB.
• Local image storage (imguploads folder) via multer Storage.js.
e. External Services & Libraries
• MongoDB database.
• bcrypt (password hashing), jsonwebtoken (JWT), multer (file upload), cors, cookie-parser.
Architectural Patterns & Principles
• Clear separation of concerns:
• Presentation (React) vs API layer (Express) vs Data (MongoDB).
• MVC-like pattern in backend: Controllers → Models → Views (HTTP responses).
• Use of middleware pipeline for cross-cutting concerns (auth, parsing).
• RESTful resource naming in routes.
Essential Elements
• Component labels: React UI, HTTP Client, Express Router, Controllers, Models, MongoDB, Image Store.
• Blue: Frontend
• Green: Backend core
• Orange: Data & Storage
• Notes on key libraries (Mongoose, bcrypt, multer).
• How the user interacts with the React front end.
• How that front end uses the services layer to communicate with the Express API.
• How Express routes requests through authentication and business logic to the data layer.
• Where images and user data reside.
This level of detail ensures all stakeholders can see the end-to-end flow and understand each component’s responsibilities. Happy diagramming!