How ihtasham42/social-media-app works
Project Type and Purpose
• PostIt is a full-stack social media web application built on the MERN stack (MongoDB, Express, React, Node.js) with real-time messaging via Socket.io.
• It provides CRUD operations on posts and comments, user authentication with JWT, live private messaging, infinite scrolling, search, and nested comments.
File Structure for Architectural Components
• Top-level:
• client/ — React single-page application (frontend)
• controllers/, models/, routes/, middleware/ — Express MVC layers (backend)
• server.js & socketServer.js — HTTP and WebSocket entrypoints
• util/ — shared utilities (filtering, pagination)
• client/src/api/ — wrappers for REST endpoints
• client/src/components/ — UI components and view containers
• client/src/helpers/ — client-side auth and socket initialization
• models/ — Mongoose schemas (User, Post, Comment, Message, etc.)
• controllers/ — business logic for each resource
• routes/ — Express routers mapping HTTP methods to controllers
• middleware/auth.js — JWT authentication guard
Extract Insights from the README
• Confirms RESTful API design plus Socket.io for real-time messaging.
• Emphasizes key features: Posts, Comments, Likes, Profiles, Real-time Chat, Infinite scroll, Profanity filtering, JWT security.
Main System Components
a. Frontend (React SPA)
• UI views, state management, API clients, WebSocket client
• Serves static assets and communicates with backend over HTTP and WS
b. Backend HTTP API (Express)
• Routes → Controllers → Models → MongoDB
• JWT authentication middleware, profanity filtering, pagination
c. Real-time Messaging Server (Socket.io)
• socketServer.js manages WebSocket connections, authentication, message events
• Integrates with MongoDB to persist Conversations & Messages
d. Database (MongoDB Atlas)
• Collections: users, posts, comments, likes, messages, conversations, follows
• Accessed via Mongoose ODM
e. External Services
• MongoDB Atlas cluster
• Optional: hosting platform (Heroku)
Relationships and Data Flows
• User → logs in via React → sends credentials to Express → JWT returned
• React → API calls (GET/POST/PUT/DELETE) → Express routes → Controller → Mongoose queries → MongoDB
• React → connects to Socket.io → authenticated via JWT → real-time message exchange → persistence
• UI reacts to API & socket events to update views
Architectural Patterns
• MVC on the server side (Routes-Controllers-Models)
• Layered architecture: Presentation (React), Application (API & WebSocket), Data (MongoDB)
• RESTful endpoints for resource operations
• Event-driven real-time messaging for chat via WebSocket
• Shared utility modules for filtering and pagination