# shalvirajpura2/devsync-collaborative-code-editor architecture

> Architecture diagram of the GitHub repository shalvirajpura2/devsync-collaborative-code-editor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/shalvirajpura2/devsync-collaborative-code-editor
- Repository: https://github.com/shalvirajpura2/devsync-collaborative-code-editor

## Overview

1. **Overall shape**
   DevSync is a two-tier application: a React/Vite frontend and a Python/FastAPI backend. The frontend handles all user interaction and editor state, while the backend owns authentication verification, room persistence, WebSocket coordination, and Python code execution.

2. **Frontend boundary**
   The `frontend/` tree is a standalone SPA built with React, Vite, and a large Radix/shadcn UI layer. It is organized by page (`LandingPage`, `AuthPage`, `RoomSelectionPage`, `EditorPage`, `SettingsPage`) and shared components (`AuthPanel`, `CodeEditor`, `DashboardLayout`), which suggests a route-driven user experience rather than a component library.

3. **Editor-centric UX**
   The main product surface is the collaborative editor page. `CodeEditor` is the central interactive component, with surrounding dashboard/layout components providing room context, navigation, and settings. The frontend also includes Firebase auth hooks and a small axios wrapper, indicating that user session state and API calls are encapsulated locally in the client.

4. **Authentication flow**
   Firebase Authentication is the identity provider. The frontend uses the Firebase JS SDK to sign in/out and obtain user tokens; the backend uses Firebase Admin / token verification logic under `backend/src/core/` to trust those tokens on API requests. This creates a clear trust boundary: Firebase authenticates users, FastAPI authorizes backend operations.

5. **Backend API layer**
   `backend/src/api/` contains the HTTP entry points, split into room-related routes and request handling. This is the public server boundary exposed to the frontend for room creation/joining, state fetches, and code-run requests. FastAPI is the framework, and Uvicorn is the runtime entrypoint.

6. **Real-time collaboration layer**
   WebSocket support is separated into `backend/src/services/websocket_manager.py`, which strongly suggests a room-based fan-out model. The expected flow is: one client edits code, the backend receives the update over a socket, and the manager broadcasts the new state to all connected users in that room.

7. **Room and state persistence**
   Room data is modeled in `backend/src/models/room.py` and stored in MongoDB via `backend/src/db/mongodb.py`. MongoDB is the persistent source of truth for room metadata and likely any saved room/editor state, while the database connection is configured through `backend/src/core/config.py`.

8. **Code execution boundary**
   `backend/src/services/code_executor.py` isolates Python execution from the rest of the API. This is an important architectural boundary: collaboration traffic and execution traffic are separate concerns, with execution returning output/errors back to the room participants after server-side evaluation.

9. **Backend support services**
   The `core/` package centralizes cross-cutting infrastructure: configuration, Firebase admin setup, and auth helpers. That separation keeps the API routes thin and pushes environment-specific setup into one place, which is useful for deployment and testing.

10. **Static assets and deployment shape**
   There is a built frontend artifact under `backend/src/static/`, alongside a separate source frontend in `frontend/`. That implies at least one deployment path where the backend serves prebuilt static assets, even though the project is also structured as two independently built apps. The GitHub Actions workflows reinforce this split, with one workflow for the backend and one for Azure Static Web Apps.

11. **Local development and environment inputs**
   The backend expects MongoDB and Firebase service-account credentials; the frontend expects Firebase project config and optionally API/WebSocket base URLs. This means the system depends on three external services/config domains: Firebase Auth, MongoDB, and the backend API/WebSocket endpoint.

12. **Testing and operational checks**
   The repository includes dedicated connection test scripts for MongoDB and Firebase, which indicates the most failure-prone integration points are infrastructure connectivity and auth setup. Those scripts are likely used as sanity checks rather than full application tests.

13. **Primary end-to-end data flow**
   A user signs in with Firebase in the browser, joins or creates a room, and the frontend talks to FastAPI for room operations. Editing events go through WebSockets for live synchronization, room data is persisted in MongoDB, and explicit run actions invoke the backend code executor, with results broadcast back to connected clients.

Main entry points: [`backend/src/api`](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/tree/main/backend/src/api) (HTTP API), [`frontend/src/pages`](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/tree/main/frontend/src/pages) (Pages), [`frontend/src/App.jsx`](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/frontend/src/App.jsx) (SPA shell), [`backend/src/core`](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/tree/main/backend/src/core) (Auth core)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["SPA shell<br/>React/Vite app<br/>[App.jsx]"]
  node_frontend_pages["Pages<br/>route views"]
  node_frontend_editor["Code editor<br/>collab editor<br/>[CodeEditor.jsx]"]
  node_frontend_layout["Dashboard layout<br/>shell layout"]
  node_frontend_auth["Auth panel<br/>auth UI<br/>[AuthPanel.jsx]"]
  node_frontend_hooks["Auth hook<br/>client state<br/>[useFirebaseAuth.js]"]
  node_frontend_api["API client<br/>axios wrapper<br/>[axios.js]"]
  node_frontend_firebase["Firebase SDK<br/>auth client<br/>[firebase.js]"]
  node_frontend_ui["UI kit<br/>Radix/shadcn components"]
end

subgraph group_backend["Backend"]
  node_backend_main["Server entry<br/>FastAPI app<br/>[main.py]"]
  node_backend_api["HTTP API<br/>routes"]
  node_backend_auth["Auth core<br/>firebase admin"]
  node_backend_rooms["Room model<br/>data model<br/>[room.py]"]
  node_backend_ws["WebSocket manager<br/>realtime fan-out"]
  node_backend_exec["Code executor<br/>python runtime<br/>[code_executor.py]"]
  node_backend_db[("Mongo store<br/>persistence<br/>[mongodb.py]")]
  node_backend_static["Static build<br/>served assets"]
end

subgraph group_external["External services"]
  node_external_firebase(("Firebase Auth<br/>external identity"))
  node_external_mongo[("MongoDB<br/>external database")]
end

node_frontend_app -->|"routes to"| node_frontend_pages
node_frontend_pages -->|"hosts"| node_frontend_editor
node_frontend_pages -->|"hosts"| node_frontend_auth
node_frontend_pages -->|"wraps"| node_frontend_layout
node_frontend_editor -.->|"uses"| node_frontend_ui
node_frontend_layout -.->|"uses"| node_frontend_ui
node_frontend_auth -->|"signs in via"| node_frontend_firebase
node_frontend_hooks -->|"consumes"| node_frontend_firebase
node_frontend_app -->|"calls"| node_frontend_api
node_frontend_api -->|"requests"| node_backend_api
node_frontend_hooks -->|"token sent to"| node_backend_auth
node_backend_main -->|"mounts"| node_backend_api
node_backend_api -->|"verifies"| node_backend_auth
node_backend_api -->|"loads"| node_backend_rooms
node_backend_api -->|"persists"| node_backend_db
node_backend_api -->|"coordinates"| node_backend_ws
node_backend_api -->|"runs code"| node_backend_exec
node_backend_rooms -->|"stored in"| node_backend_db
node_backend_auth -->|"trusts"| node_external_firebase
node_backend_db -->|"connects to"| node_external_mongo
node_frontend_app -.->|"served as"| node_backend_static

click node_frontend_app "https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/frontend/src/App.jsx"
click node_frontend_pages "https://github.com/shalvirajpura2/devsync-collaborative-code-editor/tree/main/frontend/src/pages"
click node_frontend_editor "https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/frontend/src/components/CodeEditor.jsx"
click node_frontend_layout "https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/frontend/src/components/DashboardLayout.jsx"
click node_frontend_auth "https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/frontend/src/components/AuthPanel.jsx"
click node_frontend_hooks "https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/frontend/src/hooks/useFirebaseAuth.js"
click node_frontend_api "https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/frontend/src/lib/axios.js"
click node_frontend_firebase "https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/frontend/src/lib/firebase.js"
click node_frontend_ui "https://github.com/shalvirajpura2/devsync-collaborative-code-editor/tree/main/frontend/src/components/ui"
click node_backend_main "https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/backend/src/main.py"
click node_backend_api "https://github.com/shalvirajpura2/devsync-collaborative-code-editor/tree/main/backend/src/api"
click node_backend_auth "https://github.com/shalvirajpura2/devsync-collaborative-code-editor/tree/main/backend/src/core"
click node_backend_rooms "https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/backend/src/models/room.py"
click node_backend_ws "https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/backend/src/services/websocket_manager.py"
click node_backend_exec "https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/backend/src/services/code_executor.py"
click node_backend_db "https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/backend/src/db/mongodb.py"
click node_backend_static "https://github.com/shalvirajpura2/devsync-collaborative-code-editor/tree/main/backend/src/static"

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_frontend_app,node_frontend_pages,node_frontend_editor,node_frontend_layout,node_frontend_auth,node_frontend_hooks,node_frontend_api,node_frontend_firebase,node_frontend_ui toneBlue
class node_backend_main,node_backend_api,node_backend_auth,node_backend_rooms,node_backend_ws,node_backend_exec,node_backend_db,node_backend_static toneAmber
class node_external_firebase,node_external_mongo toneMint
```

## Components

### Frontend

React/Vite SPA and client-side state

- [SPA shell](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/frontend/src/App.jsx): React/Vite app · Top-level client application and route entrypoint · `frontend/src/App.jsx`
- [Pages](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/tree/main/frontend/src/pages): route views · Landing, auth, room selection, editor, and settings screens · `frontend/src/pages`
- [Code editor](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/frontend/src/components/CodeEditor.jsx): collab editor · Main collaborative editing surface · `frontend/src/components/CodeEditor.jsx`
- [Dashboard layout](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/frontend/src/components/DashboardLayout.jsx): shell layout · Room-scoped navigation and surrounding dashboard chrome · `frontend/src/components/DashboardLayout.jsx`
- [Auth panel](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/frontend/src/components/AuthPanel.jsx): auth UI · Sign-in and sign-out UI for Firebase auth · `frontend/src/components/AuthPanel.jsx`
- [Auth hook](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/frontend/src/hooks/useFirebaseAuth.js): client state · Firebase session and token handling in the browser · `frontend/src/hooks/useFirebaseAuth.js`
- [API client](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/frontend/src/lib/axios.js): axios wrapper · Client-side HTTP access to backend endpoints · `frontend/src/lib/axios.js`
- [Firebase SDK](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/frontend/src/lib/firebase.js): auth client · Browser-side Firebase authentication integration · `frontend/src/lib/firebase.js`
- [UI kit](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/tree/main/frontend/src/components/ui): Radix/shadcn components · Shared component library used across the SPA · `frontend/src/components/ui`

### Backend

FastAPI server, persistence, and execution

- [Server entry](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/backend/src/main.py): FastAPI app · Backend application bootstrap and runtime entrypoint · `backend/src/main.py`
- [HTTP API](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/tree/main/backend/src/api): routes · Room and request endpoints exposed to the frontend · `backend/src/api`
- [Auth core](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/tree/main/backend/src/core): firebase admin · Firebase admin setup and token verification helpers · `backend/src/core`
- [Room model](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/backend/src/models/room.py): data model · Room persistence structure and shape · `backend/src/models/room.py`
- [WebSocket manager](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/backend/src/services/websocket_manager.py): realtime fan-out · Room-based live update coordination · `backend/src/services/websocket_manager.py`
- [Code executor](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/backend/src/services/code_executor.py): python runtime · Server-side Python execution boundary · `backend/src/services/code_executor.py`
- [Mongo store](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/blob/main/backend/src/db/mongodb.py): persistence · MongoDB connection and room data access · `backend/src/db/mongodb.py`
- [Static build](https://github.com/shalvirajpura2/devsync-collaborative-code-editor/tree/main/backend/src/static): served assets · Prebuilt frontend assets served by the backend · `backend/src/static`

### External services

Identity and database dependencies

- **Firebase Auth**: external identity · User authentication provider
- **MongoDB**: external database · Persistent room and state storage

## Connections

- SPA shell → Pages: routes to · Route-driven user experience
- Pages → Code editor: hosts · Editor page centers the main workflow
- Pages → Auth panel: hosts · Authentication surface for sign-in
- Pages → Dashboard layout: wraps · Room and dashboard chrome around pages
- Code editor → UI kit: uses · Editor and surrounding screens share UI primitives
- Dashboard layout → UI kit: uses · Layout builds on shared components
- Auth panel → Firebase SDK: signs in via · Browser authentication flow
- Auth hook → Firebase SDK: consumes · Session and token access
- SPA shell → API client: calls · Room and execution requests to backend
- API client → HTTP API: requests · HTTP boundary into the server
- Auth hook → Auth core: token sent to · Authenticated requests carry Firebase credentials
- Server entry → HTTP API: mounts · FastAPI route layer
- HTTP API → Auth core: verifies · Token/auth checks on incoming requests
- HTTP API → Room model: loads · Room payloads and state shape
- HTTP API → Mongo store: persists · Room metadata and stored state
- HTTP API → WebSocket manager: coordinates · Live collaboration events
- HTTP API → Code executor: runs code · Explicit execution requests
- Room model → Mongo store: stored in · Room records backed by MongoDB
- Auth core → Firebase Auth: trusts · Firebase admin verification boundary
- Mongo store → MongoDB: connects to · MongoDB persistence backend
- SPA shell → Static build: served as · Backend can serve built frontend assets
