How dun-sin/whisper works
Main Components
• Client (Frontend):
– Located in the “client” directory.
– Built with React and styled with TailwindCSS.
– Contains various components (e.g., Chat, NavBar, EmojiPicker) and state management through Context and custom hooks.
– Uses libraries for notifications, axios for HTTP requests, and socket integration (e.g., chatSocket.js, socketConnection.js).
• Server (Backend):
– Found in the “server” directory.
– NodeJS application that includes controllers (userController.js, codeController.js), models (ChatModel.js, MessageModel.js, UserModel.js), and a collection of Socket.IO event handlers (e.g., sendMessage.js, join.js, typing.js).
– Handles business logic, REST endpoints, and real-time socket events.
• Database:
– Though not a separate folder, the README mentions using MongoDB.
– The server’s .env_sample hints at a localhost MongoDB URL (or a Docker port when using Docker).
• Docker:
– A Docker Compose file is present.
– The server supports Docker deployment (e.g., “npm run dev:docker”) with the appropriate MongoDB port defined (27018 for Docker usage).
Relationships and Data Flow
• The client (browser) interacts with the server via:
– Standard HTTP/REST API for regular CRUD operations.
– Socket.IO for real-time events such as joining a chat, sending and receiving messages, typing indicators, etc.
• The server processes these requests and commands:
– Uses controllers to handle API endpoints.
– Delegates real-time logic to socket modules, managing events like sendMessage, join, editMessage, etc.
• Data is stored and retrieved from the MongoDB, accessed through the models.
• Docker is used to orchestrate deployment, where the server container and MongoDB instance (if containerized) interact over specified network ports.
Architectural Patterns and Technologies
• Separation of Concerns:
– The clear split between client and server directories supports the standard full-stack separation.
• Real-Time Communication:
– Integration of Socket.IO in the server (divided into modular socket event files) and corresponding socket helper files in the client.
• State Management (in the client):
– Usage of React Contexts (e.g., AuthContext, ChatContext) to manage global states.
• Extensibility and Modularity:
– Multiple folders and files (e.g., context, hooks, controllers, models, sockets) allow adding or modifying parts of the application without major rework.
• Use of Docker for Deployment:
– Docker Compose orchestrates the containerized parts of the application, ensuring portability.