How aditya-620/chatterbox works
ChatterBox is a full-stack real-time chat application:
• Frontend: React (Vite) SPA using Axios for REST and SockJS + STOMP for WebSocket messaging.
• Backend: Spring Boot application exposing REST APIs for room & history, and WebSocket/STOMP endpoints for real-time chat.
• Persistence: MongoDB storing Room and Message documents.
• Cross-cutting: AES-256 encryption performed in the backend before persisting messages.
Backend (ChatterBox-backend/src/main/java/...)
Key components visible directly from structure:
• config/WebSocketConfig.java → STOMP endpoint setup, topic/app prefixes, SockJS config (likely), CORS config (via FRONTEND_URL in properties)
• controllers/ChatController.java → WebSocket message handling (e.g., @MessageMapping)
• controllers/RoomController.java → REST endpoints: create room, join room, fetch messages with pagination
• entities/Message.java, entities/Room.java → MongoDB domain models
• repositories/RoomRepository.java → MongoDB data access (likely MongoRepository)
• utils/EncryptionUtil.java → AES encryption/decryption logic (hardcoded key per README)
• application.properties → runtime config, env var bindings (MONGODB_URI, etc.)
• Dockerfile → backend containerization boundary
Frontend (ChatterBox-frontend/src)
Key components:
• components/JoinCreateChat.jsx → UX entry flow (create/join room)
• components/ChatPage.jsx → main chat UI; likely initializes WebSocket and renders message list
• context/ChatContext.jsx → global chat state (current room, messages, user, theme)
• services/RoomService.js → REST calls to backend
• config/AxiosHelper.js → axios base URL set via VITE_API_URL
• config/Routes.jsx → page routing boundaries
ChatterBox Backend (Spring Boot)
• REST API: /api/v1/...
• WebSocket endpoint: /chat
MongoDB database
Configuration links
• Frontend uses VITE_API_URL → points to backend base URL
• Backend uses:
• MONGODB_URI, MONGODB_DATABASE
• FRONTEND_URL for CORS / WebSocket allowed origins
Deployment boundary
• Backend can be run via Maven or Docker (ChatterBox-backend/Dockerfile)
This is where you “separate into as many components as possible” based on the repo.
RoomController → RoomRepository → MongoDB (query)
3. Backend returns messages (likely decrypted before return; if not, explicitly note “frontend receives encrypted” vs “backend decrypts” depending on code)
Backend ChatController
• encrypts via EncryptionUtil
• persists to MongoDB (via repo/path in code)
• publishes encrypted/decrypted payload to /topic/room/{roomId}
Important architectural patterns to highlight (based on repo)
• SPA + API separation: React frontend decoupled from backend via env-based base URL.
• Dual-channel communication:
• REST for “stateful resources” (rooms, history)
• WebSocket/STOMP for “events” (new messages)
• Pub/Sub topic model: /topic/room/{roomId} is the broadcast channel.
• Repository pattern: Spring Data repository encapsulates Mongo persistence.
• Security/encryption boundary: encryption occurs server-side before storage (explicit trust boundary).
• Blue rectangles: runtime containers (React SPA, Spring Boot, MongoDB)
• REST: /api/v1/rooms, /api/v1/rooms/{roomId}, /api/v1/rooms/{roomId}/messages
• WS:
• /chat
• Send: /app/sendMessage/{roomId}
• Subscribe: /topic/room/{roomId}
Callouts for configuration:
• VITE_API_URL (frontend)
• MONGODB_URI, MONGODB_DATABASE, FRONTEND_URL (backend)
A security note bubble:
• “AES-256 key hardcoded in EncryptionUtil → replace with env/secret manager in production.”
Top: Browser/User
2. Left: React SPA (JoinCreateChat, ChatPage, ChatContext, RoomService/Axios, STOMP client)
3. Right: Spring Boot (RoomController, ChatController, WebSocketConfig, EncryptionUtil, RoomRepository, Entities)
Bottom: MongoDB
This will be the most accurate representation of what the repository actually contains, while staying detailed and readable.