How ghsjulian/mini-facebook works
Main Components
• Frontend Client: Represent the React application (located in the “frontend” directory) which handles views, routes, UI components, state/context management (MessageContext, SocketContext, authentication hooks), and pages (e.g., Home, Login, Profile, ChatBox).
• Backend Server: Show the Node.js server (under the “server” directory) that includes controllers for users, posts, and messages, as well as middleware (e.g., authentication, friendship validation) and import/export of utility functions. Also, indicate separate modules for routes and models that map to the MongoDB collections.
• Real-Time / Socket Layer: Highlight the “server/sockets” module that handles socket events for live chatting, file sending, and notifications.
• External Interfaces: Optionally show how the HTTP API endpoints and WebSocket communications connect the client and server.
Interactions and Data Flow
• The Frontend React application makes standard HTTP requests (using RESTful endpoints) to the backend for functionalities like creating or editing posts, authentication, friend requests, etc.
• A dedicated WebSocket connection (illustrated from SocketContext on client and “server/sockets/socket.js” on the backend) is used for real-time chat and notifications.
• The Backend server processes requests using controllers and routes; it also applies middleware checks for user authentication or friendship validations.
• Data persistence is handled by the MongoDB database, which stores and retrieves user info, posts, conversations, and messages.
Architectural Patterns / Design Principles
• Clear separation of concerns: Split between frontend and backend.
• MVC-like structure on the server: Models, Controllers, and Routes are distinctly organized.
• Modular design in the frontend: Components, layouts, contexts, and hooks are isolated for re-usability.
• Use of environment-specific configuration (.env files) to manage deployment variables.
• Real-time data handling via socket integration.
Relevant Technologies and Tools
• Frontend: React, Vite, JSX components, context providers, React hooks.
• Backend: Node.js, Express (or similar routing mechanism), middleware for authentication and relationships, RESTful API design.
• Database: MongoDB, with schema models for user interactions.
• Sockets: Likely using a library like Socket.IO for real-time messaging.
• Supplementary: Tools like Git for versioning, and possibly Python’s run.py to bootstrap or manage multiple components.