A simple chat application with user signup/login, user discovery, chat creation, and message exchange backed by MongoDB. The frontend is a React app (Create React App) using Redux Toolkit, and the backend is an Express API with JWT authentication.
- Frontend provides authentication pages, a protected home view, user search, and chat UI scaffolding.
- Backend exposes REST endpoints for auth, users, chats, and messages, secured with JWT.
- Data is stored in MongoDB using Mongoose models for
users,chats, andmessages.
- Frontend: React, Redux Toolkit, React Router, Axios, React Hot Toast
- Backend: Node.js, Express, Mongoose, JSON Web Tokens, bcryptjs
- Database: MongoDB (Atlas or local)
- Dev Tools: CRA (
react-scripts), Nodemon
- Node.js LTS (v18 or v20 recommended)
- A MongoDB connection string
- Create a
.envfile or edit server/config.env with:
PORT_NUMBER=5000
CONN_STRING=<your-mongodb-connection-string>
JWT_SECRET=<strong-random-secret>
- Install and start the API:
cd "c:\Users\risha\Desktop\SuperChat\server"
npm install
npm run dev
# or
npm startThe server reads CORS settings from server/app.js. When using the CRA proxy (recommended), CORS is handled by the dev server. If you call the API directly from the browser (without proxy), ensure origin includes your frontend dev URL (e.g., http://localhost:3000).
- Proxy or direct API base URL:
- Default: CRA dev server proxies requests to
http://localhost:5000viaproxyin client/package.json. - Alternative: set client/src/apiCalls/index.js base using
.env.local:
- Default: CRA dev server proxies requests to
cd "c:\Users\risha\Desktop\SuperChat\client"
echo REACT_APP_API_BASE_URL=http://localhost:5000 > .env.local- Install and start the client:
cd "c:\Users\risha\Desktop\SuperChat\client"
npm install
npm startCRA serves at http://localhost:3000 by default.
Base path: /api
- POST
/api/auth/signup– create user- Body:
{ firstname, lastname, email, password } - Accepts
firstName/lastNamealiases.
- Body:
- POST
/api/auth/login– login and receive JWT- Body:
{ email, password } - Response:
{ success, message, token }
- Body:
- GET
/api/user/get-logged-user– returns logged-in user - GET
/api/user/get-all-users– returns all users except logged-in
- POST
/api/chat/create-new-chat- Body:
{ members: [userId1, userId2] }
- Body:
- GET
/api/chat/get-all-chats– chats wherereq.userIdis a member
- POST
/api/message/new-message- Body:
{ chatId, sender, text } - Also updates
chats.LastMessage.
- Body:
- GET
/api/message/get-all-messages/:chatId– list messages by chat - POST
/api/message/get-all-messages– same as above with{ chatId }in body
Use Authorization: Bearer <token> in requests. The middleware also tolerates a bare token, but Bearer is recommended.
- Signup via
/api/auth/signup. - Login via
/api/auth/login; storetokeninlocalStorage. - Client attaches the token automatically via Axios interceptor in client/src/apiCalls/index.js.
- Protected routes use client/src/components/protectedRoute.js to:
- Fetch the logged user (
/api/user/get-logged-user). - Fetch all users (
/api/user/get-all-users).
- Fetch the logged user (
- On token missing/invalid, user is redirected to
/login.
- Stateless API: keep JWT auth stateless; avoid server-side sessions.
- DB Indexes: add indexes on
messages.chatId,messages.createdAt, andchats.membersfor faster lookups. - Pagination: paginate
/message/get-all-messageswithlimit/cursorfor large chats. - Rate Limiting & Validation: throttle auth and messaging endpoints; validate payloads.
- Real-time Transport: introduce WebSockets (e.g., Socket.IO) for live messaging, typing indicators, and read receipts, while retaining REST as fallback.
- Horizontal Scale: run multiple API instances behind a load balancer; use a shared store (e.g., Redis) for WebSocket coordination.
- Observability: centralize logs/traces/metrics; add health checks and readiness probes.
- Secrets Management: load
CONN_STRING/JWT_SECRETfrom a secret manager, not committed files.
- Using the CRA proxy (default) avoids CORS complexity during local dev.
- If you set
REACT_APP_API_BASE_URL, ensure backend CORS in server/app.js includes your frontend origin (http://localhost:3000).
cd "c:\Users\risha\Desktop\SuperChat\client"
npm run buildBuild output goes to client/build.
This project was bootstrapped with Create React App. See CRA docs for generic topics like testing, PWA, and advanced configuration.