Skip to content

Latest commit

History

66 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

DevSync

Real-Time Collaborative Development Workspace

A repository-based workspace where multiple developers edit the same files at the same time — live code sync, live file-tree sync, and live presence, all over a single Socket.IO layer.

Node.jsExpressSocket.IOReactMongoDB


Table of Contents


Overview

DevSync is a repository-based real-time collaborative workspace. A repository is the core unit of collaboration — it holds files, folders, and collaborators — and every connected client sees changes to that repository the moment they happen, without commits, pushes, pulls, or manual file sharing.

The system pairs a standard REST API (auth, repositories, files, folders, invitations) with a Socket.IO layer that keeps everyone in a repository's "room" in sync: file tree changes, folder changes, live code edits, and who's currently online.


Why This Project Exists

Most collaborative-development workflows are built around asynchronous handoffs — commit, push, pull, merge. That model is powerful, but it isn't built for two people editing the same file at the same moment. DevSync exists to explore the other half of collaboration:

  • What does a repository-scoped real-time room actually look like under Socket.IO, end to end?
  • How do you keep a file tree, an open editor, and a list of online users all consistent when three different clients can each trigger a change at once?
  • Where does JWT-based auth need to be re-verified once you leave HTTP and move into a persistent socket connection?

Answering these required building the full loop — REST-backed persistence, a socket layer authenticated with the same JWTs as the API, and a real editor (Monaco) wired to both — rather than a UI mockup with fake sync.


Feature Highlights

Live Code SyncMonaco editor edits broadcast instantly to every other client with the same file open
🗂️ Live File-Tree SyncFile/folder create, rename, and delete propagate to all connected collaborators in real time
🟢 Live PresenceSee exactly who's online in a repository right now, deduplicated across multiple tabs per user
👥 InvitationsSend, receive, accept, or reject collaborator invitations to a repository
🔐 JWT-Authenticated SocketsThe same JWT used for REST auth is re-verified at the Socket.IO handshake
🖥️ VS Code–Style WorkspaceFile explorer, tabbed editor, and a collaboration panel in one layout

Architecture Overview

graph TD
UI[React Frontend] -->|REST — axios| API[Express API]
UI -->|WebSocket| IO[Socket.IO Layer]
API --> DB[(MongoDB)]
IO --> DB
IO --> WS[workspace.socket.js<br/>room join/leave]
IO --> ED[editor.socket.js<br/>live code sync]
IO --> PR[presence.socket.js<br/>online users]
IO --> FL[file.socket.js / folder.socket.js<br/>tree sync]
WS -.->|repo:&lt;id&gt; room| ED
WS -.->|repo:&lt;id&gt; room| PR
WS -.->|repo:&lt;id&gt; room| FL
Loading

Every client that opens a workspace joins a repo:<repositoryId> Socket.IO room. Each handler (editor, presence, files, folders) broadcasts only within that room, so collaborators on different repositories never see each other's traffic.

A full component breakdown lives in the Technical Requirements Document.


Real-Time Event Model

EventDirectionPurpose
workspace:join / workspace:joinedclient → server → clientJoin a repository's room
presence:updateserver → roomBroadcast current online users after any join/leave
editor:joinclient → serverAnnounce which file a user has open
editor:changeclient → serverUser typed — send the new content
editor:updateserver → room (except sender)Propagate the change to everyone else with that file open
file:created / file:renamed / file:deletedserver → roomKeep every client's file tree in sync
folder:created / folder:renamed / folder:deletedserver → roomKeep every client's folder tree in sync

Presence is deduplicated by userId (not socketId), so a user with the workspace open in two tabs still shows up once in the online list.


Core Components

sockets/index.js + sockets/middleware.js — initializes the Socket.IO server and authenticates every incoming connection against the same JWT used by the REST API, before any handler runs.

handlers/workspace.socket.js — owns room membership: joining and leaving the repo:<id> room on connect/disconnect, and delegating to the other handlers.

handlers/presence.socket.js — an in-memory presence store (repositoryId → socketId → userInfo), intentionally not persisted to the database since it resets correctly on every server restart.

handlers/editor.socket.js — validates that a change actually came from a socket inside the relevant room before broadcasting it, then relays content to every other client with that file open.

handlers/file.socket.js / folder.socket.js — broadcast file-tree mutations so every open workspace reflects create/rename/delete operations without a manual refresh.

Design rationale and data structures for each are documented in Backend Schema.


Feature Status

FeatureStatus
Authentication (JWT + bcrypt)✅ Working
Repository CRUD✅ Working
File & folder CRUD✅ Working
Real-time code sync✅ Working
Real-time file/folder sync✅ Working
Live presence✅ Working
Collaborator invitations✅ Working
Full workspace UI (explorer, tabs, editor, collab panel)✅ Working
ZIP export of a repository⬜ Not yet implemented
Breadcrumb navigation⬜ Not yet implemented
Centralized error-handling middleware⬜ Not yet implemented
Activity logs / version history⬜ Planned

Tech Stack

LayerTechnology
FrontendReact 19, React Router, Tailwind CSS, Monaco Editor
Real-Time ClientSocket.IO Client
BackendNode.js, Express 5
Real-Time ServerSocket.IO (JWT-authenticated handshake)
DatabaseMongoDB + Mongoose
AuthJWT + bcrypt
Build ToolVite

Project Structure

DevSync-RealtimeWorkspace/
├── backend/
│ └── src/
│ ├── controllers/ # authController, repositoryController, fileController, folderController, invitation.controller
│ ├── models/ # User, Repository, File, Folder, Invitation
│ ├── routes/ # Express routers per resource
│ ├── middleware/ # JWT auth middleware
│ ├── sockets/ # Socket.IO server init, event constants, auth middleware
│ └── handlers/ # workspace, editor, presence, file, folder socket handlers
│
└── frontend/
└── src/
├── pages/ # LoginPage, RegisterPage, DashboardPage, WorkspacePage
├── features/
│ ├── auth/ # LoginForm, RegisterForm, useLogin, useRegister
│ ├── dashboard/ # RepoCard, CreateRepoModal, useDashboard
│ └── workspace/ # FileTree, EditorPane, TabBar, PresenceList, InviteForm, useSocket, useEditor, useFileTree
├── services/ # axios-based API layer per resource
└── lib/ # socket client factory, axios instance, Monaco config

Future Roadmap

  • ZIP export of a full repository
  • Breadcrumb navigation in the editor toolbar
  • Centralized backend error-handling middleware
  • Activity logs and version history
  • Repository snapshots
  • Repository analytics

See 7_FutureWhichWeNeverSee.md for the full longer-term list.


Documentation

DocumentPurpose
Product RequirementsProblem, objectives, scope, success metrics
Technical RequirementsArchitecture, components, real-time design
Application FlowRequest lifecycle, sequence diagrams
UI/UX Design BriefDesign philosophy, layout, user journey
Backend SchemaData structures, relationships, design rationale
Implementation PlanMilestones, development strategy

Installation

Prerequisites: Node.js 18+, a MongoDB connection (local or Atlas)

git clone <repo-url>cd DevSync-RealtimeWorkspace
# Backendcd backend
npm install
# Frontendcd ../frontend
npm install

backend/.env

PORT=5000
MONGODB_URI=your_mongodb_connection_string
JWT_SECRET=your_jwt_secret

frontend/.env

VITE_API_BASE_URL=http://localhost:5000
VITE_SOCKET_URL=http://localhost:5000
# Backend (from /backend)
npm run dev
# Frontend (from /frontend, separate terminal)
npm run dev

Open http://localhost:5173.

Troubleshooting
ProblemFix
Socket won't connect / stuck "connecting"Confirm VITE_SOCKET_URL matches the running backend port, and that the JWT token is present in localStorage
401 Unauthorized on API callsToken missing or expired — log in again
Changes from another tab don't appearConfirm both clients joined the same repository room (workspace:joined should fire in the browser console)
MongoDB connection error on bootCheck MONGODB_URI in backend/.env and that the MongoDB instance is reachable

License: Developed for educational and academic purposes.

About

A repository-based real-time collaborative development workspace for teams to manage projects, synchronize code changes instantly, and collaborate from a shared repository environment.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages