# rohit-sharma-1802/codesync architecture

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

- Interactive diagram: https://gitdiagram.com/rohit-sharma-1802/codesync
- Repository: https://github.com/rohit-sharma-1802/codesync

## Overview

##### Project type and purpose
- This is a full-stack, real-time collaborative coding environment with an integrated whiteboard.
- The frontend is a React/Vite single-page application using Tailwind CSS for styling, organized into reusable components, contexts, hooks, and pages.
- The backend is a Node.js/Express server that leverages Socket.io for bidirectional real-time communication and calls out to the Piston API for code execution.

##### File structure
- Top level:
- client/ – React code (App.jsx, pages, components, contexts, hooks, API wrappers, socket client).
- server/ – Node.js/Express entrypoint (server.js) and utility functions (utils/actions.js).
- The `client/src/api/index.jsx` suggests REST calls (e.g. file save/download).
- The `client/src/socket/socket.js` and `server.js` indicate Socket.io as the real-time layer.
- No persistent database directory—file operations appear ephemeral or in-memory (could be extended to a DB later).
- Deployment configs (vercel.json, vite.config.js) show Vercel/Vite usage.

##### README for additional insights
- Real-time features: code sync, chat, drawing, user presence, tooltips, auto-suggest.
- Code execution via Piston API, drawing via Tldraw.
- Tech stack badges confirm React, Express, Socket.io, Node.js, Tailwind.

##### Essential architectural elements
- Socket.io “Room” abstraction in the server and how clients join it.
- Dual-channel communication: real-time socket vs. request/response REST.
- High-level UI flows (e.g., user types code → event → broadcast → UI update).
- Code execution request path: UI → server → Piston → server → UI.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client (Browser SPA)"
        direction TB
        subgraph "UI Components"
            direction TB
            EditorComponent["EditorComponent"]:::client
            FileSystem["FileSystem"]:::client
            FileEditor["FileEditor"]:::client
            ChatList["ChatList"]:::client
            ChatInput["ChatInput"]:::client
            DrawingEditor["DrawingEditor"]:::client
            Sidebar["Sidebar"]:::client
            ChatsTab["ChatsTab"]:::client
            FilesTab["FilesTab"]:::client
            RunTab["RunTab"]:::client
            SettingsTab["SettingsTab"]:::client
            UsersTab["UsersTab"]:::client
            TabButton["TabButton"]:::client
            Toast["Toast Notifications"]:::client
        end
        subgraph "State Management (Contexts)"
            direction TB
            AppContext["AppContext/Provider"]:::client
            ChatContext["ChatContext"]:::client
            FileContext["FileContext"]:::client
            RunCodeContext["RunCodeContext"]:::client
            SettingContext["SettingContext"]:::client
            SocketContext["SocketContext"]:::client
            TabContext["TabContext"]:::client
        end
        subgraph "Hooks & Networking"
            direction TB
            useSocket["useSocket Hook"]:::client
            useRunCode["useRunCode Hook"]:::client
            useFileSystem["useFileSystem Hook"]:::client
            APIClient["REST API Client"]:::client
        end
    end

    %% Server Layer
    subgraph "Server (Node.js + Express + Socket.io)"
        direction TB
        ExpressAPI["Express REST API"]:::server
        SocketServer["Socket.io Server"]:::server
        Actions["Business Logic & Actions"]:::server
    end

    %% External Services
    subgraph "External Services"
        direction TB
        PistonAPI["Piston API"]:::external
    end

    %% Client to Server interactions
    useSocket -->|WebSocket Connection| SocketServer
    SocketServer -->|broadcast events| useSocket
    APIClient -->|HTTP Requests| ExpressAPI
    ExpressAPI -->|Responses| APIClient

    %% Code Execution flow
    useRunCode -->|POST execute| ExpressAPI
    ExpressAPI -->|invoke| Actions
    Actions -->|call| PistonAPI
    PistonAPI -->|result| Actions
    Actions -->|respond| ExpressAPI
    ExpressAPI -->|result| useRunCode

    %% Server internal
    ExpressAPI -->|delegates| Actions
    SocketServer -->|delegates| Actions

    %% Class definitions
    classDef client fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef server fill:#E2FFD8,stroke:#228B22,color:#228B22
    classDef external fill:#FFE4B5,stroke:#FF8C00,color:#FF8C00

    %% Click Events
    click EditorComponent "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/components/editor/EditorComponent.jsx"
    click FileSystem "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/components/files/FileSystem.jsx"
    click FileEditor "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/components/files/FileEditor.jsx"
    click ChatList "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/components/chats/ChatList.jsx"
    click ChatInput "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/components/chats/ChatInput.jsx"
    click DrawingEditor "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/components/drawing/DrawingEditor.jsx"
    click Sidebar "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/components/sidebar/Sidebar.jsx"
    click ChatsTab "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/components/tabs/ChatsTab.jsx"
    click FilesTab "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/components/tabs/FilesTab.jsx"
    click RunTab "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/components/tabs/RunTab.jsx"
    click SettingsTab "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/components/tabs/SettingsTab.jsx"
    click UsersTab "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/components/tabs/UsersTab.jsx"
    click TabButton "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/components/tabs/TabButton.jsx"
    click Toast "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/components/toast/Toast.jsx"
    click AppContext "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/context/AppContext.jsx"
    click ChatContext "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/context/ChatContext.jsx"
    click FileContext "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/context/FileContext.jsx"
    click RunCodeContext "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/context/RunCodeContext.jsx"
    click SettingContext "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/context/SettingContext.jsx"
    click SocketContext "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/context/SocketContext.jsx"
    click TabContext "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/context/TabContext.jsx"
    click useSocket "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/hooks/useSocket.jsx"
    click useRunCode "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/hooks/useRunCode.jsx"
    click useFileSystem "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/hooks/useFileSystem.jsx"
    click APIClient "https://github.com/rohit-sharma-1802/codesync/blob/main/client/src/api/index.jsx"
    click ExpressAPI "https://github.com/rohit-sharma-1802/codesync/blob/main/server/server.js"
    click Actions "https://github.com/rohit-sharma-1802/codesync/blob/main/server/utils/actions.js"
```
