# iamkr07/codesync architecture

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

- Interactive diagram: https://gitdiagram.com/iamkr07/codesync
- Repository: https://github.com/iamkr07/codesync

## Overview

#### Purpose and entry points
CodeSync is a room-based collaborative IDE for pair programming, interviews, and shared live coding. The React client starts at `frontend/src/main.jsx`, routes through `frontend/src/App.jsx`, and presents landing and room experiences in `frontend/src/pages/LandingPage.jsx` and `frontend/src/pages/RoomPage.jsx`. The backend entry point is `server/server.js`.

#### Client application shell
`frontend/src/layouts/MainLayout.jsx` composes the workspace UI: navigation, editor, collaboration panels, output, AI tools, and replay/snapshot views. `frontend/src/pages/LandingPage.jsx` is the session-entry surface; `frontend/src/pages/RoomPage.jsx` is the isolated live-room surface. The browser is responsible for interactive editing, room participation, and rendering remote session state.

#### Shared room state and synchronization boundary
Room-scoped state is centralized in `frontend/src/state/RoomContext.jsx` and `frontend/src/state/roomState.js`. Socket lifecycle and event subscription are encapsulated by `frontend/src/hooks/useSocket.js`, forming the client boundary to the real-time backend. The intended flow is local editor/user/chat actions → Socket.io events → server room broadcast → peer clients update shared room state.

#### Collaborative IDE workspace
`frontend/src/components/Editor.jsx` is the Monaco-based code editing surface and primary source of code-change events. `frontend/src/components/UsersPanel.jsx` exposes room presence, while `frontend/src/components/ChatPanel.jsx` handles participant communication. `frontend/src/components/OutputConsole.jsx` presents program execution results, separating code authoring from backend execution/output delivery.

#### Server orchestration and room runtime
`server/server.js` hosts the Express and Socket.io runtime. It is the authoritative coordination point for connections, room membership, real-time broadcasts, and requests that cross from the browser into privileged backend capabilities. Rooms isolate collaboration sessions, so participants should receive only events and state associated with their active room.

#### AI and execution services
`frontend/src/components/AIPanel.jsx` initiates AI-assisted code analysis and interview-oriented assistance. `server/services/aiService.js` encapsulates the backend integration with Google Gemini, keeping API credentials and model invocation outside the browser. The server also provides the execution boundary for JavaScript and Python: client code and language selection are submitted for execution, then output is returned to `OutputConsole`.

#### Persistence, snapshots, and replay
Firebase is initialized at `frontend/src/firebase.js` and serves as the client persistence integration point for Firestore-backed events and snapshots. `frontend/src/components/SnapshotModal.jsx` captures or restores session checkpoints; `frontend/src/components/ReplayPanel.jsx` reconstructs session activity from persisted event history. This creates a hybrid model: Socket.io carries low-latency live updates, while Firestore retains durable replay/snapshot data.

#### Material infrastructure
The system runs a Vite/React frontend (`frontend/package.json`) and a Node/Express server (`server/package.json`). Core external services are Socket.io for bidirectional transport, Firebase Firestore for event/snapshot persistence, Google Gemini for AI intelligence, and backend language runtimes for code execution. The frontend is deployed separately from the server-facing real-time and service boundaries.

Main entry points: [`frontend/src/layouts/MainLayout.jsx`](https://github.com/iamkr07/codesync/blob/main/frontend/src/layouts/MainLayout.jsx) (Workspace shell), [`server/server.js`](https://github.com/iamkr07/codesync/blob/main/server/server.js) (Room coordinator), [`frontend/src/App.jsx`](https://github.com/iamkr07/codesync/blob/main/frontend/src/App.jsx) (App routing), [`frontend/src/components/Editor.jsx`](https://github.com/iamkr07/codesync/blob/main/frontend/src/components/Editor.jsx) (Code editor)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["React client"]
  node_client_entry["Client entry<br/>React bootstrap<br/>[main.jsx]"]
  node_app_router["App routing<br/>React routes<br/>[App.jsx]"]
  node_landing["Landing page<br/>session entry<br/>[LandingPage.jsx]"]
  node_room_page["Room page<br/>live room route<br/>[RoomPage.jsx]"]
  node_workspace["Workspace shell<br/>IDE layout<br/>[MainLayout.jsx]"]
  node_room_state["Room state<br/>shared client state<br/>[RoomContext.jsx]"]
  node_socket_hook{{"Socket boundary<br/>Socket.io client<br/>[useSocket.js]"}}
  node_editor["Code editor<br/>Monaco editor<br/>[Editor.jsx]"]
  node_collab_panels["Presence and chat<br/>collaboration UI<br/>[ChatPanel.jsx]"]
  node_output["Output console<br/>execution UI<br/>[OutputConsole.jsx]"]
  node_ai_panel["AI panel<br/>AI assistance UI<br/>[AIPanel.jsx]"]
  node_snapshots_replay["Snapshots and replay<br/>history UI<br/>[ReplayPanel.jsx]"]
  node_firebase_client{{"Firebase integration<br/>Firestore client<br/>[firebase.js]"}}
end

subgraph group_server["Backend runtime"]
  node_server_runtime{{"Room coordinator<br/>Express + Socket.io<br/>[server.js]"}}
  node_execution["Execution boundary<br/>code execution<br/>[server.js]"]
  node_ai_service["Gemini service<br/>AI backend adapter<br/>[aiService.js]"]
end

subgraph group_external["External services"]
  node_firestore[("Firebase Firestore<br/>event persistence")]
  node_gemini{{"Google Gemini<br/>AI model service"}}
  node_language_runtimes{{"Language runtimes<br/>JavaScript and Python"}}
end

node_client_entry -->|"starts"| node_app_router
node_app_router -->|"routes to"| node_landing
node_app_router -->|"routes to"| node_room_page
node_room_page -->|"renders"| node_workspace
node_workspace -->|"reads shared state"| node_room_state
node_workspace -->|"hosts"| node_editor
node_workspace -->|"hosts"| node_collab_panels
node_workspace -->|"hosts"| node_output
node_workspace -->|"hosts"| node_ai_panel
node_workspace -->|"hosts"| node_snapshots_replay
node_editor -->|"code changes"| node_socket_hook
node_collab_panels -->|"presence and chat"| node_socket_hook
node_socket_hook -->|"room events"| node_server_runtime
node_server_runtime -.->|"room broadcasts"| node_room_state
node_ai_panel -->|"AI request"| node_server_runtime
node_server_runtime -->|"delegates AI"| node_ai_service
node_ai_service -->|"model invocation"| node_gemini
node_editor -->|"run request"| node_server_runtime
node_server_runtime -->|"dispatches code"| node_execution
node_execution -->|"executes"| node_language_runtimes
node_execution -.->|"returns output"| node_output
node_snapshots_replay -->|"save and load history"| node_firebase_client
node_firebase_client -->|"persist events and snapshots"| node_firestore

click node_client_entry "https://github.com/iamkr07/codesync/blob/main/frontend/src/main.jsx"
click node_app_router "https://github.com/iamkr07/codesync/blob/main/frontend/src/App.jsx"
click node_landing "https://github.com/iamkr07/codesync/blob/main/frontend/src/pages/LandingPage.jsx"
click node_room_page "https://github.com/iamkr07/codesync/blob/main/frontend/src/pages/RoomPage.jsx"
click node_workspace "https://github.com/iamkr07/codesync/blob/main/frontend/src/layouts/MainLayout.jsx"
click node_room_state "https://github.com/iamkr07/codesync/blob/main/frontend/src/state/RoomContext.jsx"
click node_socket_hook "https://github.com/iamkr07/codesync/blob/main/frontend/src/hooks/useSocket.js"
click node_editor "https://github.com/iamkr07/codesync/blob/main/frontend/src/components/Editor.jsx"
click node_collab_panels "https://github.com/iamkr07/codesync/blob/main/frontend/src/components/ChatPanel.jsx"
click node_output "https://github.com/iamkr07/codesync/blob/main/frontend/src/components/OutputConsole.jsx"
click node_ai_panel "https://github.com/iamkr07/codesync/blob/main/frontend/src/components/AIPanel.jsx"
click node_snapshots_replay "https://github.com/iamkr07/codesync/blob/main/frontend/src/components/ReplayPanel.jsx"
click node_firebase_client "https://github.com/iamkr07/codesync/blob/main/frontend/src/firebase.js"
click node_server_runtime "https://github.com/iamkr07/codesync/blob/main/server/server.js"
click node_execution "https://github.com/iamkr07/codesync/blob/main/server/server.js"
click node_ai_service "https://github.com/iamkr07/codesync/blob/main/server/services/aiService.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_client_entry,node_app_router,node_landing,node_room_page,node_workspace,node_room_state,node_socket_hook,node_editor,node_collab_panels,node_output,node_ai_panel,node_snapshots_replay,node_firebase_client toneBlue
class node_server_runtime,node_execution,node_ai_service toneAmber
class node_firestore,node_gemini,node_language_runtimes toneMint
```

## Components

### React client

- [Client entry](https://github.com/iamkr07/codesync/blob/main/frontend/src/main.jsx): React bootstrap · `frontend/src/main.jsx`
- [App routing](https://github.com/iamkr07/codesync/blob/main/frontend/src/App.jsx): React routes · `frontend/src/App.jsx`
- [Landing page](https://github.com/iamkr07/codesync/blob/main/frontend/src/pages/LandingPage.jsx): session entry · `frontend/src/pages/LandingPage.jsx`
- [Room page](https://github.com/iamkr07/codesync/blob/main/frontend/src/pages/RoomPage.jsx): live room route · `frontend/src/pages/RoomPage.jsx`
- [Workspace shell](https://github.com/iamkr07/codesync/blob/main/frontend/src/layouts/MainLayout.jsx): IDE layout · `frontend/src/layouts/MainLayout.jsx`
- [Room state](https://github.com/iamkr07/codesync/blob/main/frontend/src/state/RoomContext.jsx): shared client state · Centralizes room-scoped collaboration state. · `frontend/src/state/RoomContext.jsx`
- [Socket boundary](https://github.com/iamkr07/codesync/blob/main/frontend/src/hooks/useSocket.js): Socket.io client · Owns socket lifecycle and event subscriptions. · `frontend/src/hooks/useSocket.js`
- [Code editor](https://github.com/iamkr07/codesync/blob/main/frontend/src/components/Editor.jsx): Monaco editor · Primary source of code-change events. · `frontend/src/components/Editor.jsx`
- [Presence and chat](https://github.com/iamkr07/codesync/blob/main/frontend/src/components/ChatPanel.jsx): collaboration UI · `frontend/src/components/ChatPanel.jsx`
- [Output console](https://github.com/iamkr07/codesync/blob/main/frontend/src/components/OutputConsole.jsx): execution UI · `frontend/src/components/OutputConsole.jsx`
- [AI panel](https://github.com/iamkr07/codesync/blob/main/frontend/src/components/AIPanel.jsx): AI assistance UI · `frontend/src/components/AIPanel.jsx`
- [Snapshots and replay](https://github.com/iamkr07/codesync/blob/main/frontend/src/components/ReplayPanel.jsx): history UI · `frontend/src/components/ReplayPanel.jsx`
- [Firebase integration](https://github.com/iamkr07/codesync/blob/main/frontend/src/firebase.js): Firestore client · `frontend/src/firebase.js`

### Backend runtime

- [Room coordinator](https://github.com/iamkr07/codesync/blob/main/server/server.js): Express + Socket.io · Authoritatively manages connections, room membership, and broadcasts. · `server/server.js`
- [Execution boundary](https://github.com/iamkr07/codesync/blob/main/server/server.js): code execution · Runs submitted JavaScript or Python outside the browser. · `server/server.js`
- [Gemini service](https://github.com/iamkr07/codesync/blob/main/server/services/aiService.js): AI backend adapter · Keeps credentials and model invocation on the server. · `server/services/aiService.js`

### External services

- **Firebase Firestore**: event persistence · Stores durable events and session snapshots.
- **Google Gemini**: AI model service
- **Language runtimes**: JavaScript and Python

## Connections

- Client entry → App routing: starts
- App routing → Landing page: routes to
- App routing → Room page: routes to
- Room page → Workspace shell: renders
- Workspace shell → Room state: reads shared state
- Workspace shell → Code editor: hosts
- Workspace shell → Presence and chat: hosts
- Workspace shell → Output console: hosts
- Workspace shell → AI panel: hosts
- Workspace shell → Snapshots and replay: hosts
- Code editor → Socket boundary: code changes
- Presence and chat → Socket boundary: presence and chat
- Socket boundary → Room coordinator: room events · Bidirectional Socket.io transport.
- Room coordinator → Room state: room broadcasts · Peer events update active-room state.
- AI panel → Room coordinator: AI request
- Room coordinator → Gemini service: delegates AI
- Gemini service → Google Gemini: model invocation
- Code editor → Room coordinator: run request
- Room coordinator → Execution boundary: dispatches code
- Execution boundary → Language runtimes: executes
- Execution boundary → Output console: returns output
- Snapshots and replay → Firebase integration: save and load history
- Firebase integration → Firebase Firestore: persist events and snapshots
