How nasimreja077/barta-lap-chatapp works
Project Type and Purpose
• This is a full-stack, real-time chat application (“Barta Lap”) composed of two primary parts:
• A backend service (Node.js, Express, MongoDB, Socket.IO, Cloudinary)
• A frontend Single-Page App (React + Vite, Tailwind CSS, Zustand, Socket.IO-client)
• Purpose: Enable users to sign up, authenticate, send/receive text messages and images in real time, manage profile/settings, with media storage in Cloudinary.
File Structure and Architectural Patterns
• Top-level “backend” and “frontend” directories → clear separation of concerns.
• Backend follows MVC + service layering:
• src/controllers (auth, messages)
• src/models (Mongoose schemas for User, Message)
• src/routes (Express routers)
• src/lib (DB connection, Cloudinary integration, Socket setup, utilities)
• src/middleware (authentication guard)
• Frontend is component-driven React SPA using Vite:
• src/pages (route-level pages: Home, Login, SignUp, Profile, Settings)
• src/components (UI pieces: ChatContainer, Sidebar, Navbar, skeleton loaders)
• src/store (Zustand stores for auth, chat, theme)
• src/lib (Axios wrapper, Socket.IO client, utils)
• Real-time communication: Socket.IO on both client and server.
• Persistence: MongoDB (hosted externally, connection via env).
• Media: Cloudinary used for image uploads.
a. Client Browser / React SPA
b. HTTP API Server (Express)
c. WebSocket Server (Socket.IO) – co-located with HTTP server
d. MongoDB Database
e. Cloudinary Media Service
f. Authentication (JWT via auth.middleware)
g. Static Assets (served by Vite dev server or via production build)
Relationships & Data Flow
• User interacts with React UI → Axios HTTP calls to /auth (signup/login) and REST endpoints (/messages)
• On login/signup, JWT returned → stored in client store → used in Authorization header
• For real-time messaging: client opens Socket.IO connection (with JWT) → server authenticates via middleware → join user room
• Send message: client emits “send_message” → server controller writes to MongoDB → broadcasts via Socket.IO to recipient
• Media uploads: client posts image file to Express endpoint → Express uses Cloudinary SDK → returns URL → included in message payload
• Server seeds initial data via user.seed.js if needed (dev).
Architectural Patterns & Principles
• MVC on backend: controllers handle HTTP, delegate to models
• Layered architecture: controllers → services (lib utils) → persistence
• Component-based frontend: pages, components, central stores
• Separation of concerns: UI, state, network, real-time events
• Single source of truth: Zustand stores for auth/chat/theme
Detailed Component Breakdown (optional inset)
• Frontend:
• Pages (Home, Login, SignUp, Profile, Settings)
• Core Components (Navbar, Sidebar, ChatContainer, MessageInput)
• Store Layer (useAuthStore, useChatStore)
• Network Layer (Axios client, Socket client)
• Backend:
• Routes (/auth, /messages)
• Controllers (auth.controller.js, message.controller.js)
• Middleware (auth.middleware.js)
• Models (user.model.js, message.model.js)
• Lib Utilities (db.js, socket.js, cloudinary.js)