How shivam6714/nexus works
Purpose and Entry Points
This is a full-stack Discord-like communication application: authenticated users join servers, browse channels, exchange server/DM messages, manage friends, and participate in voice-oriented room UI. The React/Vite client starts at client/src/main.jsx and composes routes/UI through client/src/App.jsx. The Node.js backend boots from server/server.js, with Express application setup in server/app.js.
Client Application Shell and Access Control
The client separates public authentication views from authenticated chat and social areas. Route guards in client/src/components/common/ProtectedRoute.jsx and client/src/components/common/PublicRoute.jsx enforce session-aware navigation. Primary screens are client/src/pages/Chat.jsx, client/src/pages/FriendsPage.jsx, client/src/pages/Login.jsx, and client/src/pages/Register.jsx.
Chat Workspace Composition
The chat workspace is assembled as a multi-pane layout: server selection, channel/DM navigation, message area, members list, and user controls. Its central composition is client/src/components/layout/MainLayout.jsx; conversation rendering and sending are handled by client/src/components/layout/ChatArea.jsx, client/src/components/message/MessageList.jsx, and client/src/components/layout/MessageInput.jsx. Server/channel navigation is represented by client/src/components/sidebar/ServerSidebar.jsx and client/src/components/sidebar/ChannelSidebar.jsx.
Client Data and Realtime Boundary
Frontend service modules isolate REST calls from components, including client/src/services/api.js, client/src/services/messageService.js, client/src/services/serverService.js, and client/src/services/conversationService.js. Authentication-specific requests flow through client/src/services/authService.js. Realtime socket setup is centralized in client/src/socket/socket.js, separating persistent event transport from request/response API traffic.
Backend HTTP Pipeline
Express receives requests through route modules such as server/routes/authRoutes.js, server/routes/serverRoutes.js, server/routes/messageRoutes.js, and server/routes/conversationRoutes.js. Routes delegate to controllers, including server/controllers/authController.js, server/controllers/serverController.js, server/controllers/messageController.js, and server/controllers/friendController.js. Authentication is an explicit middleware boundary in server/middleware/authMiddleware.js; upload endpoints use server/middleware/upload.js.
Domain Persistence and Services
The backend models the core collaboration graph with MongoDB-oriented data models: users (server/models/User.js), servers (server/models/Server.js), channels (server/models/Channel.js), messages (server/models/Message.js), direct-message conversations (server/models/Conversation.js), and friendship requests (server/models/FriendRequest.js). Database connectivity is established in server/config/db.js. Reusable business operations are factored into services, notably server/services/authService.js, server/services/messageService.js, and server/services/friendService.js.
Realtime Events, Presence, and Media
Socket handling is server-owned in server/socket/socketHandler.js and authenticated through server/socket/socketAuth.js. It maintains online-user state via server/socket/onlineUsers.js and emits server/friend event domains from server/socket/serverEvents.js and server/socket/friendEvents.js. Uploaded avatars, message media, and server icons are persisted beneath server/uploads/avatars, server/uploads/messages, and server/uploads/server-icons; client-side URL normalization is handled by client/src/utils/imageUrl.js.
Main entry points: Chat.jsx Chat & social screens · authMiddleware.js Auth & upload middleware · socketHandler.js Socket handler · socket.js Socket client
Components 18
React Client
- Vite entry
client/src/main.jsx - App routes
client/src/App.jsx - Route guards · Separates public authentication from authenticated areas.
client/src/components/common/ProtectedRoute.jsx - Chat & social screens
client/src/pages/Chat.jsx - Chat workspace
client/src/components/layout/MainLayout.jsx - Conversation UI
client/src/components/layout/ChatArea.jsx - REST services · Auth, messages, servers, and conversations use request/response calls.
client/src/services/api.js - Socket client
client/src/socket/socket.js
Express API
- Server bootstrap
server/server.js - Express app
server/app.js - API routes · Auth, server, message, and conversation endpoints.
server/routes/authRoutes.js - Auth & upload middleware
server/middleware/authMiddleware.js - Controllers · Coordinates auth, server, message, and friend operations.
server/controllers/authController.js - Domain services
server/services/messageService.js
Realtime
- Socket handler · Authenticates sockets and handles communication events.
server/socket/socketHandler.js - Presence & event domains · Tracks online users and emits server/friend events.
server/socket/onlineUsers.js
Data & Media
- MongoDB models · Users, servers, channels, messages, conversations, and friend requests.
server/models/User.js - Uploaded media · Avatars, message media, and server icons.
server/uploads/avatars
Connections 19
- Vite entry → App routes: mounts
- App routes → Route guards: applies
- Route guards → Chat & social screens: permits
- Chat & social screens → Chat workspace: renders chat
- Chat workspace → Conversation UI: composes
- Chat & social screens → REST services: uses REST
- Conversation UI → Socket client: subscribes and sends
- REST services → Express app: HTTP requests
- Socket client → Socket handler: persistent events
- Server bootstrap → Express app: starts
- Express app → API routes: dispatches
- API routes → Auth & upload middleware: protects/uploads
- Auth & upload middleware → Controllers: authorizes
- Controllers → Domain services: delegates
- Domain services → MongoDB models: reads and writes
- Auth & upload middleware → Uploaded media: stores media
- Socket handler → Presence & event domains: maintains and emits
- Socket handler → MongoDB models: persists events
- Presence & event domains → Socket client: broadcasts updates