# sagar-tandan/real-time-collaborative-text-editor architecture

> Architecture diagram of the GitHub repository sagar-tandan/real-time-collaborative-text-editor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sagar-tandan/real-time-collaborative-text-editor
- Repository: https://github.com/sagar-tandan/real-time-collaborative-text-editor

## Overview

##### Project Type and Purpose
- This is a full-stack application that enables real-time collaborative text editing. The key capabilities include simultaneous text editing, visual collaboration indicators (cursors), organization-based collaboration, and basic text formatting.

##### File Structure
- There are two primary parts: the “Backend” and “Frontend” directories.
– The Backend is structured to include controllers (document, organization, user), models (document, organization, thread, user), middleware (authentication and error handling), and routing files under versioned API routes (v1). It also contains utility components (e.g., jwtUtils) and configuration files.
– The Frontend is built as a React project (using Vite and Tailwind as indicated by the configuration files) with directories for components (grouped by features such as Document, Header, HomePage, etc.), context management, sockets, hooks, and custom extensions.
- The presence of a dedicated “Socket” folder in the Frontend suggests that real-time communication (likely using WebSockets) is an essential part of the collaboration feature.

##### Using the Information from the README
- The README confirms real-time editing, organization support, and plans for future features.
- It implies separate concerns between user authentication, document data handling, organization management, and real-time syncing.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "Frontend"
        FUI["Frontend UI (User Interaction)"]:::frontend
        FSM["Frontend State Management"]:::frontend
        FSock["Frontend Socket Module"]:::frontend
    end

    %% Backend Subgraph
    subgraph "Backend"
        BARL["Backend API Routing Layer"]:::backend
        BMed["Backend Middleware"]:::backend
        BCtrl["Backend Controllers"]:::backend
        BModel["Backend Data Models"]:::backend
        BUtil["Backend Utility Functions (JWT Handling)"]:::backend
    end

    %% External Services Subgraph
    subgraph "External Services"
        DB[("Database")]
        RTS["Real-Time Service"]:::external
    end

    %% Planned Features Subgraph
    subgraph "Planned Features"
        PF["Future Enhancements (Audio Chat, Threaded Comments)"]:::planned
    end

    %% Interactions
    FUI -->|"REST_API"| BARL
    BARL --> BMed
    BMed --> BCtrl
    BCtrl -->|"Accesses"| BModel
    BCtrl -->|"JWT_Check"| BUtil
    BModel -->|"Persists Data"| DB

    FSock <-->|"WebSocket"| RTS

    %% Optional: Indicate that Frontend UI interacts with State Management
    FSM -->|"Manages"| FUI

    %% Potential connection for future expansion (dotted line)
    BARL ---|"Extend"| PF
    FUI ---|"Extend"| PF

    %% Click Events
    click FUI "https://github.com/sagar-tandan/real-time-collaborative-text-editor/tree/main/Frontend/src/components"
    click FSM "https://github.com/sagar-tandan/real-time-collaborative-text-editor/blob/main/Frontend/src/Context/MyContext.jsx"
    click FSock "https://github.com/sagar-tandan/real-time-collaborative-text-editor/blob/main/Frontend/src/Socket/Socket.jsx"
    click BARL "https://github.com/sagar-tandan/real-time-collaborative-text-editor/tree/main/Backend/src/routes/v1"
    click BCtrl "https://github.com/sagar-tandan/real-time-collaborative-text-editor/tree/main/Backend/src/controllers"
    click BMed "https://github.com/sagar-tandan/real-time-collaborative-text-editor/tree/main/Backend/src/middleware"
    click BModel "https://github.com/sagar-tandan/real-time-collaborative-text-editor/tree/main/Backend/src/models"
    click BUtil "https://github.com/sagar-tandan/real-time-collaborative-text-editor/blob/main/Backend/src/utils/jwtUtils.js"

    %% Styles
    classDef frontend fill:#D1E8FF,stroke:#0077B6,stroke-width:2px;
    classDef backend fill:#FFE5D9,stroke:#FF6B6B,stroke-width:2px;
    classDef external fill:#D3F8E2,stroke:#2D6A4F,stroke-width:2px;
    classDef planned fill:#E0BBE4,stroke:#957DAD,stroke-width:2px,stroke-dasharray: 5 5;
```
