How hamzask018/chatapp_scalable works
This repository implements a chat application with OTP-based login, user profiles, one-to-one chats, text/image messages, and email delivery of login codes. The main workflow starts with a user requesting an OTP, verifying it, then using the chat interface to create chats and exchange messages. The backend separates user, chat, and mail services; MongoDB-backed models hold users, chats, and messages, while Redis stores OTPs and RabbitMQ carries email jobs. Frontend-to-chat API wiring is only partly visible in the supplied excerpts.
Main entry points: routes/user.ts User API · controllers/user.ts User workflows · controllers/chat.ts Chat workflows · routes/chat.ts Chat API
Components 20
Web client
- Login page
frontend/app/login/page.tsx - OTP verification
frontend/components/verifyOtp.tsx - Chat page
frontend/app/chat/page.tsx - Chat sidebar
frontend/components/ChatSidebar.tsx - App context
frontend/context/AppContext.tsx
Identity and email
- User API
backend/user/src/routes/user.ts - User workflows
backend/user/src/controllers/user.ts - JWT authentication
backend/user/src/middleware/isAuth.ts - Email queue publisher
backend/user/src/config/rabbitmq.ts - OTP mail consumer
backend/mail/src/consumer.ts
Chat and messages
- Chat API
backend/chat/src/routes/chat.ts - Chat workflows
backend/chat/src/controllers/chat.ts - Chat authentication
backend/chat/src/middlewares/isAuth.ts - Image upload
backend/chat/src/middlewares/multer.ts
Data and infrastructure
- User records
backend/user/src/model/user.ts - OTP and rate limits
backend/user/src/config/redis.ts - Chat records
backend/chat/src/models/chat.ts - Message records
backend/chat/src/models/messages.ts - Image storage
backend/chat/src/config/cloudinary.ts
Other components
- User
Connections 22
- User → Login page: requests login
- User → OTP verification: enters code
- User → Chat page: uses chat
- OTP verification → User API: posts OTP
frontend/components/verifyOtp.tsx - OTP verification → App context: updates auth state
frontend/components/verifyOtp.tsx - Chat page → Chat sidebar: renders
- Login page → User API: requests OTP
- User API → JWT authentication: guards profile routes
backend/user/src/routes/user.ts - User API → User workflows: dispatches routes
backend/user/src/routes/user.ts - User workflows → OTP and rate limits: stores and checks codes
backend/user/src/controllers/user.ts - User workflows → Email queue publisher: publishes email job
backend/user/src/controllers/user.ts - User workflows → User records: reads and writes users
backend/user/src/controllers/user.ts - Email queue publisher → OTP mail consumer: queues OTP email
- OTP mail consumer → User: sends email
backend/mail/src/consumer.ts - Chat API → Chat authentication: authenticates requests
backend/chat/src/routes/chat.ts - Chat API → Image upload: processes image upload
backend/chat/src/routes/chat.ts - Chat API → Chat workflows: dispatches routes
backend/chat/src/routes/chat.ts - Chat workflows → Chat records: reads and writes chats
backend/chat/src/controllers/chat.ts - Chat workflows → Message records: reads and writes messages
backend/chat/src/controllers/chat.ts - Image upload → Image storage: uploads images
backend/chat/src/middlewares/multer.ts - Chat workflows → User API: fetches participant profile
backend/chat/src/controllers/chat.ts - Chat page → Chat API: uses chat endpoints