How ashutosh0203/chatappbackend works
This repository implements a chat application as three services: user/account, real-time chat, and OTP email delivery. The main user workflow requests an email OTP, verifies it to obtain an account token, then uses authenticated chat endpoints to create conversations and send or retrieve messages; Socket.IO distributes live events. Chat can also look up user details through the user service. Source excerpts support the route, controller, queue, and socket relationships; database connection implementations and several configuration modules were not excerpted, so their internal wiring is not inferred.
Main entry points: controllers/user.ts Account workflows · controllers/chat.ts Chat workflows · routes/user.ts Account routes · routes/chat.ts Chat routes
Components 24
Accounts and identity
- Account routes
user/src/routes/user.ts - Token authentication
user/src/middleware/isAuth.ts - Account workflows
user/src/controllers/user.ts - User records
user/src/model/User.ts - Token generation
user/src/config/generateToken.ts - User lookup API
user/src/controllers/user.ts
Chat and realtime
- Chat routes
chat/src/routes/chat.ts - Chat token auth
chat/src/middlewares/isAuth.ts - Chat workflows
chat/src/controllers/chat.ts - Conversation records
chat/src/models/Chat.ts - Message records
chat/src/models/Messages.ts - Image upload
chat/src/middlewares/mutler.ts - Realtime socket server
chat/src/config/socket.ts
OTP delivery
- Queue publisher
user/src/config/rabbitmq.ts - OTP mail consumer
mail/src/consumer.ts - Mail service entry
mail/src/index.ts
State and integrations
- User DB connection
user/src/config/db.ts - OTP and rate limits
- RabbitMQ
- SMTP email
- Image storage
chat/src/config/cloudinary.ts - Chat DB connection
chat/src/config/db.ts - MongoDB
Other components
- Chat client
Connections 26
- Chat client → Account routes: requests accounts
- Account routes → Token authentication: guards routes
user/src/routes/user.ts - Account routes → Account workflows: dispatches
user/src/routes/user.ts - Account workflows → User records: reads and writes
user/src/controllers/user.ts - Account workflows → Token generation: generates tokens
user/src/controllers/user.ts - Account workflows → OTP and rate limits: stores OTPs
user/src/controllers/user.ts - Account workflows → Queue publisher: publishes OTP
user/src/controllers/user.ts - Token authentication → User records: uses user type
user/src/middleware/isAuth.ts - Account routes → Chat client: returns responses
- User DB connection → MongoDB: connects
- Chat routes → Chat token auth: guards routes
chat/src/routes/chat.ts - Chat routes → Chat workflows: dispatches
chat/src/routes/chat.ts - Chat routes → Image upload: processes images
chat/src/routes/chat.ts - Chat workflows → Conversation records: reads and writes
chat/src/controllers/chat.ts - Chat workflows → Message records: reads and writes
chat/src/controllers/chat.ts - Chat workflows → Realtime socket server: emits events
chat/src/controllers/chat.ts - Chat workflows → User lookup API: fetches profiles
chat/src/controllers/chat.ts - Image upload → Image storage: uploads images
chat/src/middlewares/mutler.ts - Chat DB connection → MongoDB: connects
- Chat client → Chat routes: requests chats
- Chat client → Realtime socket server: opens socket
- Queue publisher → RabbitMQ: publishes messages
user/src/config/rabbitmq.ts - Mail service entry → OTP mail consumer: starts consumer
mail/src/index.ts - OTP mail consumer → RabbitMQ: consumes messages
mail/src/consumer.ts - OTP mail consumer → SMTP email: sends email
mail/src/consumer.ts - User lookup API → Chat client: returns profile