How yashasxworkz/chatty 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, React, Node.js), Socket.io for bidirectional messaging, TailwindCSS + Daisy UI for styling, and Zustand for client-side state. It provides user authentication (JWT), real-time messaging, online/offline status, image uploads (via Cloudinary), and global state management.
File structure
• Top‐level split:
• /backend – Express API + Socket.io server
• /frontend – React single-page application (Vite, TailwindCSS)
• Backend follows an MVC‐style layout:
• src/controllers – request handlers (auth, message)
• src/models – Mongoose schemas (User, Message)
• src/routes – REST endpoints (auth.route.js, message.route.js)
• src/middleware – JWT auth guard
• src/lib – reusable libs (db connection, Socket.io init, Cloudinary upload, utils)
• src/seeds – sample data loader
• Frontend is component-driven:
• src/pages – route targets (Home, Login, SignUp, Profile, Settings)
• src/components – UI parts (Sidebar, ChatContainer, MessageInput, skeletons)
• src/store – Zustand hooks for auth, chat, theme, emotion state
• src/lib – axios instance, utils
• Config/build files: package.json, vite.config.js, tailwind.config.js
a. Client (Browser/SPA)
b. Web Server (Express + Socket.io)
c. Authentication (JWT middleware)
d. Database (MongoDB Atlas)
e. Cloudinary (image storage service)
f. Real-time channel (Socket.io engine)
Relationships & data flows
• User → HTTP(S) REST calls → /api/auth & /api/messages on Express
• Express ↔ MongoDB via Mongoose (db.js lib)
• Express ↔ Cloudinary (cloudinary.js lib) for media uploads
• Client ↔ Socket.io:
• On login, SPA obtains JWT, stores in client store
• Socket client attaches JWT in handshake → server validates via auth.middleware
• Message send: client emits “send_message” → server broadcasts “receive_message” to rooms/users
• Presence: server emits “user_online” / “user_offline” events
• Frontend state: Zustand stores auth token, chat history, user list, theme, emotion states
Architectural patterns & design principles
• Backend: MVC separation, single Node.js process hosting HTTP and WebSocket on same port
• Auth: stateless JWT, middleware enforcement on both REST endpoints and Socket handshake
• Frontend: unidirectional data flow, global state via Zustand, component reusability
• Responsiveness: skeleton loaders for async data
• Scalability: cloud storage for media, external DB service