How avtarsingh97/chitchatapp works
Project type and purpose
• This is a full-stack, real-time messaging web application (CHITCHAT) built on the MERN stack.
• It supports user registration, login, conversation management and live chat via WebSocket (Socket.io).
• Backend runs on Node/Express connected to MongoDB Atlas; frontend is a React single-page app bundled with Vite and styled with Tailwind CSS.
File structure
• Top level:
– backend/ : Express server, API controllers, Mongoose models, routes, Socket.io integration.
– frontend/ : React app, Vite config, Tailwind CSS via index.html, components folder, socket client.
• backend:
– Authentication module (Auth.js handles JWT, bcrypt, cookie parsing).
– Controllers for users, conversations, messages.
– Models for User, Conversation, Message.
– Routes mirror controllers.
– connection.js sets up MongoDB via Mongoose.
– index.js wires Express, HTTP server, Socket.io, middleware (CORS, cookie-parser, dotenv).
• frontend:
– src/socket.js establishes WebSocket connection to backend.
– Components folder reflects UI routes: Login, Register, Dashboard, Chats, Conversation, Loader, Avatar selector, Home, NotFound.
– App.jsx holds Router and global state.
Key insights from README
• Tech stack list confirms MERN + Socket.io + JWT + Tailwind CSS.
• Features call out protected routes, real-time events, REST APIs for CRUD on messages and conversations.
Main components and their interactions
a. Client (Browser/React SPA)
– Renders UI, handles user input, calls REST endpoints (Axios) for login, registration, conversation history.
– Maintains WebSocket connection (socket.io-client) to receive/send real-time messages.
b. API Server (Express)
– Exposes REST endpoints under /api/users, /api/conversations, /api/messages
– Auth middleware verifies JWT tokens on protected routes.
– On HTTP requests, uses Mongoose to persist/fetch data in MongoDB Atlas.
c. WebSocket Server (Socket.io)
– Runs on the same Node/Express HTTP server instance.
– Handles real-time events: join conversation rooms, broadcast new messages, update presence.
d. Database (MongoDB Atlas)
– Stores User, Conversation, Message collections.
– Connection managed by Mongoose.
e. External Hosting Services (Vercel, Render)
– Optionally show as deployment targets.
f. Optional: CDN or asset hosting for frontend static files.
Architectural patterns and design principles
• Separation of concerns: frontend vs backend vs database.
• Layered backend: routing → controllers → models → database.
• Stateless REST API complemented by stateful WebSocket channels.
• JWT-based authentication and authorization.
• Use of environment variables for configuration (dotenv).
• Responsive, component-based UI in React.