How vanshsingh7/linksphere works
1. Purpose and Runtime Topology
LinkSphere is a Discord-like communication system: authenticated users manage community servers, channels, messages, friends, direct messages, uploads, and WebRTC calls. It is a split React/Vite client and Node/Express backend, with Socket.io sharing the backend HTTP runtime.
• client/src/main.jsx
• server/server.js
• server/app.js
2. Client Entry, Routing, and Application Shell
The browser entry mounts React; the router separates public landing/auth/OAuth pages from the protected application and settings experiences. The main app page is the UI integration point for server/channel/chat workflows, while modal components handle server creation, editing, and joining.
• client/src/main.jsx
• client/src/App.jsx
• client/src/pages/AppPage.jsx
ProtectedRoute gates authenticated client routes, while AuthContext owns client-side session/user state. The client calls the API through its configured backend base URL.
• client/src/components/ProtectedRoute.jsx
• client/src/context/AuthContext.jsx
• client/src/apiConfig.js
3. Backend API Composition and Request Boundary
server/app.js configures the Express application and mounts domain route groups: authentication, users, servers, DMs, friends, and uploads. Route modules delegate to controllers; authentication, validation, and centralized errors form the request boundary before business logic or persistence.
• server/app.js
• server/routes/serverRoutes.js
• server/middleware/authMiddleware.js
Core business domains are separated into controllers for user/auth profile operations, server/channel/message/member/invite operations, friendship, and direct messages.
• server/controllers/serverController.js
• server/controllers/dmController.js
• server/controllers/friendController.js
4. Identity and Access Control
Local signup/login use JWT-based authentication with password hashing; authenticated requests pass through JWT verification. Google OAuth is configured through Passport and returns users to the client OAuth flow. Authorization is material for server ownership/membership and protected user, messaging, and upload actions.
• server/routes/authRoutes.js
• server/config/passport.js
• server/models/User.js
5. Persistent Collaboration Data
MongoDB is the system of record, reached through Mongoose connection setup. User documents represent identity, relationship/presence fields, and OAuth linkage. Server documents contain membership, ownership, invite, and embedded channel structure; channel messages and direct messages are independently persisted. Attachments model uploaded media metadata.
• server/database/db.js
• server/models/Server.js
• server/models/Message.js
• server/models/DirectMessage.js
• server/models/Attachment.js
Primary flow: client fetches server/DM history through REST; mutation controllers validate authorization, write MongoDB records, and real-time delivery supplements persisted history.
6. Real-Time Messaging, Presence, and Calling
Socket.io is initialized with the HTTP server and provides channel-room messaging, online presence, and WebRTC signaling. Socket identity/presence connects users to active sessions; persisted messages remain retrievable via REST. The client voice hook and call modal manage browser media and peer-connection lifecycle, with Socket.io relaying offers, answers, ICE candidates, and call state.
• server/server.js
• client/src/hooks/useVoiceChannel.jsx
• client/src/components/CallModal.jsx
WebRTC media is peer-to-peer; the backend is a signaling/presence coordinator rather than a media relay.
7. External Services and Deployment Boundaries
MongoDB is required infrastructure. Cloudinary is the external object/media storage boundary, accessed by upload routes/helpers; resulting URLs are attached to profiles or messages. Google OAuth is optional external identity infrastructure. The React client is Vite-built and has Vercel deployment configuration, while Node runs the API and Socket.io service.
• server/routes/uploadRoutes.js
• server/utils/cloudinaryHelper.js
• client/vercel.json
Main entry points: app.js Express API composition · server.js HTTP + Socket.io runtime · db.js MongoDB · App.jsx Router & app shell
Components 19
React Client
- Browser UI · Authenticated collaboration client.
- React entry
client/src/main.jsx - Router & app shell · Separates public, protected, and settings experiences.
client/src/App.jsx - Community workspace · Integrates server, channel, and chat workflows.
client/src/pages/AppPage.jsx - Session state
client/src/context/AuthContext.jsx - Protected route
client/src/components/ProtectedRoute.jsx - Voice & call UI · Manages media and peer connection lifecycle.
client/src/hooks/useVoiceChannel.jsx
Node Backend
- HTTP + Socket.io runtime · Hosts REST APIs and real-time connections.
server/server.js - Express API composition · Mounts domain route groups and request middleware.
server/app.js - Authentication boundary · Verifies JWTs and supports Google OAuth.
server/routes/authRoutes.js - JWT authorization
server/middleware/authMiddleware.js - Server route group
server/routes/serverRoutes.js - Server collaboration · Handles servers, channels, messages, members, and invites.
server/controllers/serverController.js - DM & friendship · Handles direct messages and friend relationships.
server/controllers/dmController.js - Upload service · Stores media and attaches resulting URLs.
server/routes/uploadRoutes.js - Presence & signaling · Coordinates rooms, presence, and WebRTC signaling.
server/server.js
Data & External Services
- MongoDB · Persists users, servers, messages, DMs, and attachments.
server/database/db.js - Cloudinary
server/utils/cloudinaryHelper.js - Google OAuth
server/config/passport.js
Connections 22
- Browser UI → React entry: loads
- React entry → Router & app shell: mounts
- Router & app shell → Protected route: guards app routes
- Protected route → Session state: reads session
- Router & app shell → Community workspace: renders workspace
- Community workspace → HTTP + Socket.io runtime: REST history & mutations
- Session state → HTTP + Socket.io runtime: authenticated API calls
- Voice & call UI → Presence & signaling: signaling and presence
- HTTP + Socket.io runtime → Express API composition: serves requests
- HTTP + Socket.io runtime → Presence & signaling: initializes
- Express API composition → Authentication boundary: mounts auth routes
- Express API composition → JWT authorization: applies to protected routes
- Express API composition → Server route group: mounts
- Server route group → Server collaboration: delegates
- Express API composition → DM & friendship: delegates DM and friend routes
- Express API composition → Upload service: mounts upload routes
- Authentication boundary → Google OAuth: OAuth identity
- Server collaboration → MongoDB: persists collaboration data
- DM & friendship → MongoDB: persists DMs and friendships
- Upload service → Cloudinary: stores media
- Upload service → MongoDB: records attachment URLs
- Presence & signaling → MongoDB: supplements persisted history