# alanpraful-a/codecollab architecture

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

- Interactive diagram: https://gitdiagram.com/alanpraful-a/codecollab
- Repository: https://github.com/alanpraful-a/codecollab

## Overview

CodeCollab is a browser-based collaborative coding platform. Users register or log in, create or join a room, and edit JavaScript together; the editor also supports in-browser code execution, as documented in the README. Authentication uses REST endpoints backed by user records, while room edits and cursor awareness synchronize through Socket.io and Yjs, with Yjs state persisted to MongoDB. The sampled source shows the server and persistence calls; the README documents frontend-to-backend Socket.io communication. The editor’s internal execution implementation was not separately traced.

Main entry points: [`frontend/src/App.jsx`](https://github.com/alanpraful-a/codecollab/blob/main/frontend/src/App.jsx) (App routing), [`frontend/src/Editor.jsx`](https://github.com/alanpraful-a/codecollab/blob/main/frontend/src/Editor.jsx) (Editor and runner), [`backend/server.js`](https://github.com/alanpraful-a/codecollab/blob/main/backend/server.js) (HTTP and socket server), [`frontend/src/context/AuthContext.jsx`](https://github.com/alanpraful-a/codecollab/blob/main/frontend/src/context/AuthContext.jsx) (Session and API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Browser experience"]
  node_app["App routing<br/>[App.jsx]"]
  node_home["Room lobby<br/>[Home.jsx]"]
  node_editor["Editor and runner<br/>[Editor.jsx]"]
  node_login["Login page<br/>[Login.jsx]"]
  node_register["Registration page<br/>[Register.jsx]"]
end

subgraph group_auth["Authentication"]
  node_authcontext["Session and API<br/>[AuthContext.jsx]"]
  node_authroutes["Auth endpoints<br/>[authRoutes.js]"]
  node_users[("User records<br/>[User.js]")]
end

subgraph group_realtime["Room collaboration"]
  node_socket["Room event handler<br/>[editorSocket.js]"]
  node_yjs["Yjs synchronization<br/>[yjsService.js]"]
  node_rooms[("Room state records<br/>[Room.js]")]
end

subgraph group_backend["Backend and persistence"]
  node_server["HTTP and socket server<br/>[server.js]"]
  node_dbconnect["Database connection<br/>[db.js]"]
end

node_user(("Collaborator"))
node_mongodb[("MongoDB")]

node_user -->|"uses"| node_app
node_app -->|"routes to"| node_home
node_app -->|"routes to"| node_editor
node_app -->|"routes to"| node_login
node_app -->|"routes to"| node_register
node_home -->|"navigates to"| node_editor
node_login -->|"calls login"| node_authcontext
node_register -->|"calls register"| node_authcontext
node_authcontext -->|"sends REST requests"| node_authroutes
node_authroutes -->|"reads and writes"| node_users
node_server -->|"mounts routes"| node_authroutes
node_server -->|"connects database"| node_dbconnect
node_dbconnect -->|"connects to"| node_mongodb
node_server -->|"sets up"| node_socket
node_user -->|"edits code"| node_editor
node_editor -->|"synchronizes via Socket.io"| node_socket
node_socket -->|"applies updates"| node_yjs
node_yjs -->|"loads and saves state"| node_rooms

click node_app "https://github.com/alanpraful-a/codecollab/blob/main/frontend/src/App.jsx"
click node_home "https://github.com/alanpraful-a/codecollab/blob/main/frontend/src/pages/Home.jsx"
click node_editor "https://github.com/alanpraful-a/codecollab/blob/main/frontend/src/Editor.jsx"
click node_login "https://github.com/alanpraful-a/codecollab/blob/main/frontend/src/pages/Login.jsx"
click node_register "https://github.com/alanpraful-a/codecollab/blob/main/frontend/src/pages/Register.jsx"
click node_authcontext "https://github.com/alanpraful-a/codecollab/blob/main/frontend/src/context/AuthContext.jsx"
click node_authroutes "https://github.com/alanpraful-a/codecollab/blob/main/backend/routes/authRoutes.js"
click node_users "https://github.com/alanpraful-a/codecollab/blob/main/backend/models/User.js"
click node_server "https://github.com/alanpraful-a/codecollab/blob/main/backend/server.js"
click node_dbconnect "https://github.com/alanpraful-a/codecollab/blob/main/backend/config/db.js"
click node_socket "https://github.com/alanpraful-a/codecollab/blob/main/backend/sockets/editorSocket.js"
click node_yjs "https://github.com/alanpraful-a/codecollab/blob/main/backend/services/yjsService.js"
click node_rooms "https://github.com/alanpraful-a/codecollab/blob/main/backend/models/Room.js"

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_app,node_home,node_editor,node_login,node_register toneBlue
class node_authcontext,node_authroutes,node_users,node_mongodb toneAmber
class node_socket,node_yjs,node_rooms toneMint
class node_server,node_dbconnect toneRose
class node_user toneIndigo
```

## Components

### Browser experience

- [App routing](https://github.com/alanpraful-a/codecollab/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Room lobby](https://github.com/alanpraful-a/codecollab/blob/main/frontend/src/pages/Home.jsx): `frontend/src/pages/Home.jsx`
- [Editor and runner](https://github.com/alanpraful-a/codecollab/blob/main/frontend/src/Editor.jsx): `frontend/src/Editor.jsx`
- [Login page](https://github.com/alanpraful-a/codecollab/blob/main/frontend/src/pages/Login.jsx): `frontend/src/pages/Login.jsx`
- [Registration page](https://github.com/alanpraful-a/codecollab/blob/main/frontend/src/pages/Register.jsx): `frontend/src/pages/Register.jsx`

### Authentication

- [Session and API](https://github.com/alanpraful-a/codecollab/blob/main/frontend/src/context/AuthContext.jsx): `frontend/src/context/AuthContext.jsx`
- [Auth endpoints](https://github.com/alanpraful-a/codecollab/blob/main/backend/routes/authRoutes.js): `backend/routes/authRoutes.js`
- [User records](https://github.com/alanpraful-a/codecollab/blob/main/backend/models/User.js): `backend/models/User.js`

### Room collaboration

- [Room event handler](https://github.com/alanpraful-a/codecollab/blob/main/backend/sockets/editorSocket.js): `backend/sockets/editorSocket.js`
- [Yjs synchronization](https://github.com/alanpraful-a/codecollab/blob/main/backend/services/yjsService.js): `backend/services/yjsService.js`
- [Room state records](https://github.com/alanpraful-a/codecollab/blob/main/backend/models/Room.js): `backend/models/Room.js`

### Backend and persistence

- [HTTP and socket server](https://github.com/alanpraful-a/codecollab/blob/main/backend/server.js): `backend/server.js`
- [Database connection](https://github.com/alanpraful-a/codecollab/blob/main/backend/config/db.js): `backend/config/db.js`

### Other components

- **Collaborator**
- **MongoDB**

## Connections

- Collaborator → App routing: uses (evidence: `frontend/src/App.jsx`)
- App routing → Room lobby: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Editor and runner: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Login page: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Registration page: routes to (evidence: `frontend/src/App.jsx`)
- Room lobby → Editor and runner: navigates to (evidence: `frontend/src/pages/Home.jsx`)
- Login page → Session and API: calls login (evidence: `frontend/src/pages/Login.jsx`)
- Registration page → Session and API: calls register (evidence: `frontend/src/pages/Register.jsx`)
- Session and API → Auth endpoints: sends REST requests (evidence: `frontend/src/context/AuthContext.jsx`)
- Auth endpoints → User records: reads and writes (evidence: `backend/routes/authRoutes.js`)
- HTTP and socket server → Auth endpoints: mounts routes (evidence: `backend/server.js`)
- HTTP and socket server → Database connection: connects database (evidence: `backend/server.js`)
- Database connection → MongoDB: connects to (evidence: `backend/config/db.js`)
- HTTP and socket server → Room event handler: sets up (evidence: `backend/server.js`)
- Collaborator → Editor and runner: edits code (evidence: `README.md`)
- Editor and runner → Room event handler: synchronizes via Socket.io (evidence: `README.md`)
- Room event handler → Yjs synchronization: applies updates (evidence: `backend/sockets/editorSocket.js`)
- Yjs synchronization → Room state records: loads and saves state (evidence: `backend/services/yjsService.js`)
