How satwik152/chatza works
Project type and purpose
• This is a full-stack real-time chat application (“Full Stack Realtime Chat App”) built with the MERN stack (MongoDB, Express/Node.js, React), Socket.io for real-time messaging, Zustand for client state management, TailwindCSS + DaisyUI for styling, JWT for auth, and Cloudinary for image handling.
File structure
• Top-level directories:
• backend/ – Node.js/Express application, REST controllers, WebSocket logic (src/lib/socket.js), models (User, Message), middleware (auth), routes, seed data, configuration (db, cloudinary).
• frontend/ – React application with Vite, TailwindCSS, DaisyUI; pages (Home, Login, SignUp, Profile, Settings), reusable components (ChatContainer, Sidebar, Navbar, MessageInput, skeleton loaders), shared libs (axios wrapper, utils), global stores (Zustand for auth, chat, theme).
• Build and deployment scripts in package.json; .env variables for MongoDB URI, port, JWT secret, Cloudinary credentials.
Key insights from README
• Real-time events handled over WebSockets (Socket.io).
• REST API endpoints for auth (signup/login/JWT) and message history.
• Online user status maintained via sockets.
• Client-side global state via Zustand.
• Error handling on both server and client.
• Deployment targets unspecified, but build/start commands provided.
Main components and their interactions
a. Frontend (Browser/React App)
• UI pages/components → React/Vite dev server or built static assets served by hosting.
• Uses HTTP(S) REST calls (axios) to backend for signup, login, fetching message history, profile, settings.
• Opens a Socket.io connection to backend for real-time messaging, user status updates.
• State management by Zustand stores (auth, chat, theme).
b. Backend (Express/Node.js server)
• HTTP server exposing REST routes (/auth, /messages).
• Socket.io server bound to same HTTP server (or separate port) to handle handshake, authentication (JWT in socket handshake), join rooms, broadcast messages, track online users.
• Controllers coordinate DB operations via Mongoose models (User, Message).
• Middleware enforces JWT on protected REST and socket events.
• Utilities: cloudinary.js for image uploads (e.g., profile pics), db.js for MongoDB connection, utils.js for shared helpers.
c. Database
• MongoDB (cloud or local) with two collections: users, messages.
d. External services
• Cloudinary for storing profile images or any media attachments.
Architectural patterns and design principles
• Separation of concerns: frontend vs. backend layers.
• MVC‐style pattern on server: controllers, models, routes.
• Pub/Sub real-time messaging through Socket.io.
• Stateless REST API with JWT authentication.
• Client state management with a unidirectional data flow (Zustand stores).