# abhinav-anil-5670/editor architecture

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

- Interactive diagram: https://gitdiagram.com/abhinav-anil-5670/editor
- Repository: https://github.com/abhinav-anil-5670/editor

## Overview

##### Project type and purpose
- This is a frontend-only, real-time collaborative editor built as a React single-page-app (Vite) that uses Yjs (CRDT) for shared document state and WebRTC (via the y-webrtc module) for peer-to-peer syncing. There is no traditional backend API—only a signalling server to broker WebRTC handshakes.

##### File structure
- Top level:
- index.html, public/ → static assets served by Vite
- src/ → React components and entrypoint (main.jsx, App.jsx)
- src/components/Editor.jsx, JoinPage.jsx, Navbar.jsx → UI for joining a room and editing
- vite.config.js, package.json → build and dev server config
- No “backend” folder—this is purely a client app that relies on an external signalling server.

##### README for additional insights
- Signalling server is started from node_modules/y-webrtc/bin/server.js on ws://localhost:4444
- Clients join a fixed room name via WebSocket to negotiate WebRTC
- Once peers are discovered, all document updates go over WebRTC data channels using Yjs CRDT

##### Main components & relationships
a. Browser Client (React SPA)
– UI layers: JoinPage → Navbar → Editor
– Yjs document instance embedded in Editor.jsx
– y-webrtc provider configured with room name and signalling server URL
b. Signalling Server (Node.js process inside y-webrtc)
– Listens on ws://localhost:4444
– Brokers WebRTC SDP offers/answers over WebSocket
c. P2P Network (WebRTC Data Channels)
– Once negotiated, peers exchange Yjs updates directly
d. Optional: Vite Dev Server (serves the bundle, handles HMR in dev)

##### Architectural patterns & design principles
- CRDT (Yjs) ensures conflict-free merge of concurrent edits
- P2P mesh network: each client directly wires with every other client in the same room
- Single-responsibility components in React: separation of join logic, editor UI, and shared state provider

##### Key takeaways
- Accurately capture the fact that there is no traditional REST API or database—only a WebSocket signalling layer plus direct P2P syncing
- Clearly delineate the boundary between client logic (React + CRDT) and the standalone signalling server
- Core real-time collaboration loop: UI ↔ Yjs ↔ y-webrtc ↔ signalling server ↔ peers

## Diagram (Mermaid)

```mermaid
graph TD
    %% Browser Clients
    subgraph "Browser Client A (React + Vite)" 
        direction TB
        EntryA["main.jsx"]:::file
        AppA["App.jsx"]:::file
        StylesA["App.css"]:::file
        UIA["UI Layer"]:::frontend
        JoinA["JoinPage.jsx"]:::file
        NavA["Navbar.jsx"]:::file
        EditA["Editor.jsx"]:::file
        CRDTA["Yjs CRDT Instance"]:::crdt
        ProvA["y-webrtc Provider"]:::webrtc

        EntryA --> AppA
        AppA --> StylesA
        AppA --> UIA
        UIA --> JoinA
        UIA --> NavA
        UIA --> EditA
        EditA --> CRDTA
        EditA --> ProvA
    end

    subgraph "Browser Client B (React + Vite)" 
        direction TB
        EntryB["main.jsx"]:::file
        AppB["App.jsx"]:::file
        StylesB["App.css"]:::file
        UIB["UI Layer"]:::frontend
        JoinB["JoinPage.jsx"]:::file
        NavB["Navbar.jsx"]:::file
        EditB["Editor.jsx"]:::file
        CRDTB["Yjs CRDT Instance"]:::crdt
        ProvB["y-webrtc Provider"]:::webrtc

        EntryB --> AppB
        AppB --> StylesB
        AppB --> UIB
        UIB --> JoinB
        UIB --> NavB
        UIB --> EditB
        EditB --> CRDTB
        EditB --> ProvB
    end

    subgraph "Browser Client C (React + Vite)" 
        direction TB
        EntryC["main.jsx"]:::file
        AppC["App.jsx"]:::file
        StylesC["App.css"]:::file
        UIC["UI Layer"]:::frontend
        JoinC["JoinPage.jsx"]:::file
        NavC["Navbar.jsx"]:::file
        EditC["Editor.jsx"]:::file
        CRDTC["Yjs CRDT Instance"]:::crdt
        ProvC["y-webrtc Provider"]:::webrtc

        EntryC --> AppC
        AppC --> StylesC
        AppC --> UIC
        UIC --> JoinC
        UIC --> NavC
        UIC --> EditC
        EditC --> CRDTC
        EditC --> ProvC
    end

    %% Static Assets and Config
    Index["index.html"]:::file
    Public["public/"]:::file
    ViteConfig["vite.config.js"]:::config
    Package["package.json"]:::config

    %% Signalling Server
    Signaller["Signalling Server\n(y-webrtc broker)"]:::server

    %% Connections: Clients to Signalling Server
    ProvA -->|"WebSocket (SDP exchange)"| Signaller
    ProvB -->|"WebSocket (SDP exchange)"| Signaller
    ProvC -->|"WebSocket (SDP exchange)"| Signaller

    %% P2P Mesh Network
    ProvA -- "WebRTC DataChannel\n(Yjs updates)" --- ProvB
    ProvA -- "WebRTC DataChannel\n(Yjs updates)" --- ProvC
    ProvB -- "WebRTC DataChannel\n(Yjs updates)" --- ProvC

    %% Dev Server Asset Serving (optional)
    ViteConfig --> EntryA
    Index --> EntryA
    Public --> EntryA

    %% Legend
    subgraph "Legend"
        direction TB
        WS["Blue solid: WebSocket (SDP)"]:::wsLegend
        RTC["Green dashed: WebRTC DataChannel"]:::rtcLegend
    end

    %% Click Events
    click EntryA "https://github.com/abhinav-anil-5670/editor/blob/main/src/main.jsx"
    click EntryB "https://github.com/abhinav-anil-5670/editor/blob/main/src/main.jsx"
    click EntryC "https://github.com/abhinav-anil-5670/editor/blob/main/src/main.jsx"
    click AppA "https://github.com/abhinav-anil-5670/editor/blob/main/src/App.jsx"
    click AppB "https://github.com/abhinav-anil-5670/editor/blob/main/src/App.jsx"
    click AppC "https://github.com/abhinav-anil-5670/editor/blob/main/src/App.jsx"
    click StylesA "https://github.com/abhinav-anil-5670/editor/blob/main/src/App.css"
    click StylesB "https://github.com/abhinav-anil-5670/editor/blob/main/src/App.css"
    click StylesC "https://github.com/abhinav-anil-5670/editor/blob/main/src/App.css"
    click Index "https://github.com/abhinav-anil-5670/editor/blob/main/index.html"
    click Public "https://github.com/abhinav-anil-5670/editor/tree/main/public/"
    click JoinA "https://github.com/abhinav-anil-5670/editor/blob/main/src/components/JoinPage.jsx"
    click JoinB "https://github.com/abhinav-anil-5670/editor/blob/main/src/components/JoinPage.jsx"
    click JoinC "https://github.com/abhinav-anil-5670/editor/blob/main/src/components/JoinPage.jsx"
    click NavA "https://github.com/abhinav-anil-5670/editor/blob/main/src/components/Navbar.jsx"
    click NavB "https://github.com/abhinav-anil-5670/editor/blob/main/src/components/Navbar.jsx"
    click NavC "https://github.com/abhinav-anil-5670/editor/blob/main/src/components/Navbar.jsx"
    click EditA "https://github.com/abhinav-anil-5670/editor/blob/main/src/components/Editor.jsx"
    click EditB "https://github.com/abhinav-anil-5670/editor/blob/main/src/components/Editor.jsx"
    click EditC "https://github.com/abhinav-anil-5670/editor/blob/main/src/components/Editor.jsx"
    click ViteConfig "https://github.com/abhinav-anil-5670/editor/blob/main/vite.config.js"
    click Signaller "https://github.com/abhinav-anil-5670/editor/blob/main/node_modules/y-webrtc/bin/server.js"
    click Package "https://github.com/abhinav-anil-5670/editor/blob/main/package.json"

    %% Styles
    classDef file fill:#f9f,stroke:#333,stroke-width:1px
    classDef frontend fill:#bbf,stroke:#333,stroke-width:1px
    classDef crdt fill:#fdc,stroke:#333,stroke-width:1px
    classDef webrtc fill:#cfc,stroke:#333,stroke-width:1px
    classDef server fill:#fcc,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    classDef config fill:#efe,stroke:#333,stroke-width:1px
    classDef wsLegend fill:#fff,stroke:#00f,stroke-width:2px
    classDef rtcLegend fill:#fff,stroke:#0a0,stroke-width:2px,stroke-dasharray: 5 5
```
