# shivam6714/nexus architecture

> Architecture diagram of the GitHub repository shivam6714/nexus, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shivam6714/nexus
- Repository: https://github.com/shivam6714/nexus

## Overview

#### 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: [`client/src/pages/Chat.jsx`](https://github.com/shivam6714/nexus/blob/main/client/src/pages/Chat.jsx) (Chat & social screens), [`server/middleware/authMiddleware.js`](https://github.com/shivam6714/nexus/blob/main/server/middleware/authMiddleware.js) (Auth & upload middleware), [`server/socket/socketHandler.js`](https://github.com/shivam6714/nexus/blob/main/server/socket/socketHandler.js) (Socket handler), [`client/src/socket/socket.js`](https://github.com/shivam6714/nexus/blob/main/client/src/socket/socket.js) (Socket client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React Client"]
  node_client_entry["Vite entry<br/>client bootstrap<br/>[main.jsx]"]
  node_client_app["App routes<br/>application shell<br/>[App.jsx]"]
  node_route_guards["Route guards<br/>session access control<br/>[ProtectedRoute.jsx]"]
  node_client_screens["Chat &amp; social screens<br/>page views<br/>[Chat.jsx]"]
  node_workspace["Chat workspace<br/>multi-pane layout<br/>[MainLayout.jsx]"]
  node_conversation_ui["Conversation UI<br/>messages and composer<br/>[ChatArea.jsx]"]
  node_client_services["REST services<br/>API client boundary<br/>[api.js]"]
  node_client_socket["Socket client<br/>realtime transport<br/>[socket.js]"]
end

subgraph group_api["Express API"]
  node_server_boot["Server bootstrap<br/>Node entrypoint<br/>[server.js]"]
  node_express_app["Express app<br/>HTTP application<br/>[app.js]"]
  node_routes["API routes<br/>HTTP endpoint modules<br/>[authRoutes.js]"]
  node_auth_upload["Auth &amp; upload middleware<br/>request boundary<br/>[authMiddleware.js]"]
  node_controllers["Controllers<br/>request orchestration<br/>[authController.js]"]
  node_domain_services["Domain services<br/>business operations<br/>[messageService.js]"]
end

subgraph group_realtime["Realtime"]
  node_socket_handler["Socket handler<br/>event gateway<br/>[socketHandler.js]"]
  node_presence_events["Presence &amp; event domains<br/>online state and broadcasts<br/>[onlineUsers.js]"]
end

subgraph group_data["Data &amp; Media"]
  node_mongodb[("MongoDB models<br/>collaboration persistence<br/>[User.js]")]
  node_uploads["Uploaded media<br/>file storage"]
end

node_client_entry -->|"mounts"| node_client_app
node_client_app -->|"applies"| node_route_guards
node_route_guards -->|"permits"| node_client_screens
node_client_screens -->|"renders chat"| node_workspace
node_workspace -->|"composes"| node_conversation_ui
node_client_screens -->|"uses REST"| node_client_services
node_conversation_ui -->|"subscribes and sends"| node_client_socket
node_client_services -->|"HTTP requests"| node_express_app
node_client_socket -->|"persistent events"| node_socket_handler
node_server_boot -->|"starts"| node_express_app
node_express_app -->|"dispatches"| node_routes
node_routes -->|"protects/uploads"| node_auth_upload
node_auth_upload -->|"authorizes"| node_controllers
node_controllers -->|"delegates"| node_domain_services
node_domain_services -->|"reads and writes"| node_mongodb
node_auth_upload -->|"stores media"| node_uploads
node_socket_handler -->|"maintains and emits"| node_presence_events
node_socket_handler -->|"persists events"| node_mongodb
node_presence_events -->|"broadcasts updates"| node_client_socket

click node_client_entry "https://github.com/shivam6714/nexus/blob/main/client/src/main.jsx"
click node_client_app "https://github.com/shivam6714/nexus/blob/main/client/src/App.jsx"
click node_route_guards "https://github.com/shivam6714/nexus/blob/main/client/src/components/common/ProtectedRoute.jsx"
click node_client_screens "https://github.com/shivam6714/nexus/blob/main/client/src/pages/Chat.jsx"
click node_workspace "https://github.com/shivam6714/nexus/blob/main/client/src/components/layout/MainLayout.jsx"
click node_conversation_ui "https://github.com/shivam6714/nexus/blob/main/client/src/components/layout/ChatArea.jsx"
click node_client_services "https://github.com/shivam6714/nexus/blob/main/client/src/services/api.js"
click node_client_socket "https://github.com/shivam6714/nexus/blob/main/client/src/socket/socket.js"
click node_server_boot "https://github.com/shivam6714/nexus/blob/main/server/server.js"
click node_express_app "https://github.com/shivam6714/nexus/blob/main/server/app.js"
click node_routes "https://github.com/shivam6714/nexus/blob/main/server/routes/authRoutes.js"
click node_auth_upload "https://github.com/shivam6714/nexus/blob/main/server/middleware/authMiddleware.js"
click node_controllers "https://github.com/shivam6714/nexus/blob/main/server/controllers/authController.js"
click node_domain_services "https://github.com/shivam6714/nexus/blob/main/server/services/messageService.js"
click node_socket_handler "https://github.com/shivam6714/nexus/blob/main/server/socket/socketHandler.js"
click node_presence_events "https://github.com/shivam6714/nexus/blob/main/server/socket/onlineUsers.js"
click node_mongodb "https://github.com/shivam6714/nexus/blob/main/server/models/User.js"
click node_uploads "https://github.com/shivam6714/nexus/tree/main/server/uploads/avatars"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_client_entry,node_client_app,node_route_guards,node_client_screens,node_workspace,node_conversation_ui,node_client_services,node_client_socket toneBlue
class node_server_boot,node_express_app,node_routes,node_auth_upload,node_controllers,node_domain_services toneAmber
class node_socket_handler,node_presence_events toneMint
class node_mongodb,node_uploads toneRose
```

## Components

### React Client

- [Vite entry](https://github.com/shivam6714/nexus/blob/main/client/src/main.jsx): client bootstrap · `client/src/main.jsx`
- [App routes](https://github.com/shivam6714/nexus/blob/main/client/src/App.jsx): application shell · `client/src/App.jsx`
- [Route guards](https://github.com/shivam6714/nexus/blob/main/client/src/components/common/ProtectedRoute.jsx): session access control · Separates public authentication from authenticated areas. · `client/src/components/common/ProtectedRoute.jsx`
- [Chat & social screens](https://github.com/shivam6714/nexus/blob/main/client/src/pages/Chat.jsx): page views · `client/src/pages/Chat.jsx`
- [Chat workspace](https://github.com/shivam6714/nexus/blob/main/client/src/components/layout/MainLayout.jsx): multi-pane layout · `client/src/components/layout/MainLayout.jsx`
- [Conversation UI](https://github.com/shivam6714/nexus/blob/main/client/src/components/layout/ChatArea.jsx): messages and composer · `client/src/components/layout/ChatArea.jsx`
- [REST services](https://github.com/shivam6714/nexus/blob/main/client/src/services/api.js): API client boundary · Auth, messages, servers, and conversations use request/response calls. · `client/src/services/api.js`
- [Socket client](https://github.com/shivam6714/nexus/blob/main/client/src/socket/socket.js): realtime transport · `client/src/socket/socket.js`

### Express API

- [Server bootstrap](https://github.com/shivam6714/nexus/blob/main/server/server.js): Node entrypoint · `server/server.js`
- [Express app](https://github.com/shivam6714/nexus/blob/main/server/app.js): HTTP application · `server/app.js`
- [API routes](https://github.com/shivam6714/nexus/blob/main/server/routes/authRoutes.js): HTTP endpoint modules · Auth, server, message, and conversation endpoints. · `server/routes/authRoutes.js`
- [Auth & upload middleware](https://github.com/shivam6714/nexus/blob/main/server/middleware/authMiddleware.js): request boundary · `server/middleware/authMiddleware.js`
- [Controllers](https://github.com/shivam6714/nexus/blob/main/server/controllers/authController.js): request orchestration · Coordinates auth, server, message, and friend operations. · `server/controllers/authController.js`
- [Domain services](https://github.com/shivam6714/nexus/blob/main/server/services/messageService.js): business operations · `server/services/messageService.js`

### Realtime

- [Socket handler](https://github.com/shivam6714/nexus/blob/main/server/socket/socketHandler.js): event gateway · Authenticates sockets and handles communication events. · `server/socket/socketHandler.js`
- [Presence & event domains](https://github.com/shivam6714/nexus/blob/main/server/socket/onlineUsers.js): online state and broadcasts · Tracks online users and emits server/friend events. · `server/socket/onlineUsers.js`

### Data & Media

- [MongoDB models](https://github.com/shivam6714/nexus/blob/main/server/models/User.js): collaboration persistence · Users, servers, channels, messages, conversations, and friend requests. · `server/models/User.js`
- [Uploaded media](https://github.com/shivam6714/nexus/tree/main/server/uploads/avatars): file storage · Avatars, message media, and server icons. · `server/uploads/avatars`

## Connections

- 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
